Permalink
Browse files

Allow planemo lint to take many paths.

Implements #139.
  • Loading branch information...
jmchilton committed Apr 25, 2015
1 parent 01f2af9 commit 343902dcf08bf01dfbb95d98f4a7b9c32c30d777
Showing with 27 additions and 14 deletions.
  1. +3 −3 planemo/commands/cmd_lint.py
  2. +6 −3 planemo/options.py
  3. +9 −8 planemo/tool_lint.py
  4. +9 −0 tests/test_lint.py
@@ -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"]
)
@@ -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.
@@ -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,
)


@@ -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
@@ -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]

0 comments on commit 343902d

Please sign in to comment.