Skip to content

Commit

Permalink
Fix requirements.txt parsing (#2683)
Browse files Browse the repository at this point in the history
Resolves #2682
  • Loading branch information
gaborbernat authored Dec 11, 2022
1 parent 3a54b53 commit 3c89572
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2682.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression in ``requirements.txt`` parsing - by :user:`gaborbernat`.
4 changes: 2 additions & 2 deletions src/tox/tox_env/python/pip/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def __init__(self, raw: str, root: Path):
self._req_parser_: RequirementsFile | None = None

def _extend_parser(self, parser: ArgumentParser) -> None:
parser.add_argument("--no-deps", action="store_true", default=False)
parser.add_argument("--no-deps", action="store_true", dest="no_deps", default=False)

def _merge_option_line(self, base_opt: Namespace, opt: Namespace, filename: str) -> None:
super()._merge_option_line(base_opt, opt, filename)
if opt.no_deps:
if getattr(opt, "no_deps", False): # if the option comes from a requirements file this flag is missing there
base_opt.no_deps = True

def _option_to_args(self, opt: Namespace) -> list[str]:
Expand Down
9 changes: 9 additions & 0 deletions tests/tox_env/python/pip/test_req_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from argparse import Namespace
from pathlib import Path

import pytest
Expand Down Expand Up @@ -58,3 +59,11 @@ def test_req_with_no_deps(tmp_path: Path) -> None:
python_deps = PythonDeps(raw="-rr.txt", root=tmp_path)
with pytest.raises(ValueError, match="unrecognized arguments: --no-deps"):
python_deps.requirements


def test_opt_only_req_file(tmp_path: Path) -> None:
"""deps with --hash should raise an exception."""
(tmp_path / "r.txt").write_text("--use-feature fast-deps")
python_deps = PythonDeps(raw="-rr.txt", root=tmp_path)
assert not python_deps.requirements
assert python_deps.options == Namespace(features_enabled=["fast-deps"])

0 comments on commit 3c89572

Please sign in to comment.