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

Add CONDA_DEVENV_USE_LOCKS env var to configure the default for --use-locks #184

Merged
merged 1 commit into from
Jul 11, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
CHANGELOG
=========

3.2.0 (2023-07-11)
------------------

* The ``CONDA_DEVENV_USE_LOCKS`` can be used to change the default value of ``--use-locks``. Useful to set on CI to ensure
lock files are being used.

3.1.1 (2023-07-04)
------------------

Expand Down
10 changes: 9 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ No other changes are required.

You can control if ``devenv`` should use lock files using the ``--use-locks {auto,yes,no}`` command-line option.

.. versionadded:: 3.2.0

The default value for ``--use-locks`` can be set via ``CONDA_DEVENV_USE_LOCKS``, which is useful on CI
to change the behavior when no explicit option is present in the command line.


Updating
--------

Expand Down Expand Up @@ -482,7 +488,9 @@ Options
--use-locks {auto,yes,no}
How to use lock files: 'auto' will use them if
available, 'yes' will try to use and fail if not
available, 'no' skip lockfiles always.
available, 'no' skip lock files always. Can also be
configured via CONDA_DEVENV_USE_LOCKS environment
variable.
--update-locks PACKAGE
Update the given package in all lock files, while
still obeying the pins in the devenv.yml file. Can be
Expand Down
9 changes: 6 additions & 3 deletions src/conda_devenv/devenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,12 @@ def parse_args(argv: list[str] | None) -> argparse.Namespace:
group.add_argument(
"--use-locks",
choices=["auto", "yes", "no"],
default="auto",
help="How to use lock files: 'auto' will use them if available, 'yes' "
"will try to use and fail if not available, 'no' skip lockfiles always.",
default=os.environ.get("CONDA_DEVENV_USE_LOCKS", "auto"),
help=(
"How to use lock files: 'auto' will use them if available, 'yes' "
"will try to use and fail if not available, 'no' skip lock files always. "
"Can also be configured via CONDA_DEVENV_USE_LOCKS environment variable."
),
)
group.add_argument(
"--update-locks",
Expand Down
20 changes: 16 additions & 4 deletions tests/test_locking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from pathlib import Path
from textwrap import dedent
from typing import Literal

import pytest

Expand Down Expand Up @@ -219,7 +220,7 @@ def test_auto_use_lock_files(
)
)

# Create the env directory because we need it to exist to create the activate/deactive scripts.
# Create the env directory because we need it to exist to create the activate/deactivate scripts.
env_dir = tmp_path / "envs"
env_dir.joinpath(f"{env_name}/conda-meta").mkdir(parents=True)
env_dirs = [env_dir]
Expand All @@ -242,7 +243,7 @@ def test_auto_use_lock_files(
),
]

# Use locks again but create an environment different than the one defined
# Use locks again but create an environment different from the one defined
# in environment.devenv.yml.
subprocess_call_mock.reset_mock()
env_dir2 = tmp_path / "envs"
Expand All @@ -269,9 +270,20 @@ def test_auto_use_lock_files(
]


@pytest.mark.parametrize("mode", ["cmd-line", "env-var"])
def test_use_locks_is_yes_but_no_lock_file(
tmp_path: Path, monkeypatch, patch_conda_calls: None, capsys
tmp_path: Path,
monkeypatch,
patch_conda_calls: None,
capsys,
mode: Literal["cmd-line", "env-var"],
nicoddemus marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
if mode == "cmd-line":
cmdline = ["--use-locks=yes"]
else:
assert mode == "env-var"
monkeypatch.setenv("CONDA_DEVENV_USE_LOCKS", "yes")
cmdline = []
monkeypatch.chdir(tmp_path)
env_file = tmp_path / "environment.devenv.yml"
env_file.write_text(
Expand All @@ -289,7 +301,7 @@ def test_use_locks_is_yes_but_no_lock_file(
)
)

assert devenv.main(["--use-locks=yes"]) == 2
assert devenv.main(cmdline) == 2
out, err = capsys.readouterr()
platform = CondaPlatform.current().value
assert (
Expand Down