Permalink
Browse files

Overhaul Conda support for recent Galaxy improvements.

Always set a condarc file up when using planemo - this is needed to fix channel handling for galaxy-lib update which sets up a $HOME for every conda command. Also update the list of default channels.
  • Loading branch information...
jmchilton committed Aug 31, 2016
1 parent b93d9dd commit 07d94bddd9d1d132045a3e6055b1f559869161bc
@@ -43,7 +43,7 @@ def cli(ctx, path, **kwds):
% which bowtie2
TODO_PLACE_PATH_HERE
"""
conda_context = build_conda_context(use_planemo_shell_exec=False, **kwds)
conda_context = build_conda_context(ctx, use_planemo_shell_exec=False, **kwds)
conda_targets = collect_conda_targets(
path, conda_context=conda_context
)
@@ -21,5 +21,5 @@ def cli(ctx, **kwds):
license a 3-clause BSD 3 license. Please review full license at
http://docs.continuum.io/anaconda/eula.
"""
conda_context = build_conda_context(**kwds)
conda_context = build_conda_context(ctx, **kwds)
return conda_util.install_conda(conda_context=conda_context)
@@ -15,7 +15,7 @@
@command_function
def cli(ctx, path, **kwds):
"""Install conda packages for tool requirements."""
conda_context = build_conda_context(**kwds)
conda_context = build_conda_context(ctx, **kwds)
return_codes = []
for conda_target in collect_conda_targets(path):
ctx.log("Install conda target %s" % conda_target)
@@ -1,29 +1,37 @@
""" Planemo specific utilities for dealing with conda, extending Galaxy's
features with planemo specific idioms.
"""Planemo specific utilities for dealing with conda.
The extend Galaxy/galaxy-lib's features with planemo specific idioms.
"""
from __future__ import absolute_import

import os

from galaxy.tools.deps import conda_util
from galaxy.tools.deps.requirements import parse_requirements_from_xml
from galaxy.tools.loader_directory import load_tool_elements_from_path

from planemo.io import shell


def build_conda_context(**kwds):
""" Build a Galaxy CondaContext tailored to planemo use
and common command-line arguments.
def build_conda_context(ctx, **kwds):
"""Build a galaxy-lib CondaContext tailored to planemo use.
Using planemo's common command-line/globa config options.
"""
condarc_override_default = os.path.join(ctx.workspace, "condarc")
conda_prefix = kwds.get("conda_prefix", None)
use_planemo_shell = kwds.get("use_planemo_shell_exec", True)
ensure_channels = kwds.get("conda_ensure_channels", "")
condarc_override = kwds.get("condarc", condarc_override_default)
shell_exec = shell if use_planemo_shell else None
return conda_util.CondaContext(conda_prefix=conda_prefix,
ensure_channels=ensure_channels,
condarc_override=condarc_override,
shell_exec=shell_exec)


def collect_conda_targets(path, found_tool_callback=None, conda_context=None):
"""Load CondaTarget objects from supplied artifact sources."""
conda_targets = []
for (tool_path, tool_xml) in load_tool_elements_from_path(path):
if found_tool_callback:
@@ -180,7 +180,7 @@ def docker_galaxy_config(ctx, runnables, for_tests=False, **kwds):
def config_join(*args):
return os.path.join(config_directory, *args)

_handle_dependency_resolution(config_directory, kwds)
_handle_dependency_resolution(ctx, config_directory, kwds)
_handle_job_metrics(config_directory, kwds)

shed_tool_conf = "config/shed_tool_conf.xml"
@@ -289,7 +289,7 @@ def config_join(*args):
galaxy_root = config_join("galaxy-dev")

server_name = "planemo%d" % random.randint(0, 100000)
_handle_dependency_resolution(config_directory, kwds)
_handle_dependency_resolution(ctx, config_directory, kwds)
_handle_job_config_file(config_directory, server_name, kwds)
_handle_job_metrics(config_directory, kwds)
file_path = kwds.get("file_path") or config_join("files")
@@ -1118,7 +1118,7 @@ def _handle_job_config_file(config_directory, server_name, kwds):
kwds["job_config_file"] = job_config_file


def _handle_dependency_resolution(config_directory, kwds):
def _handle_dependency_resolution(ctx, config_directory, kwds):
resolutions_strategies = [
"brew_dependency_resolution",
"dependency_resolvers_config_file",
@@ -1149,16 +1149,19 @@ def _handle_dependency_resolution(config_directory, kwds):
def add_attribute(key, value):
attributes.append('%s="%s"' % (key, value))

conda_prefix_specified = False
for key, default_value in iteritems(dependency_attribute_kwds):
value = kwds.get(key, default_value)
if value != default_value:
conda_prefix_specified = value == "conda_prefix"
# Strip leading prefix (conda_) off attributes
attribute_key = "_".join(key.split("_")[1:])
add_attribute(attribute_key, value)

if not [attribute for attribute in attributes if "prefix" in attribute]:
conda_context = build_conda_context(**kwds)
conda_context = build_conda_context(ctx, **kwds)
if not conda_prefix_specified:
add_attribute("prefix", conda_context.conda_prefix)
add_attribute("condarc_override", conda_context.condarc_override)

attribute_str = " ".join(attributes)

@@ -1173,6 +1176,11 @@ def add_attribute(key, value):
'attributes': attribute_str
})
open(resolvers_conf, "w").write(conf_contents)
ctx.vlog(
"Writing dependency_resolvers_config_file to path %s with contents [%s]",
resolvers_conf,
conf_contents,
)
kwds["dependency_resolvers_config_file"] = resolvers_conf


@@ -432,7 +432,7 @@ def conda_ensure_channels_option():
use_global_config=True,
help=("Ensure conda is configured with specified comma separated "
"list of channels."),
default="r,bioconda"
default="r,bioconda,iuc",
)


0 comments on commit 07d94bd

Please sign in to comment.