comparison env/lib/python3.7/site-packages/planemo/linters/xsd.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 """Tool linting module that lints Galaxy tool against experimental XSD."""
2 import copy
3 import os
4 import tempfile
5
6 import galaxy.tool_util
7
8 import planemo.lint
9
10 TOOL_XSD = os.path.join(os.path.dirname(galaxy.tool_util.__file__), 'xsd', "galaxy.xsd")
11
12
13 def lint_tool_xsd(tool_xml, lint_ctx):
14 """Write a temp file out and lint it."""
15 with tempfile.NamedTemporaryFile() as tf:
16 _clean_root(tool_xml).write(tf.name)
17 planemo.lint.lint_xsd(lint_ctx, TOOL_XSD, tf.name)
18
19
20 def _clean_root(tool_xml):
21 """XSD assumes macros have been expanded, so remove them."""
22 clean_tool_xml = copy.deepcopy(tool_xml)
23 to_remove = []
24 for macros_el in clean_tool_xml.getroot().findall("macros"):
25 to_remove.append(macros_el)
26 for macros_el in to_remove:
27 clean_tool_xml.getroot().remove(macros_el)
28 return clean_tool_xml