Skip to content

Commit

Permalink
Add mamba support to language: conda
Browse files Browse the repository at this point in the history
  • Loading branch information
xhochy committed Jan 15, 2022
1 parent b944395 commit e43463a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pre_commit/languages/conda.py
@@ -1,5 +1,6 @@
import contextlib
import os
import shutil
from typing import Generator
from typing import Sequence
from typing import Tuple
Expand Down Expand Up @@ -58,15 +59,25 @@ def install_environment(
helpers.assert_version_default('conda', version)
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)

conda_exe = None
if os.environ.get('PRE_COMMIT_USE_MICROMAMBA', '1') == '1':
conda_exe = shutil.which('micromamba')
if (
conda_exe is None and
os.environ.get('PRE_COMMIT_USE_MAMBA', '1') == '1'
):
conda_exe = shutil.which('mamba')
conda_exe = conda_exe or 'conda'

env_dir = prefix.path(directory)
with clean_path_on_failure(env_dir):
cmd_output_b(
'conda', 'env', 'create', '-p', env_dir, '--file',
conda_exe, 'env', 'create', '-p', env_dir, '--file',
'environment.yml', cwd=prefix.prefix_dir,
)
if additional_dependencies:
cmd_output_b(
'conda', 'install', '-p', env_dir, *additional_dependencies,
conda_exe, 'install', '-p', env_dir, *additional_dependencies,
cwd=prefix.prefix_dir,
)

Expand Down

0 comments on commit e43463a

Please sign in to comment.