Skip to content

Commit

Permalink
Implement --no-deps in requirements files
Browse files Browse the repository at this point in the history
  • Loading branch information
leorochael committed Jun 25, 2024
1 parent d1bb33a commit 1a49ce6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions news/9948.feature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ Implement the ``--no-deps-for`` switch for the ``install`` command and the
requirements file. This switch will prevent the installation of dependencies of
specific packages, as opposed to the ``--no-deps`` switch which prevents the
installation dependencies of all requested packages.

Also implement recognition of the global ``--no-deps`` switch in the requirements
file.
2 changes: 2 additions & 0 deletions src/pip/_internal/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
cmdoptions.find_links,
cmdoptions.no_binary,
cmdoptions.only_binary,
cmdoptions.no_deps,
cmdoptions.no_deps_for,
cmdoptions.prefer_binary,
cmdoptions.require_hashes,
Expand Down Expand Up @@ -226,6 +227,7 @@ def handle_option_line(
options.features_enabled.extend(
f for f in opts.features_enabled if f not in options.features_enabled
)
options.ignore_dependencies |= opts.ignore_dependencies
options.ignore_dependencies_for.update(opts.ignore_dependencies_for)

# set finder options
Expand Down
37 changes: 37 additions & 0 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,43 @@ def test_new_resolver_ignore_dependencies_for(script: PipTestEnvironment) -> Non
script.assert_not_installed("dep")


def test_new_resolver_no_deps_in_requirements(
tmpdir: pathlib.Path,
script: PipTestEnvironment,
) -> None:
create_basic_wheel_for_package(
script,
"base",
"0.1.0",
depends=["dep"],
)
create_basic_wheel_for_package(
script,
"dep",
"0.1.0",
)

req_file = tmpdir / "requirements.txt"
req_file.write_text(
"""
base==0.1.0
--no-deps
"""
)

script.pip(
"install",
"--no-cache-dir",
"--no-index",
"--find-links",
script.scratch_path,
"-r",
req_file,
)
script.assert_installed(base="0.1.0")
script.assert_not_installed("dep")


@pytest.mark.parametrize(
"root_dep",
[
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def options(session: PipSession) -> mock.Mock:
index_url="default_url",
format_control=FormatControl(set(), set()),
features_enabled=[],
ignore_dependencies=False,
ignore_dependencies_for=set(),
)

Expand Down Expand Up @@ -764,6 +765,24 @@ def test_join_lines(self, tmpdir: Path, finder: PackageFinder) -> None:

assert finder.index_urls == ["url1", "url2"]

def test_ignore_dependencies(self, tmpdir: Path, options: mock.Mock) -> None:
req = tmpdir / "req1.txt"
req.write_text(
"""
--no-deps
"""
)

list(
parse_reqfile(
req,
session=PipSession(),
options=options,
)
)

assert options.ignore_dependencies

def test_ignore_dependencies_for(self, tmpdir: Path, options: mock.Mock) -> None:
req = tmpdir / "req1.txt"
req.write_text(
Expand Down

0 comments on commit 1a49ce6

Please sign in to comment.