Skip to content

Commit ce0dc4e

Browse files
committed
Allow URIs to be used instead of paths for a couple operations.
Depends on galaxy-lib enhancements from galaxyproject/galaxy-lib#52.
1 parent 06bcf19 commit ce0dc4e

File tree

8 files changed

+61
-16
lines changed

8 files changed

+61
-16
lines changed

planemo/commands/cmd_lint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@click.command('lint')
11-
@options.optional_tools_arg(multiple=True)
11+
@options.optional_tools_arg(multiple=True, allow_uris=True)
1212
@options.report_level_option()
1313
@options.report_xunit()
1414
@options.fail_level_option()
@@ -46,12 +46,12 @@
4646
# default=False,
4747
# )
4848
@command_function
49-
def cli(ctx, paths, **kwds):
49+
def cli(ctx, uris, **kwds):
5050
"""Check for common errors and best practices."""
5151
lint_args = build_lint_args(ctx, **kwds)
5252
exit_code = lint_tools_on_path(
5353
ctx,
54-
paths,
54+
uris,
5555
lint_args,
5656
recursive=kwds["recursive"]
5757
)

planemo/commands/cmd_run.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
from planemo.cli import command_function
1010
from planemo.engine import engine_context
1111
from planemo.io import conditionally_captured_io, warn
12+
from planemo.tools import uri_to_path
1213

1314

1415
@click.command('run')
15-
@options.required_tool_arg()
16+
@options.required_tool_arg(allow_uris=True)
1617
@options.required_job_arg()
1718
@options.galaxy_run_options()
1819
@options.galaxy_config_options()
@@ -22,12 +23,13 @@
2223
@options.run_output_json_option()
2324
@options.engine_options()
2425
@command_function
25-
def cli(ctx, path, job_path, **kwds):
26+
def cli(ctx, uri, job_path, **kwds):
2627
"""Planemo command for running tools and jobs.
2728
2829
\b
2930
% planemo run cat1-tool.cwl cat-job.json
3031
"""
32+
path = DEFAULT_TOOL_LOCATION_FETCHER.to_tool_path(uri)
3133
kwds["cwl"] = path.endswith(".cwl")
3234
conformance_test = kwds.get("conformance_test", False)
3335

planemo/commands/cmd_serve.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
from planemo.cli import command_function
66
from planemo.galaxy import galaxy_serve
77
from planemo.runnable import for_paths
8+
from planemo.tools import uris_to_paths
89

910

1011
@click.command('serve')
11-
@options.optional_tools_arg(multiple=True)
12+
@options.optional_tools_arg(multiple=True, allow_uris=True)
1213
@options.galaxy_serve_options()
1314
@options.enable_cwl_option()
1415
@options.galaxy_cwl_root_option()
1516
@command_function
16-
def cli(ctx, paths, **kwds):
17+
def cli(ctx, uris, **kwds):
1718
"""Launch Galaxy instance with specified tools.
1819
1920
The Galaxy tool panel will include just the referenced tool or tools (by
@@ -36,5 +37,6 @@ def cli(ctx, paths, **kwds):
3637
proof yet, so please be careful and do not try this against a production
3738
Galaxy instance.
3839
"""
40+
paths = uris_to_paths(ctx, uris)
3941
runnables = for_paths(paths)
4042
galaxy_serve(ctx, runnables, **kwds)

planemo/cwl/run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def run_cwltool(ctx, path, job_path, **kwds):
7171
if kwds.get("no_container", False):
7272
args.append("--no-container")
7373

74+
args.append("--non-strict")
75+
7476
args.extend([path, job_path])
7577
ctx.vlog("Calling cwltool with arguments %s" % args)
7678
with tempfile.NamedTemporaryFile() as tmp_stdout, \
@@ -81,7 +83,7 @@ def run_cwltool(ctx, path, job_path, **kwds):
8183
ret_code = main.main(
8284
args,
8385
stdout=tmp_stdout,
84-
stderr=tmp_stderr
86+
stderr=tmp_stderr,
8587
)
8688
tmp_stdout.flush()
8789
tmp_stderr.flush()

planemo/options.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,24 @@ def conda_global_option():
509509
)
510510

511511

512-
def required_tool_arg():
512+
def required_tool_arg(allow_uris=False):
513513
""" Decorate click method as requiring the path to a single tool.
514514
"""
515-
arg_type = click.Path(
515+
arg_type_class = click.Path if not allow_uris else UriLike
516+
arg_type = arg_type_class(
516517
exists=True,
517518
file_okay=True,
518519
dir_okay=False,
519520
readable=True,
520521
resolve_path=True,
521522
)
522-
return click.argument("path", metavar="TOOL_PATH", type=arg_type)
523+
if allow_uris:
524+
name = "uri"
525+
metavar = "TOOL_URI"
526+
else:
527+
name = "path"
528+
metavar = "TOOL_PATH"
529+
return click.argument(name, metavar=metavar, type=arg_type)
523530

524531

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

537544

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

558565

559-
def optional_tools_arg(multiple=False):
566+
class UriLike(click.Path):
567+
568+
def convert(self, value, param, ctx):
569+
if "://" in value:
570+
return value
571+
else:
572+
return super(UriLike, self).convert(value, param, ctx)
573+
574+
575+
def optional_tools_arg(multiple=False, allow_uris=False):
560576
""" Decorate click method as optionally taking in the path to a tool
561577
or directory of tools. If no such argument is given the current working
562578
directory will be treated as a directory of tools.
563579
"""
564-
arg_type = click.Path(
580+
arg_type_class = click.Path if not allow_uris else UriLike
581+
arg_type = arg_type_class(
565582
exists=True,
566583
file_okay=True,
567584
dir_okay=True,
568585
readable=True,
569586
resolve_path=True,
570587
)
571-
name = "paths" if multiple else "path"
588+
if allow_uris:
589+
name = "uris" if multiple else "uri"
590+
else:
591+
name = "paths" if multiple else "path"
572592
nargs = -1 if multiple else 1
573593
return click.argument(
574594
name,

planemo/tools.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import traceback
77

88
from galaxy.tools import loader_directory
9+
from galaxy.tools.fetcher import ToolLocationFetcher
910

1011
from planemo.io import error, info
1112

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

1617

18+
def uri_to_path(ctx, uri):
19+
fetcher = ToolLocationFetcher()
20+
return fetcher.to_tool_path(uri)
21+
22+
23+
def uris_to_paths(ctx, uris):
24+
fetcher = ToolLocationFetcher()
25+
paths = []
26+
for uri in uris:
27+
path = fetcher.to_tool_path(uri)
28+
paths.append(path)
29+
return paths
30+
31+
1732
def yield_tool_sources_on_paths(ctx, paths, recursive=False):
1833
for path in paths:
1934
for (tool_path, tool_source) in yield_tool_sources(ctx, path, recursive):

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ virtualenv
1313
lxml
1414
gxformat2>=0.1.1
1515
ephemeris>=0.2.0
16-
galaxy-lib>=17.5.6
16+
galaxy-lib>=17.5.7
1717
html5lib>=0.9999999,!=0.99999999,!=0.999999999,!=1.0b10,!=1.0b09 ; python_version == '2.7'
1818
cwltool==1.0.20170224141733 ; python_version == '2.7'

tests/test_lint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def test_ok_tools(self):
1818
lint_cmd = ["lint", "--urls", ok_tool]
1919
self._check_exit_code(lint_cmd)
2020

21+
def test_ok_http(self):
22+
lint_cmd = ["lint", "https://raw.githubusercontent.com/galaxyproject/planemo/master/tests/data/tools/ok_conditional.xml"]
23+
self._check_exit_code(lint_cmd)
24+
2125
def test_fail_tools(self):
2226
fail_tools = glob.glob("%s/fail_*" % TEST_TOOLS_DIR)
2327
for fail_tool in fail_tools:

0 commit comments

Comments
 (0)