Skip to content

Commit d380750

Browse files
authored
Merge branch 'main' into users/rahuldevikar/fix3687-scoped
2 parents 4513a3d + f80405e commit d380750

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

docs/changelog/3447.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``deps`` entries with ``~=`` version specifier being incorrectly treated as local paths instead of being passed
2+
through to pip - by :user:`Fridayai700`.

src/tox/tox_env/python/pip/req/file.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# https://www.python.org/dev/peps/pep-0508/#extras
2828
_EXTRA_PATH = re.compile(r"(.*)\[([-._,\sa-zA-Z0-9]*)]")
2929
_EXTRA_ELEMENT = re.compile(r"[a-zA-Z0-9]*[-._a-zA-Z0-9]")
30+
_VERSION_SPECIFIER = re.compile(r"[><=!~]=|===?|[><]")
3031
ReqFileLines = Iterator[tuple[int, str]]
3132

3233
DEFAULT_INDEX_URL = "https://pypi.org/simple"
@@ -40,6 +41,8 @@ def __init__(self, req: str, options: dict[str, Any], from_file: str, lineno: in
4041
except InvalidRequirement:
4142
if is_url(req) or any(req.startswith(f"{v}+") and is_url(req[len(v) + 1 :]) for v in VCS):
4243
self._requirement = req
44+
elif _VERSION_SPECIFIER.search(req):
45+
self._requirement = req # invalid requirement with version specifier — let pip report the error
4346
else:
4447
root = Path(from_file).parent
4548
extras: list[str] = []

tests/tox_env/python/pip/req/test_file.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,13 @@ def test_requirement_via_file_protocol_na(tmp_path: Path) -> None:
550550
assert req_file.options
551551

552552

553+
@pytest.mark.parametrize("req", ["pre-commit ~= 4", "pre-commit~=4"])
554+
def test_requirement_with_tilde_equals_not_treated_as_path(tmp_path: Path, req: str) -> None:
555+
"""Deps with ``~=`` version specifier should not be treated as local paths (#3447)."""
556+
parsed = ParsedRequirement(req, {}, str(tmp_path / "tox.ini"), 1)
557+
assert str(parsed.requirement) == req
558+
559+
553560
def test_requirement_to_path_one_level_up(tmp_path: Path) -> None:
554561
other_req = tmp_path / "other.txt"
555562
other_req.write_text("-e ..")

0 commit comments

Comments
 (0)