Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit bdacc4d

Browse files
committed
If initializing Conda with local packages enabled, ensure conda-build is installed.
This is required by Conda. Also provide a flag to force this behavior, when using planemo conda-build should always be installed I think - it is a developer tool after all.
1 parent 1a6c532 commit bdacc4d

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

galaxy/tools/deps/conda_util.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
UNVERSIONED_ENV_DIR_NAME = re.compile(r"__(.*)@_uv_")
3131
USE_PATH_EXEC_DEFAULT = False
3232
CONDA_VERSION = "4.2.13"
33+
CONDA_BUILD_VERSION = "2.1.5"
3334
USE_LOCAL_DEFAULT = False
3435

3536

@@ -86,19 +87,31 @@ def __init__(self, conda_prefix=None, conda_exec=None,
8687
self.ensured_channels = False
8788
self._conda_version = None
8889
self._miniconda_version = None
90+
self._conda_build_available = None
8991
self._use_local = use_local
9092

9193
@property
9294
def conda_version(self):
9395
if self._conda_version is None:
94-
self._guess_conda_version()
96+
self._guess_conda_properties()
9597
return self._conda_version
9698

97-
def _guess_conda_version(self):
99+
@property
100+
def conda_build_available(self):
101+
if self._conda_build_available is None:
102+
self._guess_conda_properties()
103+
return self._conda_build_available
104+
105+
@property
106+
def use_local(self):
107+
return self._use_local
108+
109+
def _guess_conda_properties(self):
98110
conda_meta_path = self._conda_meta_path
99111
# Perhaps we should call "conda info --json" and parse it but for now we are going
100112
# to assume the default.
101113
conda_version = LooseVersion(CONDA_VERSION)
114+
conda_build_available = False
102115
miniconda_version = "3"
103116

104117
if os.path.exists(conda_meta_path):
@@ -113,9 +126,12 @@ def _guess_conda_version(self):
113126
conda_version = LooseVersion(version)
114127
if package == "python" and version.startswith("2"):
115128
miniconda_version = "2"
129+
if package == "conda-build":
130+
conda_build_available = True
116131

117132
self._conda_version = conda_version
118133
self._miniconda_version = miniconda_version
134+
self._conda_build_available = conda_build_available
119135

120136
@property
121137
def _conda_meta_path(self):
@@ -138,6 +154,13 @@ def ensure_channels_configured(self):
138154
if changed:
139155
self.save_condarc(conda_conf)
140156

157+
def ensure_conda_build_installed_if_needed(self):
158+
if self.use_local and not self.conda_build_available:
159+
conda_targets = [CondaTarget("conda-build", version=CONDA_BUILD_VERSION)]
160+
return install_conda_targets(conda_targets, env_name=None, conda_context=self)
161+
else:
162+
return 0
163+
141164
def conda_info(self):
142165
if self.conda_exec is not None:
143166
info_out = commands.execute([self.conda_exec, "info", "--json"])
@@ -393,13 +416,18 @@ def hash_conda_packages(conda_packages, conda_target=None):
393416

394417
# shell makes sense for planemo, in Galaxy this should just execute
395418
# these commands as Python
396-
def install_conda(conda_context=None):
419+
def install_conda(conda_context=None, force_conda_build=False):
397420
conda_context = _ensure_conda_context(conda_context)
398421
f, script_path = tempfile.mkstemp(suffix=".sh", prefix="conda_install")
399422
os.close(f)
400423
download_cmd = " ".join(commands.download_command(conda_link(), to=script_path, quote_url=True))
401424
install_cmd = "bash '%s' -b -p '%s'" % (script_path, conda_context.conda_prefix)
402-
fix_version_cmd = "%s install -y -q conda=%s " % (os.path.join(conda_context.conda_prefix, 'bin/conda'), CONDA_VERSION)
425+
package_targets = [
426+
"conda=%s" % CONDA_VERSION,
427+
]
428+
if force_conda_build or conda_context.use_local:
429+
package_targets.append("conda-build=%s" % CONDA_BUILD_VERSION)
430+
fix_version_cmd = "%s install -y -q %s " % (os.path.join(conda_context.conda_prefix, 'bin/conda'), " ".join(package_targets))
403431
full_command = "%s && %s && %s" % (download_cmd, install_cmd, fix_version_cmd)
404432
try:
405433
log.info("Installing Conda, this may take several minutes.")

galaxy/tools/deps/resolvers/conda.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def get_option(name):
113113
self.auto_init = _string_as_bool(get_option("auto_init"))
114114
self.conda_context = conda_context
115115
self.disabled = not galaxy.tools.deps.installable.ensure_installed(conda_context, install_conda, self.auto_init)
116+
if self.auto_init and not self.disabled:
117+
self.conda_context.ensure_conda_build_installed_if_needed()
116118
self.auto_install = auto_install
117119
self.copy_dependencies = copy_dependencies
118120

0 commit comments

Comments
 (0)