Permalink
Browse files

Allow URIs to be used instead of paths for a couple operations.

Depends on galaxy-lib enhancements from galaxyproject/galaxy-lib#52.
  • Loading branch information...
jmchilton committed Mar 9, 2017
1 parent 06bcf19 commit ce0dc4e31ef2ec3ab72b4db58a08f5e0483a76cf
@@ -8,7 +8,7 @@


@click.command('lint')
@options.optional_tools_arg(multiple=True)
@options.optional_tools_arg(multiple=True, allow_uris=True)
@options.report_level_option()
@options.report_xunit()
@options.fail_level_option()
@@ -46,12 +46,12 @@
# default=False,
# )
@command_function
def cli(ctx, paths, **kwds):
def cli(ctx, uris, **kwds):
"""Check for common errors and best practices."""
lint_args = build_lint_args(ctx, **kwds)
exit_code = lint_tools_on_path(
ctx,
paths,
uris,
lint_args,
recursive=kwds["recursive"]
)
@@ -9,10 +9,11 @@
from planemo.cli import command_function
from planemo.engine import engine_context
from planemo.io import conditionally_captured_io, warn
from planemo.tools import uri_to_path


@click.command('run')
@options.required_tool_arg()
@options.required_tool_arg(allow_uris=True)
@options.required_job_arg()
@options.galaxy_run_options()
@options.galaxy_config_options()
@@ -22,12 +23,13 @@
@options.run_output_json_option()
@options.engine_options()
@command_function
def cli(ctx, path, job_path, **kwds):
def cli(ctx, uri, job_path, **kwds):
"""Planemo command for running tools and jobs.
\b
% planemo run cat1-tool.cwl cat-job.json
"""
path = DEFAULT_TOOL_LOCATION_FETCHER.to_tool_path(uri)
kwds["cwl"] = path.endswith(".cwl")
conformance_test = kwds.get("conformance_test", False)

@@ -5,15 +5,16 @@
from planemo.cli import command_function
from planemo.galaxy import galaxy_serve
from planemo.runnable import for_paths
from planemo.tools import uris_to_paths


@click.command('serve')
@options.optional_tools_arg(multiple=True)
@options.optional_tools_arg(multiple=True, allow_uris=True)
@options.galaxy_serve_options()
@options.enable_cwl_option()
@options.galaxy_cwl_root_option()
@command_function
def cli(ctx, paths, **kwds):
def cli(ctx, uris, **kwds):
"""Launch Galaxy instance with specified tools.
The Galaxy tool panel will include just the referenced tool or tools (by
@@ -36,5 +37,6 @@ def cli(ctx, paths, **kwds):
proof yet, so please be careful and do not try this against a production
Galaxy instance.
"""
paths = uris_to_paths(ctx, uris)
runnables = for_paths(paths)
galaxy_serve(ctx, runnables, **kwds)
@@ -71,6 +71,8 @@ def run_cwltool(ctx, path, job_path, **kwds):
if kwds.get("no_container", False):
args.append("--no-container")

args.append("--non-strict")

args.extend([path, job_path])
ctx.vlog("Calling cwltool with arguments %s" % args)
with tempfile.NamedTemporaryFile() as tmp_stdout, \
@@ -81,7 +83,7 @@ def run_cwltool(ctx, path, job_path, **kwds):
ret_code = main.main(
args,
stdout=tmp_stdout,
stderr=tmp_stderr
stderr=tmp_stderr,
)
tmp_stdout.flush()
tmp_stderr.flush()
@@ -509,17 +509,24 @@ def conda_global_option():
)


def required_tool_arg():
def required_tool_arg(allow_uris=False):
""" Decorate click method as requiring the path to a single tool.
"""
arg_type = click.Path(
arg_type_class = click.Path if not allow_uris else UriLike
arg_type = arg_type_class(
exists=True,
file_okay=True,
dir_okay=False,
readable=True,
resolve_path=True,
)
return click.argument("path", metavar="TOOL_PATH", type=arg_type)
if allow_uris:
name = "uri"
metavar = "TOOL_URI"
else:
name = "path"
metavar = "TOOL_PATH"
return click.argument(name, metavar=metavar, type=arg_type)


def required_job_arg():
@@ -536,7 +543,7 @@ def required_job_arg():


def _optional_tools_default(ctx, param, value):
if param.name == "paths" and len(value) == 0:
if param.name in ["paths", "uris"] and len(value) == 0:
return [os.path.abspath(os.getcwd())]
else:
return value
@@ -556,19 +563,32 @@ def optional_tools_or_packages_arg(multiple=False):
)


def optional_tools_arg(multiple=False):
class UriLike(click.Path):

def convert(self, value, param, ctx):
if "://" in value:
return value
else:
return super(UriLike, self).convert(value, param, ctx)


def optional_tools_arg(multiple=False, allow_uris=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.
"""
arg_type = click.Path(
arg_type_class = click.Path if not allow_uris else UriLike
arg_type = arg_type_class(
exists=True,
file_okay=True,
dir_okay=True,
readable=True,
resolve_path=True,
)
name = "paths" if multiple else "path"
if allow_uris:
name = "uris" if multiple else "uri"
else:
name = "paths" if multiple else "path"
nargs = -1 if multiple else 1
return click.argument(
name,
@@ -6,6 +6,7 @@
import traceback

from galaxy.tools import loader_directory
from galaxy.tools.fetcher import ToolLocationFetcher

from planemo.io import error, info

@@ -14,6 +15,20 @@
SHED_FILES = ["tool_dependencies.xml", "repository_dependencies.xml"]


def uri_to_path(ctx, uri):
fetcher = ToolLocationFetcher()
return fetcher.to_tool_path(uri)


def uris_to_paths(ctx, uris):
fetcher = ToolLocationFetcher()
paths = []
for uri in uris:
path = fetcher.to_tool_path(uri)
paths.append(path)
return paths


def yield_tool_sources_on_paths(ctx, paths, recursive=False):
for path in paths:
for (tool_path, tool_source) in yield_tool_sources(ctx, path, recursive):
@@ -13,6 +13,6 @@ virtualenv
lxml
gxformat2>=0.1.1
ephemeris>=0.2.0
galaxy-lib>=17.5.6
galaxy-lib>=17.5.7
html5lib>=0.9999999,!=0.99999999,!=0.999999999,!=1.0b10,!=1.0b09 ; python_version == '2.7'
cwltool==1.0.20170224141733 ; python_version == '2.7'
@@ -18,6 +18,10 @@ def test_ok_tools(self):
lint_cmd = ["lint", "--urls", ok_tool]
self._check_exit_code(lint_cmd)

def test_ok_http(self):
lint_cmd = ["lint", "https://raw.githubusercontent.com/galaxyproject/planemo/master/tests/data/tools/ok_conditional.xml"]
self._check_exit_code(lint_cmd)

def test_fail_tools(self):
fail_tools = glob.glob("%s/fail_*" % TEST_TOOLS_DIR)
for fail_tool in fail_tools:

0 comments on commit ce0dc4e

Please sign in to comment.