Skip to content
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

Allow to mamba install environments #2204

Closed
janjagusch opened this issue Jan 13, 2022 · 5 comments · Fixed by #2207
Closed

Allow to mamba install environments #2204

janjagusch opened this issue Jan 13, 2022 · 5 comments · Fixed by #2207
Labels

Comments

@janjagusch
Copy link

Thanks for maintaining pre-commit, we really enjoying working with it!

When installing conda environments, mamba is often the preferred option, as it is faster and requires less memory when solving an environment.

As of today, pre-commit uses conda for creating environments, as this is hard-coded into the source code:

with clean_path_on_failure(env_dir):
cmd_output_b(
'conda', 'env', 'create', '-p', env_dir, '--file',
'environment.yml', cwd=prefix.prefix_dir,
)

We have a use case, where we want to install pre-commit hooks in CI, but the installation fails because of out-of-memory errors. Installing the same environment with mamba however, succeeds.

It would be nice if one could define whether pre-commit uses conda or mamba for installing environments. This could for example be accomplished by introducing an environment variable PRE_COMMIT_USE_MAMBA. If there is a better way to pass such configuration to pre-commit, please let me know.

I'd be glad to work on this feature, if this is something you'd like to see added to pre-commit.

@asottile
Copy link
Member

if it's drop in presumably you could ln -s $(which mamba) ~/bin/conda or something of the sort?

@xhochy
Copy link
Contributor

xhochy commented Jan 14, 2022

Thanks @janjagusch for opening this issue. I also thought already about opening one here. There are some open points why I didn't yet make one here:

  • mamba is a 90% drop-in for the end user, you still want to disable it in some rare but regular situations.
  • You cannot do ln -s $(which mamba) ~/bin/conda as this will also break a lot of other things, e.g. conda's shell activation which is slightly different from mamba's. This might converge in the near future but has not and might never do.
  • You cannot only select nowadays between mamba and conda but there is also micromamba available. This is a statically linked binary compatible with the install and env commands of mamba/conda but differing on some other aspects. If mamba is supported, one should also add support for micromamba.

Normally, I have implemented this via the pseudocode in other tools:

conda_exe = shutil.which("mamba")
if not conda_exe or os.environ.get("PRE_COMMIT_USE_MAMBA", "1") == "0":
  mamba_exe = "conda"

An alternative in pre-commit could also be to implement it as another language, e.g. if you want to use mamba, use language: mamba. Additionally, this also could open up the possibility to use micromamba as a third alternative without the need for another environment variable.

@xhochy
Copy link
Contributor

xhochy commented Jan 15, 2022

After sleeping a night over this, I think we should not implement a new language as this will be confusing to the end-user. All three tools are package managers for the same distribution technique and only differ in speed and how they handle things like environment activation. There is no behavioural difference for pre-commit hooks, thus there also shouldn't be a difference in how things are configured.

I opted for the ordering of first checking for micromamba, then mamba and then a default fallback for conda. This is in increasing order of "popularity". If you have one of the former tools installed, you have it installed because you explicited opted for using it.

@jezdez
Copy link

jezdez commented Jan 18, 2022

If it is any consolation, the conda project has been working in the past months on porting the mamba solver to conda which should help with the most memory and cpu consuming parts of the installation. We'll do an opt-in release in a month or so.

@lautjy
Copy link

lautjy commented Jan 19, 2023

Thanks for the info @jezdez ! Would be great if that solves the enormous memory consumption of conda.
For reference. 1GB AWS box runs out of MEM : conda/conda#5003 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

5 participants