Skip to content

Commit

Permalink
New linter - lint order of XML appearing in the XML file.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmchilton committed Mar 16, 2015
1 parent 8207026 commit 4823c5e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
17 changes: 1 addition & 16 deletions planemo/commands/cmd_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,7 @@
load_tool,
raw_tool_xml_tree,
)


TAG_ORDER = [
'description',
'macros',
'requirements',
'code',
'stdio',
'version_command',
'command',
'inputs',
'outputs',
'tests',
'help',
'citations',
]
from galaxy.tools.linters.xml_order import TAG_ORDER


@click.command('normalize')
Expand Down
6 changes: 3 additions & 3 deletions planemo/tool_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
<expand macro="version_command" />
{% endif %}
{%- else %}
<stdio>
<exit_code range="1:" />
</stdio>
<requirements>
{%- for requirement in requirements %}
{{ requirement }}
Expand All @@ -31,6 +28,9 @@
{{ container }}
{%- endfor %}
</requirements>
<stdio>
<exit_code range="1:" />
</stdio>
{%- if version_command %}
<version_command>{{ version_command }}</version_command>
{%- endif %}
Expand Down
32 changes: 32 additions & 0 deletions planemo_ext/galaxy/tools/linters/xml_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
TAG_ORDER = [
'description',
'macros',
'requirements',
'code',
'stdio',
'version_command',
'command',
'inputs',
'outputs',
'tests',
'help',
'citations',
]


# Ensure the XML blocks appear in the correct order prescribed
# by the tool author best practices.
def lint_xml_ordering(tool_xml, lint_ctx):
last_tag = None
last_key = None
for elem in list(tool_xml.getroot()):
tag = elem.tag
if tag in TAG_ORDER:
key = TAG_ORDER.index(tag)
if last_key:
if last_key > key:
lint_ctx.warn("Best practice violation [%s] elements should come before [%s]" % (tag, last_tag))
last_tag = tag
last_key = key
else:
lint_ctx.info("Unknown tag [%s] encoutered, this may result in a warning in the future." % tag)

0 comments on commit 4823c5e

Please sign in to comment.