Permalink
Browse files

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.
  • Loading branch information...
jmchilton committed Mar 16, 2015
1 parent 8207026 commit 4823c5e15c16aa871ea50bb7da466068d171f2fb
Showing with 36 additions and 19 deletions.
  1. +1 −16 planemo/commands/cmd_normalize.py
  2. +3 −3 planemo/tool_builder.py
  3. +32 −0 planemo_ext/galaxy/tools/linters/xml_order.py
@@ -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')
@@ -20,9 +20,6 @@
<expand macro="version_command" />
{% endif %}
{%- else %}
<stdio>
<exit_code range="1:" />
</stdio>
<requirements>
{%- for requirement in requirements %}
{{ requirement }}
@@ -31,6 +28,9 @@
{{ container }}
{%- endfor %}
</requirements>
<stdio>
<exit_code range="1:" />
</stdio>
{%- if version_command %}
<version_command>{{ version_command }}</version_command>
{%- endif %}
@@ -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.