Skip to content

Commit

Permalink
Avoid false warnings about missing UV_CONSTRAINT variable (#162)
Browse files Browse the repository at this point in the history
- Fixes issue where UV_CONSTRAINT warning was disabled even when
  defined
- Avoids repeated messages on each environment_variables use
  • Loading branch information
ssbarnea authored Jan 28, 2025
1 parent f05cd43 commit dac8b82
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, create_args: ToxEnvCreateArgs) -> None:
self._executor: Execute | None = None
self._installer: UvInstaller | None = None
self._created = False
self._displayed_uv_constraint_warning = False
super().__init__(create_args)

def register_config(self) -> None:
Expand Down Expand Up @@ -183,12 +184,14 @@ def environment_variables(self) -> dict[str, str]:
env = super().environment_variables
env.pop("UV_PYTHON", None) # UV_PYTHON takes precedence over VIRTUAL_ENV
env["VIRTUAL_ENV"] = str(self.venv_dir)
for pip_var in ("PIP_CONSTRAINT", "PIP_CONSTRAINTS"):
if pip_var in env:
_LOGGER.warning(
"Found %s defined, you may want to also define UV_CONSTRAINT to match pip behavior.", pip_var
)
break
if "UV_CONSTRAINT" not in env and not self._displayed_uv_constraint_warning:
for pip_var in ("PIP_CONSTRAINT", "PIP_CONSTRAINTS"):
if pip_var in env:
_LOGGER.warning(
"Found %s defined, you may want to also define UV_CONSTRAINT to match pip behavior.", pip_var
)
self._displayed_uv_constraint_warning = True
break
return env

def _default_pass_env(self) -> list[str]:
Expand Down
24 changes: 23 additions & 1 deletion tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,27 @@ def test_uv_pip_constraints(tox_project: ToxProjectCreator) -> None:
result = project.run()
result.assert_success()
assert (
"Found PIP_CONSTRAINTS defined, you may want to also define UV_CONSTRAINT to match pip behavior." in result.out
result.out.count(
"Found PIP_CONSTRAINTS defined, you may want to also define UV_CONSTRAINT to match pip behavior."
)
== 1
), "Warning should be found once and only once in output."


def test_uv_pip_constraints_no(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.ini": f"""
[testenv]
package=skip
setenv=
PIP_CONSTRAINTS={os.devnull}
UV_CONSTRAINT={os.devnull}
commands=python --version
"""
})
result = project.run()
result.assert_success()
assert (
"Found PIP_CONSTRAINTS defined, you may want to also define UV_CONSTRAINT to match pip behavior."
not in result.out
)

0 comments on commit dac8b82

Please sign in to comment.