Skip to content

Commit

Permalink
Merge pull request #951 from nexusformat/950-repair-workflow
Browse files Browse the repository at this point in the history
repair workflow and make Python code compliant with py3
  • Loading branch information
prjemian authored Dec 13, 2021
2 parents 493adbe + 26de659 commit 40bd567
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
12 changes: 12 additions & 0 deletions .github/env-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: nexusformat

channels:
- defaults
- conda-forge
- aps-anl-tag

dependencies:
- lxml
- pyRestTable
- Sphinx
- six
3 changes: 1 addition & 2 deletions .github/workflows/syntax-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion nxdl.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@
<xs:documentation>
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" />``.
``&lt;item value="Synchrotron X-ray Source" />``.
Could contain these elements:

* ``doc``
Expand Down
47 changes: 16 additions & 31 deletions utils/nxdl_desc2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import os, sys
import lxml.etree
import textwrap


TITLE_MARKERS = '- + ~ ^ * @'.split() # used for underscoring section titles
Expand Down Expand Up @@ -209,7 +210,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:
Expand Down Expand Up @@ -335,7 +336,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]
Expand All @@ -353,37 +354,20 @@ 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('</')
text = s[p1:p2].decode().lstrip('\n') # cut off the enclosing tag

lines = text.splitlines()
if len(lines) > 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 "Something wrong with indentation on this line:\n" + line
text += '\n' + line[indent:]
# Be sure to grab _all_ content in the <xs:documentation> node.
# In the documentation nodes, use XML entities ("&lt;"" 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
text = textwrap.dedent(rst) # remove common leading space

# substitute HTML entities in markup: "<" for "&lt;"
# thanks: http://stackoverflow.com/questions/2087370/decode-html-entities-in-python-string
Expand Down Expand Up @@ -481,7 +465,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])
Expand Down

0 comments on commit 40bd567

Please sign in to comment.