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 dry run to run on guarded environments #9

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions conda_protect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def conda_guard_pre_commands_action(command: str):
TODO: This still doesn't handle `conda env update -f environment.yml`
We will have to look inside the file and pluck out the environment name
"""
# Allow things to go forward when `dry_run` is `True`
if context.dry_run:
return

known_envs = get_environment_info()
lookup_attr, value = _get_active_environment()

Expand Down
4 changes: 2 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "conda-auth"
version = "0.2.0"
name = "conda-protect"
version = "0.5.0"
description = "Protects conda environments to avoid mistakenly modifying them"
authors = ["Travis Hathaway <travis.j.hathaway@gmail.com>"]
channels = ["conda-forge"]
Expand Down
22 changes: 21 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import pytest
from conda.testing import conda_cli # noqa: F401
from conda.exceptions import DryRunExit

from conda_protect.main import GUARDFILE_NAME, CondaProtectError, GUARD_COMMAND_NAME

Expand Down Expand Up @@ -53,7 +54,26 @@ def test_guarded_command_fails(mocker, conda_cli, conda_environment): # noqa: F
assert err == ""

with pytest.raises(CondaProtectError):
conda_cli("install", "--prefix", str(conda_environment), "python")
conda_cli("install", "--prefix", str(conda_environment), "ca-certificates")

# remove conda_protect
out, err, code = conda_cli(GUARD_COMMAND_NAME, str(conda_environment))

assert err == ""


def test_dry_run_continues(mocker, conda_cli, conda_environment):
"""
When `--dry-run` is used, the environment is not guarded
"""
mocker.patch("sys.argv", ["conda", GUARD_COMMAND_NAME, str(conda_environment)])

out, err, code = conda_cli(GUARD_COMMAND_NAME, str(conda_environment))

assert err == ""

with pytest.raises(DryRunExit):
conda_cli("install", "--dry-run", "--prefix", str(conda_environment), "ca-certificates")

# remove conda_protect
out, err, code = conda_cli(GUARD_COMMAND_NAME, str(conda_environment))
Expand Down
Loading