Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added figures to generated documentation #767

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions ontopy/ontodoc_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
self.individuals = set()
self.datatypes = set()

# All navigation IDs added by the ontology. Used to warn about
# dublicated IDs
self.navids = set()

if ontology:
self.add_ontology(ontology)

Expand Down Expand Up @@ -137,7 +141,7 @@
subsections: str = "all",
header: bool = True,
) -> str:
# pylint: disable=too-many-branches,too-many-locals
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
"""Return reference documentation of all module entities.

Arguments:
Expand Down Expand Up @@ -186,15 +190,23 @@
]
)

def add_keyvalue(key, value, escape=True, htmllink=True):
def add_keyvalue(
key, value, escape=True, htmllink=True, show_figure=True
):
"""Help function for adding a key-value row to table."""
if escape:
value = html.escape(str(value))
if htmllink:
value = re.sub(
r"(https?://[^\s]+)", r'<a href="\1">\1</a>', value
)
value = value.replace("\n", "<br>")
if show_figure and re.match(
r"^(http://|https://)[a-zA-Z.+?@/_-]+\.(png|jpg|jpeg|svg|gif)$",
value,
):
value = f'<img src="{value}">'

Check warning on line 201 in ontopy/ontodoc_rst.py

View check run for this annotation

Codecov / codecov/patch

ontopy/ontodoc_rst.py#L201

Added line #L201 was not covered by tests
else:
if escape:
value = html.escape(str(value))
if htmllink:
value = re.sub(
r"(https?://[^\s]+)", r'<a href="\1">\1</a>', value
)
value = value.replace("\n", "<br>")
lines.extend(
[
" <tr>",
Expand Down Expand Up @@ -222,11 +234,27 @@
)
for entity in sorted(maps[subsection], key=get_label):
label = get_label(entity)
navid = navid2 = ""
if entity.name in self.navids:
warnings.warn(f"duplicated entity names: {entity.name}")

Check warning on line 239 in ontopy/ontodoc_rst.py

View check run for this annotation

Codecov / codecov/patch

ontopy/ontodoc_rst.py#L239

Added line #L239 was not covered by tests
else:
self.navids.add(entity.name)
navid = f' <div id="{entity.name}"></div>'
if hasattr(entity, "prefLabel"):
preflabel = str(entity.prefLabel.first())
if preflabel != entity.name:
if preflabel in self.navids:
warnings.warn(f"duplicated prefLabel: {preflabel}")

Check warning on line 247 in ontopy/ontodoc_rst.py

View check run for this annotation

Codecov / codecov/patch

ontopy/ontodoc_rst.py#L247

Added line #L247 was not covered by tests
else:
self.navids.add(preflabel)
navid2 = f' <div id="{preflabel}"></div>'

lines.extend(
[
".. raw:: html",
"",
f' <div id="{entity.name}"></div>',
navid,
navid2,
"",
f"{label}",
"^" * len(label),
Expand Down
3 changes: 2 additions & 1 deletion ontopy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,8 @@ def copy_annotation(onto, src, dst):
elif src in onto:
src = onto[src]
else:
warnings.warn(f"no such annotation: '{src}' Skip copy annotation...")

warnings.warn(f"skipping copy for missing source annotation: {src}")
return

if onto.world[dst]:
Expand Down
Loading