Skip to content

Commit

Permalink
Allow planemo lint to take many paths.
Browse files Browse the repository at this point in the history
Implements #139.
  • Loading branch information
jmchilton committed Apr 25, 2015
1 parent 01f2af9 commit 343902d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions planemo/commands/cmd_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@


@click.command('lint')
@options.optional_tools_arg()
@options.optional_tools_arg(-1)
@options.report_level_option()
@options.fail_level_option()
@options.skip_option()
@options.lint_xsd_option()
@options.recursive_option()
@pass_context
def cli(ctx, path, **kwds):
def cli(ctx, paths, **kwds):
"""Check specified tool(s) for common errors and adherence to best
practices.
"""
lint_args = build_lint_args(ctx, **kwds)
exit = lint_tools_on_path(
ctx,
path,
paths,
lint_args,
recursive=kwds["recursive"]
)
Expand Down
9 changes: 6 additions & 3 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def required_tool_arg():
return click.argument('path', metavar="TOOL_PATH", type=arg_type)


def optional_tools_arg():
def optional_tools_arg(multiple=False):
""" Decorate click method as optionally taking in the path to a tool
or directory of tools. If no such argument is given the current working
directory will be treated as a directory of tools.
Expand All @@ -145,11 +145,14 @@ def optional_tools_arg():
readable=True,
resolve_path=True,
)
name = 'paths' if multiple else 'path'
nargs = -1 if multiple else 1
return click.argument(
'path',
name,
metavar="TOOL_PATH",
default=".",
type=arg_type
type=arg_type,
nargs=nargs,
)


Expand Down
17 changes: 9 additions & 8 deletions planemo/tool_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
SHED_FILES = ["tool_dependencies.xml", "repository_dependencies.xml"]


def lint_tools_on_path(ctx, path, lint_args, **kwds):
def lint_tools_on_path(ctx, paths, lint_args, **kwds):
assert_tools = kwds.get("assert_tools", True)
recursive = kwds.get("recursive", False)
exit = 0
valid_tools = 0
for (tool_path, tool_xml) in yield_tool_xmls(ctx, path, recursive):
info("Linting tool %s" % tool_path)
if not lint_xml(tool_xml, **lint_args):
error("Failed linting")
exit = 1
else:
valid_tools += 1
for path in paths:
for (tool_path, tool_xml) in yield_tool_xmls(ctx, path, recursive):
info("Linting tool %s" % tool_path)
if not lint_xml(tool_xml, **lint_args):
error("Failed linting")
exit = 1
else:
valid_tools += 1
if exit == 0 and valid_tools == 0 and assert_tools:
exit = 2
return exit
Expand Down
9 changes: 9 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def test_fail_tools(self):
lint_cmd = ["lint", fail_tool]
self._check_exit_code(lint_cmd, exit_code=1)

def test_lint_multiple(self):
names = ["fail_citation.xml", "fail_order.xml"]
paths = list(map(lambda p: os.path.join(TEST_TOOLS_DIR, p), names))
self._check_exit_code(["lint"] + paths, exit_code=1)
self._check_exit_code(
["lint", "--skip", "citations,xml_order"] + paths,
exit_code=0
)

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

0 comments on commit 343902d

Please sign in to comment.