Skip to content

Commit

Permalink
Clean up in-planemo linters...
Browse files Browse the repository at this point in the history
Don't call an ElementTree.ElementTree a root, it isn't - it has a root. So fix variables names and correct a bug introduced into ``--xsd`` when the linters were refactored to be passed the ElementTree and not the root.
  • Loading branch information
jmchilton committed Sep 16, 2016
1 parent a086f36 commit 830e87a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions planemo/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
from planemo.xml import validation


def lint_dois(root, lint_ctx):
dois = find_dois_for_xml(root)
def lint_dois(tool_xml, lint_ctx):
dois = find_dois_for_xml(tool_xml)
for publication in dois:
is_doi(publication, lint_ctx)


def find_dois_for_xml(root):
def find_dois_for_xml(tool_xml):
dois = []
for element in root.root.findall("citations"):
for element in tool_xml.root.findall("citations"):
for citation in list(element):
if citation.tag == 'citation' and citation.attrib.get('type', '') == 'doi':
dois.append(citation.text)
Expand Down
4 changes: 2 additions & 2 deletions planemo/linters/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import planemo.lint


def lint_tool_dois(root, lint_ctx):
planemo.lint.lint_dois(root, lint_ctx)
def lint_tool_dois(tool_xml, lint_ctx):
planemo.lint.lint_dois(tool_xml, lint_ctx)
14 changes: 7 additions & 7 deletions planemo/linters/xsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
TOOL_XSD = os.path.join(XSDS_PATH, "tool", "galaxy.xsd")


def lint_tool_xsd(root, lint_ctx):
def lint_tool_xsd(tool_xml, lint_ctx):
"""Write a temp file out and lint it."""
with tempfile.NamedTemporaryFile() as tf:
_clean_root(root).write(tf.name)
_clean_root(tool_xml).write(tf.name)
planemo.lint.lint_xsd(lint_ctx, TOOL_XSD, tf.name)


def _clean_root(root):
def _clean_root(tool_xml):
"""XSD assumes macros have been expanded, so remove them."""
clean_root = copy.deepcopy(root)
clean_tool_xml = copy.deepcopy(tool_xml)
to_remove = []
for macros_el in clean_root.findall("macros"):
for macros_el in clean_tool_xml.getroot().findall("macros"):
to_remove.append(macros_el)
for macros_el in to_remove:
clean_root.getroot().remove(macros_el)
return clean_root
clean_tool_xml.getroot().remove(macros_el)
return clean_tool_xml

0 comments on commit 830e87a

Please sign in to comment.