Skip to content

Commit

Permalink
Translate PIP_CONSTRAINT(S) into UV_CONSTRAINTS if needed (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jan 16, 2025
1 parent d5d73b1 commit 87daeb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
17 changes: 17 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 87daeb6

Please sign in to comment.