Skip to content

Commit dac8b82

Browse files
authored
Avoid false warnings about missing UV_CONSTRAINT variable (#162)
- Fixes issue where UV_CONSTRAINT warning was disabled even when defined - Avoids repeated messages on each environment_variables use
1 parent f05cd43 commit dac8b82

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/tox_uv/_venv.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(self, create_args: ToxEnvCreateArgs) -> None:
5151
self._executor: Execute | None = None
5252
self._installer: UvInstaller | None = None
5353
self._created = False
54+
self._displayed_uv_constraint_warning = False
5455
super().__init__(create_args)
5556

5657
def register_config(self) -> None:
@@ -183,12 +184,14 @@ def environment_variables(self) -> dict[str, str]:
183184
env = super().environment_variables
184185
env.pop("UV_PYTHON", None) # UV_PYTHON takes precedence over VIRTUAL_ENV
185186
env["VIRTUAL_ENV"] = str(self.venv_dir)
186-
for pip_var in ("PIP_CONSTRAINT", "PIP_CONSTRAINTS"):
187-
if pip_var in env:
188-
_LOGGER.warning(
189-
"Found %s defined, you may want to also define UV_CONSTRAINT to match pip behavior.", pip_var
190-
)
191-
break
187+
if "UV_CONSTRAINT" not in env and not self._displayed_uv_constraint_warning:
188+
for pip_var in ("PIP_CONSTRAINT", "PIP_CONSTRAINTS"):
189+
if pip_var in env:
190+
_LOGGER.warning(
191+
"Found %s defined, you may want to also define UV_CONSTRAINT to match pip behavior.", pip_var
192+
)
193+
self._displayed_uv_constraint_warning = True
194+
break
192195
return env
193196

194197
def _default_pass_env(self) -> list[str]:

tests/test_tox_uv_venv.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,27 @@ def test_uv_pip_constraints(tox_project: ToxProjectCreator) -> None:
396396
result = project.run()
397397
result.assert_success()
398398
assert (
399-
"Found PIP_CONSTRAINTS defined, you may want to also define UV_CONSTRAINT to match pip behavior." in result.out
399+
result.out.count(
400+
"Found PIP_CONSTRAINTS defined, you may want to also define UV_CONSTRAINT to match pip behavior."
401+
)
402+
== 1
403+
), "Warning should be found once and only once in output."
404+
405+
406+
def test_uv_pip_constraints_no(tox_project: ToxProjectCreator) -> None:
407+
project = tox_project({
408+
"tox.ini": f"""
409+
[testenv]
410+
package=skip
411+
setenv=
412+
PIP_CONSTRAINTS={os.devnull}
413+
UV_CONSTRAINT={os.devnull}
414+
commands=python --version
415+
"""
416+
})
417+
result = project.run()
418+
result.assert_success()
419+
assert (
420+
"Found PIP_CONSTRAINTS defined, you may want to also define UV_CONSTRAINT to match pip behavior."
421+
not in result.out
400422
)

0 commit comments

Comments
 (0)