comparison env/lib/python3.9/site-packages/planemo/linters/xsd.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
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