Skip to content

Commit

Permalink
Translate PIP_CONSTRAINT(S) into UV_CONSTRAINTS if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 16, 2025
1 parent e123ace commit 134d164
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
import logging
import sys
from abc import ABC
from functools import cached_property
Expand Down Expand Up @@ -41,6 +42,7 @@
"system",
"only-system",
]
logger = logging.getLogger(__name__)


class UvVenv(Python, ABC):
Expand Down Expand Up @@ -178,6 +180,12 @@ 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
return env

def _default_pass_env(self) -> list[str]:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,17 @@ def test_uv_python_set(tox_project: ToxProjectCreator, monkeypatch: pytest.Monke
})
result = project.run("-vv")
result.assert_success()


def test_uv_pip_constraints(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.ini": (
"[testenv]\npackage=skip\ndeps=setuptools\n"
"setenv=\n\tPIP_CONSTRAINTS=/dev/null\n"
"commands=python -c 'import setuptools'"
)
})
result = project.run()
result.assert_success()
assert "PIP_CONSTRAINTS" in result.out
assert "UV_CONSTRAINT" in result.out

0 comments on commit 134d164

Please sign in to comment.