Skip to content

Commit

Permalink
Do not replace Galaxy's Python environment for select tools.
Browse files Browse the repository at this point in the history
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 galaxyproject#3238.
Fixes galaxyproject#3224.
Fixes https://biostar.usegalaxy.org/p/20865/.
  • Loading branch information
jmchilton committed Dec 21, 2016
1 parent 22fda44 commit 329ca24
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,16 @@ def output_is_dynamic(output):
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.
Expand Down Expand Up @@ -1288,6 +1298,7 @@ def build_dependency_shell_commands( self, job_directory=None, metadata=False ):
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,
)

Expand Down
23 changes: 16 additions & 7 deletions lib/galaxy/tools/deps/resolvers/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def resolve(self, name, version, type, **kwds):
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)

Expand All @@ -190,7 +192,8 @@ def resolve(self, name, version, type, **kwds):
conda_environment,
exact,
name,
version
version,
preserve_python_environment,
)
else:
if len(conda_environment) > 79:
Expand Down Expand Up @@ -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):
Expand All @@ -267,11 +271,16 @@ def version(self):
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:
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 ):
Expand Down

0 comments on commit 329ca24

Please sign in to comment.