Skip to content

Commit 4823c5e

Browse files
committed
New linter - lint order of XML appearing in the XML file.
The best practice guidelines prescribe a fixed order - this verifies that order. It will also print a little info box if unknown top-level tags are encountered - this may become a warning in the future (certainly if the XSD validation works out). Fix tool_builder.py to actually produce best practice tools.
1 parent 8207026 commit 4823c5e

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

planemo/commands/cmd_normalize.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,7 @@
99
load_tool,
1010
raw_tool_xml_tree,
1111
)
12-
13-
14-
TAG_ORDER = [
15-
'description',
16-
'macros',
17-
'requirements',
18-
'code',
19-
'stdio',
20-
'version_command',
21-
'command',
22-
'inputs',
23-
'outputs',
24-
'tests',
25-
'help',
26-
'citations',
27-
]
12+
from galaxy.tools.linters.xml_order import TAG_ORDER
2813

2914

3015
@click.command('normalize')

planemo/tool_builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
<expand macro="version_command" />
2121
{% endif %}
2222
{%- else %}
23-
<stdio>
24-
<exit_code range="1:" />
25-
</stdio>
2623
<requirements>
2724
{%- for requirement in requirements %}
2825
{{ requirement }}
@@ -31,6 +28,9 @@
3128
{{ container }}
3229
{%- endfor %}
3330
</requirements>
31+
<stdio>
32+
<exit_code range="1:" />
33+
</stdio>
3434
{%- if version_command %}
3535
<version_command>{{ version_command }}</version_command>
3636
{%- endif %}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
TAG_ORDER = [
2+
'description',
3+
'macros',
4+
'requirements',
5+
'code',
6+
'stdio',
7+
'version_command',
8+
'command',
9+
'inputs',
10+
'outputs',
11+
'tests',
12+
'help',
13+
'citations',
14+
]
15+
16+
17+
# Ensure the XML blocks appear in the correct order prescribed
18+
# by the tool author best practices.
19+
def lint_xml_ordering(tool_xml, lint_ctx):
20+
last_tag = None
21+
last_key = None
22+
for elem in list(tool_xml.getroot()):
23+
tag = elem.tag
24+
if tag in TAG_ORDER:
25+
key = TAG_ORDER.index(tag)
26+
if last_key:
27+
if last_key > key:
28+
lint_ctx.warn("Best practice violation [%s] elements should come before [%s]" % (tag, last_tag))
29+
last_tag = tag
30+
last_key = key
31+
else:
32+
lint_ctx.info("Unknown tag [%s] encoutered, this may result in a warning in the future." % tag)

0 commit comments

Comments
 (0)