Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display warning if PIP_CONSTRAINT(S) are defined and UV_CONSTRAINTS not #154

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
"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
)
Loading