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 d5d73b1 commit 9a75449
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ lint.select = [
"ALL",
]
lint.ignore = [
"ANN101", # Missing type annotation for `self` in method
"COM812", # Conflict with formatter
"CPY", # No copyriuvt statements
"D", # no documentation for now
Expand Down
10 changes: 9 additions & 1 deletion src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,6 +42,7 @@
"system",
"only-system",
]
_LOGGER: Final[logging.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
16 changes: 16 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,19 @@ 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
deps=setuptools
setenv=
PIP_CONSTRAINTS=/dev/null
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 9a75449

Please sign in to comment.