Skip to content

Commit 26e3cdb

Browse files
committed
More linting configurablity.
Add --skip argument to lint and shed_lint to pass in modules to skip while linting - I think the common ones are going to be citations and xml_order - so that would be --skip 'citations,xml_order' for instance. (TODO: Probably worth still catching unknown top-level tags even if xml_order is disabled - so those should be split out I guess). A default value for skip can be specified by specifing a list of items in ``~/.planemo.yml`` under a ``lint_skip`` key. Also improves the display of linting so the short name is what is display - e.g. user will now see "Applying linter citations" and not "Appling linter lint_citations".
1 parent e7886d8 commit 26e3cdb

File tree

7 files changed

+70
-9
lines changed

7 files changed

+70
-9
lines changed

planemo/commands/cmd_lint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
@options.optional_tools_arg()
1414
@options.report_level_option()
1515
@options.fail_level_option()
16+
@options.skip_option()
1617
@options.lint_xsd_option()
1718
@pass_context
1819
def cli(ctx, path, **kwds):
1920
"""Check specified tool(s) for common errors and adherence to best
2021
practices.
2122
"""
22-
lint_args = build_lint_args(**kwds)
23+
lint_args = build_lint_args(ctx, **kwds)
2324
exit = lint_tools_on_path(ctx, path, lint_args)
2425
sys.exit(exit)

planemo/options.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,17 @@ def report_level_option():
278278
)
279279

280280

281+
def skip_option():
282+
return click.option(
283+
"-s",
284+
"--skip",
285+
default=None,
286+
help=("Comma-separated list of lint tests to skip (e.g send ."
287+
"--skip 'citations,xml_order' to skip linting of citations "
288+
"and best-practice XML ordering.")
289+
)
290+
291+
281292
def fail_level_option():
282293
return click.option(
283294
'--fail_level',

planemo/shed_lint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
def lint_repository(ctx, path, **kwds):
4141
info("Linting repository %s" % path)
42-
lint_args = build_lint_args(**kwds)
42+
lint_args = build_lint_args(ctx, **kwds)
4343
lint_ctx = LintContext(lint_args["level"])
4444
lint_ctx.lint(
4545
"tool_dependencies",

planemo/tool_lint.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@ def yield_tool_xmls(ctx, path):
3838
yield (tool_path, tool_xml)
3939

4040

41-
def build_lint_args(**kwds):
41+
def build_lint_args(ctx, **kwds):
4242
report_level = kwds.get("report_level", "all")
4343
fail_level = kwds.get("fail_level", "warn")
44+
skip = kwds.get("skip", None)
45+
if skip is None:
46+
skip = ctx.global_config.get("lint_skip", "")
47+
if isinstance(skip, list):
48+
skip = ",".join(skip)
49+
50+
skip_types = [s.strip() for s in skip.split(",")]
4451
lint_args = dict(
4552
level=report_level,
4653
fail_level=fail_level,
47-
extra_modules=_lint_extra_modules(**kwds)
54+
extra_modules=_lint_extra_modules(**kwds),
55+
skip_types=skip_types,
4856
)
4957
return lint_args
5058

planemo_ext/galaxy/tools/lint.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
LEVEL_ERROR = "error"
88

99

10-
def lint_xml(tool_xml, level=LEVEL_ALL, fail_level=LEVEL_WARN, extra_modules=[]):
11-
lint_context = LintContext(level=level)
10+
def lint_xml(tool_xml, level=LEVEL_ALL, fail_level=LEVEL_WARN, extra_modules=[], skip_types=[]):
11+
lint_context = LintContext(level=level, skip_types=skip_types)
1212
lint_xml_with(lint_context, tool_xml, extra_modules)
1313
return not lint_context.failed(fail_level)
1414

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

2626
class LintContext(object):
2727

28-
def __init__(self, level):
28+
def __init__(self, level, skip_types=[]):
29+
self.skip_types = skip_types
2930
self.level = level
3031
self.found_errors = False
3132
self.found_warns = False
3233

3334
def lint(self, name, lint_func, lint_target):
34-
name = name.replace("tsts", "tests")
35+
name = name.replace("tsts", "tests")[len("lint_"):]
36+
if name in self.skip_types:
37+
return
3538
self.printed_linter_info = False
3639
self.valid_messages = []
3740
self.info_messages = []
@@ -42,7 +45,6 @@ def lint(self, name, lint_func, lint_target):
4245
if self.error_messages:
4346
status = "FAIL"
4447
elif self.warn_messages:
45-
4648
status = "WARNING"
4749
else:
4850
status = "CHECK"

tests/data/tools/fail_citation.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<tool id="copy" name="Copy Dataset" version="1.0">
2+
<description>copies a dataset</description>
3+
<command>
4+
cp $input $output
5+
</command>
6+
<inputs>
7+
<param name="input1" type="data" format="txt" label="Concatenate Dataset"/>
8+
</inputs>
9+
<outputs>
10+
<data name="output" format="txt"/>
11+
</outputs>
12+
<tests>
13+
<test expect_failure="true" expect_exit_code="1">
14+
<param name="input1" value="1.bed"/>
15+
<assert_stdout>
16+
<has_line line="Indexed 0 sequences" />
17+
</assert_stdout>
18+
<assert_stderr>
19+
<has_line line="Identifier 'gi|16127999|ref|NP_414546.1|' not found in sequence file" />
20+
</assert_stderr>
21+
</test>
22+
</tests>
23+
<help>
24+
Some Awesome Help!
25+
</help>
26+
</tool>

tests/test_lint.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import glob
23

34
from .test_utils import CliTestCase
@@ -17,3 +18,15 @@ def test_fail_tools(self):
1718
for fail_tool in fail_tools:
1819
lint_cmd = ["lint", fail_tool]
1920
self._check_exit_code(lint_cmd, exit_code=1)
21+
22+
def test_skips(self):
23+
fail_citation = os.path.join(TEST_TOOLS_DIR, "fail_citation.xml")
24+
lint_cmd = ["lint", fail_citation]
25+
self._check_exit_code(lint_cmd, exit_code=1)
26+
27+
lint_cmd = ["lint", "--skip", "citations", fail_citation]
28+
self._check_exit_code(lint_cmd, exit_code=0)
29+
30+
# Check string splitting and stuff.
31+
lint_cmd = ["lint", "--skip", "xml_order, citations", fail_citation]
32+
self._check_exit_code(lint_cmd, exit_code=0)

0 commit comments

Comments
 (0)