From 012d41712856243ef3a1091471d72c65be37249f Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Thu, 9 Dec 2021 13:28:09 -0600 Subject: [PATCH 1/5] CI #950 new env and adjust workflow --- .github/env-workflow.yml | 12 ++++++++++++ .github/workflows/syntax-checks.yml | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .github/env-workflow.yml diff --git a/.github/env-workflow.yml b/.github/env-workflow.yml new file mode 100644 index 0000000000..071053449b --- /dev/null +++ b/.github/env-workflow.yml @@ -0,0 +1,12 @@ +name: nexusformat + +channels: + - defaults + - conda-forge + - aps-anl-tag + +dependencies: + - lxml + - pyRestTable + - Sphinx + - six diff --git a/.github/workflows/syntax-checks.yml b/.github/workflows/syntax-checks.yml index b24738a6b2..ccb83d0aea 100644 --- a/.github/workflows/syntax-checks.yml +++ b/.github/workflows/syntax-checks.yml @@ -40,8 +40,7 @@ jobs: - name: Install dependencies run: | - $CONDA/bin/conda env update --file environment.yml --name $ENV_NAME - # $CONDA/bin/conda install pytest --name $ENV_NAME + $CONDA/bin/conda env update --file .github/env-workflow.yml --name $ENV_NAME $CONDA/bin/conda list -r --name $ENV_NAME env: PY_VER: ${{ matrix.python-version }} From 0944ac42284ecb096ea0e5c8829a78db0b6663ec Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Thu, 9 Dec 2021 13:53:05 -0600 Subject: [PATCH 2/5] MNT #946 Python code works in py27 and py39 locally --- utils/nxdl_desc2rst.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/nxdl_desc2rst.py b/utils/nxdl_desc2rst.py index 0bc7f83d95..c47a82ab41 100755 --- a/utils/nxdl_desc2rst.py +++ b/utils/nxdl_desc2rst.py @@ -209,7 +209,7 @@ def _tagMatch(ns, parent, match_list): '''match this tag to a list''' if parent is None: - raise "Must supply a valid parent node" + raise ValueError("Must supply a valid parent node") parent_tag = parent.tag tag_found = False for item in match_list: @@ -335,7 +335,7 @@ def applyTemplates(ns, parent, path, indentLevel, handler=generalHandler): if name in ('nx:groupGroup',): print(">"*45, name) if name in db: - raise "Duplicate name found: " + name + raise KeyError("Duplicate name found: " + name) db[name] = node for name in sorted(db): node = db[name] @@ -382,7 +382,9 @@ def getDocFromNode(ns, node, retval=None): text = lines[0][indent:] for line in lines[1:]: if not len(line[:indent].strip()) == 0: - raise "Something wrong with indentation on this line:\n" + line + raise IndentationError( + "Something wrong with indentation on this line:\n" + line + ) text += '\n' + line[indent:] # substitute HTML entities in markup: "<" for "<" From 8fe935d1af1fcdacb3f25a563d4808e801ab271d Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Thu, 9 Dec 2021 16:57:15 -0600 Subject: [PATCH 3/5] MNT #951 use XML entity in embedded rst --- nxdl.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nxdl.xsd b/nxdl.xsd index 110f0fd3cb..440ea90102 100644 --- a/nxdl.xsd +++ b/nxdl.xsd @@ -1182,7 +1182,7 @@ An ``enumeration`` restricts the values allowed for a specification. Each value is specified using an ``item`` element, such as: - ````. + ``<item value="Synchrotron X-ray Source" />``. Could contain these elements: * ``doc`` From 13f124df9d00b223a5379f45fe3aa2803d471703 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Thu, 9 Dec 2021 17:06:40 -0600 Subject: [PATCH 4/5] MNT #951 refactor --- utils/nxdl_desc2rst.py | 44 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/utils/nxdl_desc2rst.py b/utils/nxdl_desc2rst.py index c47a82ab41..bb7bc25bd3 100755 --- a/utils/nxdl_desc2rst.py +++ b/utils/nxdl_desc2rst.py @@ -10,6 +10,7 @@ import os, sys import lxml.etree +import textwrap TITLE_MARKERS = '- + ~ ^ * @'.split() # used for underscoring section titles @@ -353,39 +354,19 @@ def printDocs(ns, parent, indentLevel=0): def getDocFromNode(ns, node, retval=None): - docnodes = node.xpath('xs:annotation/xs:documentation', namespaces=ns) - if docnodes == None: + annotation_node = node.find('xs:annotation', ns) + if annotation_node is None: return retval - if not len(docnodes) == 1: + documentation_node = annotation_node.find('xs:documentation', ns) + if documentation_node is None: return retval - # be sure to grab _all_ content in the documentation - # it might look like XML - s = lxml.etree.tostring(docnodes[0], pretty_print=True) - p1 = s.decode().find('>')+1 - p2 = s.decode().rfind(' 1: - indent0 = len(lines[0]) - len(lines[0].lstrip()) - indent1 = len(lines[1]) - len(lines[1].lstrip()) - if len(lines) > 2: - indent2 = len(lines[2]) - len(lines[2].lstrip()) - else: - indent2 = 0 - if indent0 == 0: - indent = max(indent1, indent2) - text = lines[0] - else: - indent = indent0 - text = lines[0][indent:] - for line in lines[1:]: - if not len(line[:indent].strip()) == 0: - raise IndentationError( - "Something wrong with indentation on this line:\n" + line - ) - text += '\n' + line[indent:] + # Be sure to grab _all_ content in the node. + # The content might look like XML. + s = lxml.etree.tostring(documentation_node, method="text", pretty_print=True) + rst = s.decode().lstrip('\n') # remove any leading blank lines + rst = rst.rstrip() # remove any trailing white space + text = textwrap.dedent(rst) # remove common leading space # substitute HTML entities in markup: "<" for "<" # thanks: http://stackoverflow.com/questions/2087370/decode-html-entities-in-python-string @@ -483,7 +464,8 @@ def main(tree, ns): developermode = True developermode = False if developermode and len(sys.argv) != 2: - NXDL_SCHEMA_FILE = os.path.join('..', 'nxdl.xsd') + path = os.path.dirname(__file__) + NXDL_SCHEMA_FILE = os.path.join(path, '..', 'nxdl.xsd') else: if len(sys.argv) != 2: print("usage: %s nxdl.xsd" % sys.argv[0]) From 26de65997833d080f7a0afdbdb15c10a6705d09e Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Fri, 10 Dec 2021 10:57:19 -0600 Subject: [PATCH 5/5] DOC #951 about XML entities --- utils/nxdl_desc2rst.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/nxdl_desc2rst.py b/utils/nxdl_desc2rst.py index bb7bc25bd3..be6f285db9 100755 --- a/utils/nxdl_desc2rst.py +++ b/utils/nxdl_desc2rst.py @@ -362,7 +362,8 @@ def getDocFromNode(ns, node, retval=None): return retval # Be sure to grab _all_ content in the node. - # The content might look like XML. + # In the documentation nodes, use XML entities ("<"" instead of "<") + # for documentation characters that would otherwise be considered as XML. s = lxml.etree.tostring(documentation_node, method="text", pretty_print=True) rst = s.decode().lstrip('\n') # remove any leading blank lines rst = rst.rstrip() # remove any trailing white space