Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion planemo/commands/cmd_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
@options.optional_tools_arg()
@options.report_level_option()
@options.fail_level_option()
@options.skip_option()
@options.lint_xsd_option()
@pass_context
def cli(ctx, path, **kwds):
"""Check specified tool(s) for common errors and adherence to best
practices.
"""
lint_args = build_lint_args(**kwds)
lint_args = build_lint_args(ctx, **kwds)
exit = lint_tools_on_path(ctx, path, lint_args)
sys.exit(exit)
11 changes: 11 additions & 0 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ def report_level_option():
)


def skip_option():
return click.option(
"-s",
"--skip",
default=None,
help=("Comma-separated list of lint tests to skip (e.g send ."
"--skip 'citations,xml_order' to skip linting of citations "
"and best-practice XML ordering.")
)


def fail_level_option():
return click.option(
'--fail_level',
Expand Down
2 changes: 1 addition & 1 deletion planemo/shed_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

def lint_repository(ctx, path, **kwds):
info("Linting repository %s" % path)
lint_args = build_lint_args(**kwds)
lint_args = build_lint_args(ctx, **kwds)
lint_ctx = LintContext(lint_args["level"])
lint_ctx.lint(
"tool_dependencies",
Expand Down
12 changes: 10 additions & 2 deletions planemo/tool_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ def yield_tool_xmls(ctx, path):
yield (tool_path, tool_xml)


def build_lint_args(**kwds):
def build_lint_args(ctx, **kwds):
report_level = kwds.get("report_level", "all")
fail_level = kwds.get("fail_level", "warn")
skip = kwds.get("skip", None)
if skip is None:
skip = ctx.global_config.get("lint_skip", "")
if isinstance(skip, list):
skip = ",".join(skip)

skip_types = [s.strip() for s in skip.split(",")]
lint_args = dict(
level=report_level,
fail_level=fail_level,
extra_modules=_lint_extra_modules(**kwds)
extra_modules=_lint_extra_modules(**kwds),
skip_types=skip_types,
)
return lint_args

Expand Down
12 changes: 7 additions & 5 deletions planemo_ext/galaxy/tools/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
LEVEL_ERROR = "error"


def lint_xml(tool_xml, level=LEVEL_ALL, fail_level=LEVEL_WARN, extra_modules=[]):
lint_context = LintContext(level=level)
def lint_xml(tool_xml, level=LEVEL_ALL, fail_level=LEVEL_WARN, extra_modules=[], skip_types=[]):
lint_context = LintContext(level=level, skip_types=skip_types)
lint_xml_with(lint_context, tool_xml, extra_modules)
return not lint_context.failed(fail_level)

Expand All @@ -25,13 +25,16 @@ def lint_xml_with(lint_context, tool_xml, extra_modules=[]):

class LintContext(object):

def __init__(self, level):
def __init__(self, level, skip_types=[]):
self.skip_types = skip_types
self.level = level
self.found_errors = False
self.found_warns = False

def lint(self, name, lint_func, lint_target):
name = name.replace("tsts", "tests")
name = name.replace("tsts", "tests")[len("lint_"):]
if name in self.skip_types:
return
self.printed_linter_info = False
self.valid_messages = []
self.info_messages = []
Expand All @@ -42,7 +45,6 @@ def lint(self, name, lint_func, lint_target):
if self.error_messages:
status = "FAIL"
elif self.warn_messages:

status = "WARNING"
else:
status = "CHECK"
Expand Down
26 changes: 26 additions & 0 deletions tests/data/tools/fail_citation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<tool id="copy" name="Copy Dataset" version="1.0">
<description>copies a dataset</description>
<command>
cp $input $output
</command>
<inputs>
<param name="input1" type="data" format="txt" label="Concatenate Dataset"/>
</inputs>
<outputs>
<data name="output" format="txt"/>
</outputs>
<tests>
<test expect_failure="true" expect_exit_code="1">
<param name="input1" value="1.bed"/>
<assert_stdout>
<has_line line="Indexed 0 sequences" />
</assert_stdout>
<assert_stderr>
<has_line line="Identifier 'gi|16127999|ref|NP_414546.1|' not found in sequence file" />
</assert_stderr>
</test>
</tests>
<help>
Some Awesome Help!
</help>
</tool>
13 changes: 13 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import glob

from .test_utils import CliTestCase
Expand All @@ -17,3 +18,15 @@ def test_fail_tools(self):
for fail_tool in fail_tools:
lint_cmd = ["lint", fail_tool]
self._check_exit_code(lint_cmd, exit_code=1)

def test_skips(self):
fail_citation = os.path.join(TEST_TOOLS_DIR, "fail_citation.xml")
lint_cmd = ["lint", fail_citation]
self._check_exit_code(lint_cmd, exit_code=1)

lint_cmd = ["lint", "--skip", "citations", fail_citation]
self._check_exit_code(lint_cmd, exit_code=0)

# Check string splitting and stuff.
lint_cmd = ["lint", "--skip", "xml_order, citations", fail_citation]
self._check_exit_code(lint_cmd, exit_code=0)