Skip to content

Commit 8faf661

Browse files
committed
Allow conda_install to work with packages as well as just tools.
1 parent 9c790d0 commit 8faf661

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

planemo/commands/cmd_conda_install.py

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

1111

1212
@click.command('conda_install')
13-
@options.optional_tools_arg(multiple=True)
13+
@options.optional_tools_or_packages_arg(multiple=True)
1414
@options.conda_target_options()
15+
@options.conda_global_option()
1516
@options.conda_auto_init_option()
1617
@command_function
1718
def cli(ctx, paths, **kwds):
@@ -21,7 +22,7 @@ def cli(ctx, paths, **kwds):
2122
for conda_target in collect_conda_targets(ctx, paths):
2223
ctx.log("Install conda target %s" % conda_target)
2324
return_code = conda_util.install_conda_target(
24-
conda_target, conda_context=conda_context
25+
conda_target, conda_context=conda_context, skip_environment=kwds.get("global", False)
2526
)
2627
return_codes.append(return_code)
2728
return coalesce_return_codes(return_codes, assert_at_least_one=True)

planemo/conda.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,37 @@ def collect_conda_targets(ctx, paths, found_tool_callback=None, conda_context=No
6060
appear once in the output.
6161
"""
6262
conda_targets = set([])
63-
for (tool_path, tool_source) in yield_tool_sources_on_paths(ctx, paths):
63+
real_paths = []
64+
for path in paths:
65+
if not os.path.exists(path):
66+
targets = target_str_to_targets(path)
67+
[conda_targets.add(_) for _ in targets]
68+
else:
69+
real_paths.append(path)
70+
71+
for (tool_path, tool_source) in yield_tool_sources_on_paths(ctx, real_paths):
6472
if found_tool_callback:
6573
found_tool_callback(tool_path)
6674
for target in tool_source_conda_targets(tool_source):
6775
conda_targets.add(target)
6876
return conda_targets
6977

7078

79+
# Copied and modified from mulled stuff - need to syncronize these concepts.
80+
def target_str_to_targets(targets_raw):
81+
def parse_target(target_str):
82+
if "=" in target_str:
83+
package_name, version = target_str.split("=", 1)
84+
else:
85+
package_name = target_str
86+
version = None
87+
target = conda_util.CondaTarget(package_name, version)
88+
return target
89+
90+
targets = [parse_target(_) for _ in targets_raw.split(",")]
91+
return targets
92+
93+
7194
def collect_conda_target_lists(ctx, paths, found_tool_callback=None):
7295
"""Load CondaTarget lists from supplied artifact sources.
7396

planemo/options.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,18 @@ def conda_auto_init_option():
481481
)
482482

483483

484+
def conda_global_option():
485+
return planemo_option(
486+
"--global",
487+
is_flag=True,
488+
default=False,
489+
help=("Install Conda dependencies globally instead of in requirement specific "
490+
"environments packaged for tools. If the Conda bin directory is on your "
491+
"PATH, tools may still use binaries but this is more designed for "
492+
"interactive testing and debugging.")
493+
)
494+
495+
484496
def required_tool_arg():
485497
""" Decorate click method as requiring the path to a single tool.
486498
"""
@@ -514,6 +526,20 @@ def _optional_tools_default(ctx, param, value):
514526
return value
515527

516528

529+
def optional_tools_or_packages_arg(multiple=False):
530+
""" Decorate click method as optionally taking in the path to a tool
531+
or directory of tools or a Conda package. If no such argument is given
532+
the current working directory will be treated as a directory of tools.
533+
"""
534+
name = "paths" if multiple else "path"
535+
nargs = -1 if multiple else 1
536+
return click.argument(
537+
name,
538+
metavar="TARGET",
539+
nargs=nargs,
540+
)
541+
542+
517543
def optional_tools_arg(multiple=False):
518544
""" Decorate click method as optionally taking in the path to a tool
519545
or directory of tools. If no such argument is given the current working

0 commit comments

Comments
 (0)