From 05cd16f11cb523345894816ab6cc8165ebe71559 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 20 Dec 2016 13:11:18 -0500 Subject: [PATCH 1/2] Fix explicit Docker container resolution. Fix thanks to @stevecassidy. Fixes #3207. Broken with introduction of container resolution stradegies in #2986. --- lib/galaxy/tools/deps/container_resolvers/explicit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/tools/deps/container_resolvers/explicit.py b/lib/galaxy/tools/deps/container_resolvers/explicit.py index 851f0c1f99c..be83e0d92f7 100644 --- a/lib/galaxy/tools/deps/container_resolvers/explicit.py +++ b/lib/galaxy/tools/deps/container_resolvers/explicit.py @@ -20,7 +20,7 @@ class ExplicitContainerResolver(ContainerResolver): a correct container. """ for container_description in tool_info.container_descriptions: - if self._container_type_enabled(container_description): - return True + if self._container_type_enabled(container_description, enabled_container_types): + return container_description - return False + return None From fe2a1d8ade4fbda158ae035c78133258d7fec099 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 21 Dec 2016 11:34:14 -0500 Subject: [PATCH 2/2] Do not replace Galaxy's Python environment for select tools. This has never happened in my testing, but there have been multiple reports of Conda crafting environments for the set metadata tool that include Python. When this happens Galaxy's Python environment is lost and the tool cannot function properly. Fixes #3238. Fixes #3224. Fixes https://biostar.usegalaxy.org/p/20865/. Rebased to add a comment as suggested by @nsoranzo. --- lib/galaxy/tools/__init__.py | 11 ++++++++++ lib/galaxy/tools/deps/resolvers/conda.py | 26 +++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 9410f15197a..77597db63b9 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -375,6 +375,16 @@ class Tool( object, Dictifiable ): def valid_input_states( self ): return model.Dataset.valid_input_states + @property + def requires_galaxy_python_environment(self): + """Indicates this tool's runtime requires Galaxy's Python environment.""" + # All special tool types (data source, history import/export, etc...) + # seem to require Galaxy's Python. + return self.tool_type != "default" or self.id in [ + "__SET_METADATA__", + "upload1", + ] + def __get_job_tool_configuration(self, job_params=None): """Generalized method for getting this tool's job configuration. @@ -1288,6 +1298,7 @@ class Tool( object, Dictifiable ): installed_tool_dependencies=self.installed_tool_dependencies, tool_dir=self.tool_dir, job_directory=job_directory, + preserve_python_environment=self.requires_galaxy_python_environment, metadata=metadata, ) diff --git a/lib/galaxy/tools/deps/resolvers/conda.py b/lib/galaxy/tools/deps/resolvers/conda.py index 13477f77100..5a3eabaef22 100644 --- a/lib/galaxy/tools/deps/resolvers/conda.py +++ b/lib/galaxy/tools/deps/resolvers/conda.py @@ -164,6 +164,8 @@ class CondaDependencyResolver(DependencyResolver, ListableDependencyResolver, In log.warning("Conda dependency resolver not sent job directory.") return NullDependency(version=version, name=name) + preserve_python_environment = kwds.get("preserve_python_environment", False) + if not is_installed and self.auto_install: is_installed = self.install_dependency(name=name, version=version, type=type) @@ -190,7 +192,8 @@ class CondaDependencyResolver(DependencyResolver, ListableDependencyResolver, In conda_environment, exact, name, - version + version, + preserve_python_environment, ) else: if len(conda_environment) > 79: @@ -247,12 +250,13 @@ class CondaDependency(Dependency): dict_collection_visible_keys = Dependency.dict_collection_visible_keys + ['environment_path', 'name', 'version'] dependency_type = 'conda' - def __init__(self, activate, environment_path, exact, name=None, version=None): + def __init__(self, activate, environment_path, exact, name=None, version=None, preserve_python_environment=False): self.activate = activate self.environment_path = environment_path self._exact = exact self._name = name self._version = version + self._preserve_python_environment = preserve_python_environment @property def exact(self): @@ -267,11 +271,19 @@ class CondaDependency(Dependency): return self._version def shell_commands(self, requirement): - return """[ "$CONDA_DEFAULT_ENV" = "%s" ] || . %s '%s' 2>&1 """ % ( - self.environment_path, - self.activate, - self.environment_path - ) + if self._preserve_python_environment: + # On explicit testing the only such requirement I am aware of is samtools - and it seems to work + # fine with just appending the PATH as done below. Other tools may require additional + # variables in the future. + return """export PATH=$PATH:'%s/bin' """ % ( + self.environment_path, + ) + else: + return """[ "$CONDA_DEFAULT_ENV" = "%s" ] || . %s '%s' 2>&1 """ % ( + self.environment_path, + self.activate, + self.environment_path + ) def _string_as_bool( value ):