-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Use mamba
under a feature flag to create conda environments
#6815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d34b8d0
c0ad809
0ff60a3
29d8657
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -493,6 +493,23 @@ class Conda(PythonEnvironment): | |
def venv_path(self): | ||
return os.path.join(self.project.doc_path, 'conda', self.version.slug) | ||
|
||
def conda_bin_name(self): | ||
""" | ||
Decide whether use ``mamba`` or ``conda`` to create the environment. | ||
|
||
Return ``mamba`` if the project has ``CONDA_USES_MAMBA`` feature and | ||
``conda`` otherwise. This will be the executable name to be used when | ||
creating the conda environment. | ||
|
||
``mamba`` is really fast to solve dependencies and download channel | ||
metadata on startup. | ||
|
||
See https://github.com/QuantStack/mamba | ||
""" | ||
if self.project.has_feature(Feature.CONDA_USES_MAMBA): | ||
return 'mamba' | ||
return 'conda' | ||
|
||
def _update_conda_startup(self): | ||
""" | ||
Update ``conda`` before use it for the first time. | ||
|
@@ -501,6 +518,8 @@ def _update_conda_startup(self): | |
independently the version of Miniconda that it has installed. | ||
""" | ||
self.build_env.run( | ||
# TODO: use ``self.conda_bin_name()`` once ``mamba`` is installed in | ||
# the Docker image | ||
'conda', | ||
'update', | ||
'--yes', | ||
|
@@ -511,6 +530,18 @@ def _update_conda_startup(self): | |
cwd=self.checkout_path, | ||
) | ||
|
||
def _install_mamba(self): | ||
self.build_env.run( | ||
'conda', | ||
'install', | ||
'--yes', | ||
'--quiet', | ||
'--name=base', | ||
'--channel=conda-forge', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SylvainCorlay! is it possible to install I can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you consider using a miniforge flavor including mamba instead of miniconda. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment from the peanut gallery: regro/conda-metachannel#31 (comment) conda-metachannel service is down, unfortunately. Perhaps if there was a About mamba in miniforge... from what I read in conda-forge/miniforge#23, looks like there is no consensus (the path of least resistance seems to be creating a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't use anything different than regular So, given this current restriction, I was asking if something like @astrojuanlu mentioned already existed (
This was a good idea when @astrojuanlu commented it to me. However, if it's currently down it doesn't seem to be something we can rely on by default 😞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My goal here is to avoid this random problem with the available tools and restrictions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI @humitos miniforge now includes a "mambaforge" installer which has mamba pre-installed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am looking into what we could do to allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @humitos https://pypi.org/project/conda-lock/ You could generate a conda lock file offline, and use it in your script so that no solving is required. |
||
'mamba', | ||
cwd=self.checkout_path, | ||
) | ||
|
||
def setup_base(self): | ||
conda_env_path = os.path.join(self.project.doc_path, 'conda') | ||
version_path = os.path.join(conda_env_path, self.version.slug) | ||
|
@@ -534,8 +565,12 @@ def setup_base(self): | |
self._append_core_requirements() | ||
self._show_environment_yaml() | ||
|
||
# TODO: remove it when ``mamba`` is installed in the Docker image | ||
if self.project.has_feature(Feature.CONDA_USES_MAMBA): | ||
self._install_mamba() | ||
|
||
self.build_env.run( | ||
'conda', | ||
self.conda_bin_name(), | ||
'env', | ||
'create', | ||
'--quiet', | ||
|
@@ -621,6 +656,9 @@ def _get_core_requirements(self): | |
'pillow', | ||
] | ||
|
||
if self.project.has_feature(Feature.CONDA_USES_MAMBA): | ||
conda_requirements.append('pip') | ||
|
||
# Install pip-only things. | ||
pip_requirements = [ | ||
'recommonmark', | ||
|
@@ -648,7 +686,7 @@ def install_core_requirements(self): | |
# Install requirements via ``conda install`` command if they were | ||
# not appended to the ``environment.yml`` file. | ||
cmd = [ | ||
'conda', | ||
self.conda_bin_name(), | ||
'install', | ||
'--yes', | ||
'--quiet', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean resolver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... I think it's the same, but they call it "Solver" :)
https://docs.conda.io/projects/conda/en/latest/api/solver.html#conda.core.solve.Solver