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

adding links to first references of the vocabulary items #1272

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0233d91
adding links to first references of the vocabulary items
sanbrock Jun 15, 2023
a671d15
do not display first reference redundantly if it is the only reference
sanbrock Jun 15, 2023
124b41e
reformatting
sanbrock Jun 15, 2023
8351366
changing to shorter link with tooltip
sanbrock Jun 15, 2023
1af3a42
linting
sanbrock Jun 15, 2023
8c0881d
linting
sanbrock Jun 15, 2023
d5faa6b
supporting unicode char for latex
sanbrock Jun 15, 2023
1138ebf
short tooltip and link
sanbrock Jun 15, 2023
cb92872
adjusted conf.py
sanbrock Jun 15, 2023
c117842
removing pynxtools as dependecy
sanbrock Jun 15, 2023
185f649
linting
sanbrock Jun 15, 2023
5a1de22
linting
sanbrock Jun 15, 2023
286c0c2
imports
sanbrock Jun 15, 2023
6837fb6
Adds pyproject
domna Jun 16, 2023
73d795b
Merge pull request #1276 from FAIRmat-NFDI/origin/python-package
sanbrock Jun 16, 2023
52a21ee
linting
sanbrock Jun 16, 2023
d3d101f
adjusted default location of definitions inside the module
sanbrock Jun 16, 2023
025c078
new characters as Code Camp suggested
sanbrock Jun 16, 2023
adf098e
make new char available for latex
sanbrock Jun 16, 2023
222a3c0
make new char available for latex
sanbrock Jun 16, 2023
7252a49
make new char available for latex
sanbrock Jun 16, 2023
fd4b4a6
collapsing doc_enum-s
sanbrock Jun 16, 2023
90ff26b
missing sphinx dependency
sanbrock Jun 16, 2023
015aa77
removing h5py dependency
sanbrock Jun 21, 2023
f2cd2ac
remove dependencies also from pypi configuration
sanbrock Jun 21, 2023
aabf43b
added sphinx-toolbox
sanbrock Jun 21, 2023
c510dae
collapsing is deactivated for this PR
sanbrock Jun 21, 2023
ce20d6b
Fixes versioning
domna Jul 18, 2023
45cb4ac
Merge pull request #1305 from domna/link_first_reference
sanbrock Jul 18, 2023
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
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,23 @@ makelog.txt
# Unknown
/python/
__github_creds__.txt

sanbrock marked this conversation as resolved.
Show resolved Hide resolved
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
recursive-include applications/ *.nxdl.xml
sanbrock marked this conversation as resolved.
Show resolved Hide resolved
recursive-include contributed_definitions/ *.nxdl.xml
recursive-include base_classes/ *.nxdl.xml
include ./ *.xsd
52 changes: 50 additions & 2 deletions dev_tools/docs/nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..globals.errors import NXDLParseError
from ..globals.nxdl import NXDL_NAMESPACE
from ..globals.urls import REPO_URL
from ..utils import nexus as pynxtools_nxlib
from ..utils.types import PathLike
from .anchor_list import AnchorRegistry

Expand Down Expand Up @@ -506,7 +507,7 @@ def _print_attribute(self, ns, kind, node, optional, indent, parent_path):
)
self._print(f"{indent}.. index:: {index_name} ({kind} attribute)\n")
self._print(
f"{indent}**@{name}**: {optional}{self._format_type(node)}{self._format_units(node)}\n"
f"{indent}**@{name}**: {optional}{self._format_type(node)}{self._format_units(node)} {self.get_first_parent_ref(f'{parent_path}/{name}', 'attribute')}\n"
)
self._print_doc(indent + self._INDENTATION_UNIT, ns, node)
node_list = node.xpath("nx:enumeration", namespaces=ns)
Expand Down Expand Up @@ -549,6 +550,7 @@ def _print_full_tree(self, ns, parent, name, indent, parent_path):
f"{self._format_type(node)}"
f"{dims}"
f"{self._format_units(node)}"
f" {self.get_first_parent_ref(f'{parent_path}/{name}', 'field')}"
"\n"
)

Expand Down Expand Up @@ -585,7 +587,9 @@ def _print_full_tree(self, ns, parent, name, indent, parent_path):
# target = hTarget.replace(".. _", "").replace(":\n", "")
# TODO: https://github.com/nexusformat/definitions/issues/1057
self._print(f"{indent}{hTarget}")
self._print(f"{indent}**{name}**: {optional_text}{typ}\n")
self._print(
f"{indent}**{name}**: {optional_text}{typ} {self.get_first_parent_ref(f'{parent_path}/{name}', 'group')}\n"
)

self._print_if_deprecated(ns, node, indent + self._INDENTATION_UNIT)
self._print_doc(indent + self._INDENTATION_UNIT, ns, node)
Expand Down Expand Up @@ -624,3 +628,47 @@ def _print_full_tree(self, ns, parent, name, indent, parent_path):
def _print(self, *args, end="\n"):
# TODO: change instances of \t to proper indentation
self._rst_lines.append(" ".join(args) + end)

def get_first_parent_ref(self, path, tag):
nx_name = path[1 : path.find("/", 1)]
path = path[path.find("/", 1) :]

try:
parents = pynxtools_nxlib.get_inherited_nodes(path, nx_name)[2]
except FileNotFoundError:
return ""
if len(parents) > 1:
parent = parents[1]
parent_path = parent_display_name = parent.attrib["nxdlpath"]
parent_path_segments = parent_path[1:].split("/")
parent_def_name = parent.attrib["nxdlbase"][
parent.attrib["nxdlbase"]
.rfind("/") : parent.attrib["nxdlbase"]
.rfind(".nxdl")
]

# Case where the first parent is a base_class
if parent_path_segments[0] == "":
return ""

# special treatment for NXnote@type
if (
tag == "attribute"
and parent_def_name == "/NXnote"
and parent_path == "/type"
):
return ""

if tag == "attribute":
pos_of_right_slash = parent_path.rfind("/")
parent_path = (
parent_path[:pos_of_right_slash]
+ "@"
+ parent_path[pos_of_right_slash + 1 :]
)
parent_display_name = f"{parent_def_name[1:]}{parent_path}"
return (
f":abbr:`... (override: {parent_display_name})"
+ f"`:ref:`🔗 </{parent_display_name}-{tag}>`"
)
return ""
Loading