mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2207 from xhochy/mamba
Add mamba support to `language: conda`
This commit is contained in:
commit
12b482345b
2 changed files with 51 additions and 2 deletions
|
|
@ -50,6 +50,15 @@ def in_env(
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
def _conda_exe() -> str:
|
||||||
|
if os.environ.get('PRE_COMMIT_USE_MICROMAMBA'):
|
||||||
|
return 'micromamba'
|
||||||
|
elif os.environ.get('PRE_COMMIT_USE_MAMBA'):
|
||||||
|
return 'mamba'
|
||||||
|
else:
|
||||||
|
return 'conda'
|
||||||
|
|
||||||
|
|
||||||
def install_environment(
|
def install_environment(
|
||||||
prefix: Prefix,
|
prefix: Prefix,
|
||||||
version: str,
|
version: str,
|
||||||
|
|
@ -58,15 +67,17 @@ def install_environment(
|
||||||
helpers.assert_version_default('conda', version)
|
helpers.assert_version_default('conda', version)
|
||||||
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
|
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
|
||||||
|
|
||||||
|
conda_exe = _conda_exe()
|
||||||
|
|
||||||
env_dir = prefix.path(directory)
|
env_dir = prefix.path(directory)
|
||||||
with clean_path_on_failure(env_dir):
|
with clean_path_on_failure(env_dir):
|
||||||
cmd_output_b(
|
cmd_output_b(
|
||||||
'conda', 'env', 'create', '-p', env_dir, '--file',
|
conda_exe, 'env', 'create', '-p', env_dir, '--file',
|
||||||
'environment.yml', cwd=prefix.prefix_dir,
|
'environment.yml', cwd=prefix.prefix_dir,
|
||||||
)
|
)
|
||||||
if additional_dependencies:
|
if additional_dependencies:
|
||||||
cmd_output_b(
|
cmd_output_b(
|
||||||
'conda', 'install', '-p', env_dir, *additional_dependencies,
|
conda_exe, 'install', '-p', env_dir, *additional_dependencies,
|
||||||
cwd=prefix.prefix_dir,
|
cwd=prefix.prefix_dir,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
38
tests/languages/conda_test.py
Normal file
38
tests/languages/conda_test.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pre_commit import envcontext
|
||||||
|
from pre_commit.languages.conda import _conda_exe
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
('ctx', 'expected'),
|
||||||
|
(
|
||||||
|
pytest.param(
|
||||||
|
(
|
||||||
|
('PRE_COMMIT_USE_MICROMAMBA', envcontext.UNSET),
|
||||||
|
('PRE_COMMIT_USE_MAMBA', envcontext.UNSET),
|
||||||
|
),
|
||||||
|
'conda',
|
||||||
|
id='default',
|
||||||
|
),
|
||||||
|
pytest.param(
|
||||||
|
(
|
||||||
|
('PRE_COMMIT_USE_MICROMAMBA', '1'),
|
||||||
|
('PRE_COMMIT_USE_MAMBA', ''),
|
||||||
|
),
|
||||||
|
'micromamba',
|
||||||
|
id='default',
|
||||||
|
),
|
||||||
|
pytest.param(
|
||||||
|
(
|
||||||
|
('PRE_COMMIT_USE_MICROMAMBA', ''),
|
||||||
|
('PRE_COMMIT_USE_MAMBA', '1'),
|
||||||
|
),
|
||||||
|
'mamba',
|
||||||
|
id='default',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_conda_exe(ctx, expected):
|
||||||
|
with envcontext.envcontext(ctx):
|
||||||
|
assert _conda_exe() == expected
|
||||||
Loading…
Add table
Add a link
Reference in a new issue