Skip to content

Commit 343902d

Browse files
committed
Allow planemo lint to take many paths.
Implements #139.
1 parent 01f2af9 commit 343902d

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

planemo/commands/cmd_lint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010

1111

1212
@click.command('lint')
13-
@options.optional_tools_arg()
13+
@options.optional_tools_arg(-1)
1414
@options.report_level_option()
1515
@options.fail_level_option()
1616
@options.skip_option()
1717
@options.lint_xsd_option()
1818
@options.recursive_option()
1919
@pass_context
20-
def cli(ctx, path, **kwds):
20+
def cli(ctx, paths, **kwds):
2121
"""Check specified tool(s) for common errors and adherence to best
2222
practices.
2323
"""
2424
lint_args = build_lint_args(ctx, **kwds)
2525
exit = lint_tools_on_path(
2626
ctx,
27-
path,
27+
paths,
2828
lint_args,
2929
recursive=kwds["recursive"]
3030
)

planemo/options.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def required_tool_arg():
133133
return click.argument('path', metavar="TOOL_PATH", type=arg_type)
134134

135135

136-
def optional_tools_arg():
136+
def optional_tools_arg(multiple=False):
137137
""" Decorate click method as optionally taking in the path to a tool
138138
or directory of tools. If no such argument is given the current working
139139
directory will be treated as a directory of tools.
@@ -145,11 +145,14 @@ def optional_tools_arg():
145145
readable=True,
146146
resolve_path=True,
147147
)
148+
name = 'paths' if multiple else 'path'
149+
nargs = -1 if multiple else 1
148150
return click.argument(
149-
'path',
151+
name,
150152
metavar="TOOL_PATH",
151153
default=".",
152-
type=arg_type
154+
type=arg_type,
155+
nargs=nargs,
153156
)
154157

155158

planemo/tool_lint.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
SHED_FILES = ["tool_dependencies.xml", "repository_dependencies.xml"]
1414

1515

16-
def lint_tools_on_path(ctx, path, lint_args, **kwds):
16+
def lint_tools_on_path(ctx, paths, lint_args, **kwds):
1717
assert_tools = kwds.get("assert_tools", True)
1818
recursive = kwds.get("recursive", False)
1919
exit = 0
2020
valid_tools = 0
21-
for (tool_path, tool_xml) in yield_tool_xmls(ctx, path, recursive):
22-
info("Linting tool %s" % tool_path)
23-
if not lint_xml(tool_xml, **lint_args):
24-
error("Failed linting")
25-
exit = 1
26-
else:
27-
valid_tools += 1
21+
for path in paths:
22+
for (tool_path, tool_xml) in yield_tool_xmls(ctx, path, recursive):
23+
info("Linting tool %s" % tool_path)
24+
if not lint_xml(tool_xml, **lint_args):
25+
error("Failed linting")
26+
exit = 1
27+
else:
28+
valid_tools += 1
2829
if exit == 0 and valid_tools == 0 and assert_tools:
2930
exit = 2
3031
return exit

tests/test_lint.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ def test_fail_tools(self):
2222
lint_cmd = ["lint", fail_tool]
2323
self._check_exit_code(lint_cmd, exit_code=1)
2424

25+
def test_lint_multiple(self):
26+
names = ["fail_citation.xml", "fail_order.xml"]
27+
paths = list(map(lambda p: os.path.join(TEST_TOOLS_DIR, p), names))
28+
self._check_exit_code(["lint"] + paths, exit_code=1)
29+
self._check_exit_code(
30+
["lint", "--skip", "citations,xml_order"] + paths,
31+
exit_code=0
32+
)
33+
2534
def test_skips(self):
2635
fail_citation = os.path.join(TEST_TOOLS_DIR, "fail_citation.xml")
2736
lint_cmd = ["lint", fail_citation]

0 commit comments

Comments
 (0)