Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/linters/xml_order.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 """This module contains a linting functions for tool XML block order. | |
2 | |
3 For more information on the IUC standard for XML block order see - | |
4 https://github.com/galaxy-iuc/standards. | |
5 """ | |
6 # https://github.com/galaxy-iuc/standards | |
7 # https://github.com/galaxy-iuc/standards/pull/7/files | |
8 TAG_ORDER = [ | |
9 'description', | |
10 'macros', | |
11 'parallelism', | |
12 'requirements', | |
13 'code', | |
14 'stdio', | |
15 'version_command', | |
16 'command', | |
17 'environment_variables', | |
18 'configfiles', | |
19 'inputs', | |
20 'outputs', | |
21 'tests', | |
22 'help', | |
23 'citations', | |
24 ] | |
25 | |
26 DATASOURCE_TAG_ORDER = [ | |
27 'description', | |
28 'macros', | |
29 'command', | |
30 'configfiles', | |
31 'inputs', | |
32 'request_param_translation', | |
33 'uihints', | |
34 'outputs', | |
35 'options', | |
36 'help', | |
37 'citations', | |
38 ] | |
39 | |
40 | |
41 # Ensure the XML blocks appear in the correct order prescribed | |
42 # by the tool author best practices. | |
43 def lint_xml_order(tool_xml, lint_ctx): | |
44 tool_root = tool_xml.getroot() | |
45 | |
46 if tool_root.attrib.get('tool_type', '') == 'data_source': | |
47 _validate_for_tags(tool_root, lint_ctx, DATASOURCE_TAG_ORDER) | |
48 else: | |
49 _validate_for_tags(tool_root, lint_ctx, TAG_ORDER) | |
50 | |
51 | |
52 def _validate_for_tags(root, lint_ctx, tag_ordering): | |
53 last_tag = None | |
54 last_key = None | |
55 for elem in root: | |
56 tag = elem.tag | |
57 if tag in tag_ordering: | |
58 key = tag_ordering.index(tag) | |
59 if last_key: | |
60 if last_key > key: | |
61 lint_ctx.warn(f"Best practice violation [{tag}] elements should come before [{last_tag}]") | |
62 last_tag = tag | |
63 last_key = key | |
64 else: | |
65 lint_ctx.info("Unknown tag [%s] encountered, this may result in a warning in the future." % tag) |