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

Fix requirements.txt parsing #2683

Merged
merged 1 commit into from Dec 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2682.bugfix.rst
@@ -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
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
@@ -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"])