diff --git a/pyproject.toml b/pyproject.toml index e76d832..ba94054 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,9 +91,8 @@ lint.select = [ "ALL", ] lint.ignore = [ - "ANN101", # Missing type annotation for `self` in method "COM812", # Conflict with formatter - "CPY", # No copyriuvt statements + "CPY", # No copyright statements "D", # no documentation for now "D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible "D205", # 1 blank line required between summary line and description diff --git a/src/tox_uv/_venv.py b/src/tox_uv/_venv.py index 4734ca1..a781274 100644 --- a/src/tox_uv/_venv.py +++ b/src/tox_uv/_venv.py @@ -3,12 +3,13 @@ from __future__ import annotations import json +import logging import sys from abc import ABC from functools import cached_property from pathlib import Path from platform import python_implementation -from typing import TYPE_CHECKING, Any, Literal, Optional, Type, cast # noqa: UP035 +from typing import TYPE_CHECKING, Any, Final, Literal, Optional, Type, cast # noqa: UP035 from tox.config.loader.str_convert import StrConvert from tox.execute.local_sub_process import LocalSubProcessExecutor @@ -41,6 +42,7 @@ "system", "only-system", ] +_LOGGER: Final[logging.Logger] = logging.getLogger(__name__) class UvVenv(Python, ABC): @@ -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]: diff --git a/tests/test_tox_uv_venv.py b/tests/test_tox_uv_venv.py index 4a5e112..bfc1225 100644 --- a/tests/test_tox_uv_venv.py +++ b/tests/test_tox_uv_venv.py @@ -339,3 +339,20 @@ 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": f""" + [testenv] + package=skip + setenv= + PIP_CONSTRAINTS={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." in result.out + )