Skip to content

Commit

Permalink
Refactor and test
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed Mar 23, 2022
1 parent f2f6dc5 commit 7343577
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ def match_markers(self, extras_requested: Optional[Iterable[str]] = None) -> boo
else:
return True

@property
def has_ignore_dependencies(self) -> bool:
if isinstance(self.comes_from, InstallRequirement):
return self.comes_from.ignore_dependencies
else:
return self.ignore_dependencies

@property
def has_hash_options(self) -> bool:
"""Return whether any known-good hashes are specified as options.
Expand Down
10 changes: 10 additions & 0 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
REQUIRES_PYTHON_IDENTIFIER = cast(NormalizedName, "<Python from Requires-Python>")


def has_ignore_dependencies(candidate: Candidate) -> bool:
ireq = candidate.get_install_requirement()
if ireq:
return ireq.has_ignore_dependencies
elif isinstance(candidate, AlreadyInstalledCandidate):
return candidate._ireq.has_ignore_dependencies
else:
return False


def as_base_candidate(candidate: Candidate) -> Optional[BaseCandidate]:
"""The runtime version of BaseCandidate."""
base_candidate_classes = (
Expand Down
16 changes: 4 additions & 12 deletions src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

from pip._vendor.resolvelib.providers import AbstractProvider

from pip._internal.req import InstallRequirement

from .base import Candidate, Constraint, Requirement
from .candidates import REQUIRES_PYTHON_IDENTIFIER, AlreadyInstalledCandidate
from .candidates import REQUIRES_PYTHON_IDENTIFIER, has_ignore_dependencies
from .factory import Factory

if TYPE_CHECKING:
Expand Down Expand Up @@ -235,15 +233,9 @@ def is_satisfied_by(self, requirement: Requirement, candidate: Candidate) -> boo
return requirement.is_satisfied_by(candidate)

def get_dependencies(self, candidate: Candidate) -> Sequence[Requirement]:
ireq = candidate.get_install_requirement()
with_requires = not self._ignore_dependencies
if ireq and with_requires:
if ireq.comes_from and isinstance(ireq.comes_from, InstallRequirement):
with_requires = not ireq.comes_from.ignore_dependencies
else:
with_requires = not ireq.ignore_dependencies
elif isinstance(candidate, AlreadyInstalledCandidate):
with_requires = not candidate._ireq.ignore_dependencies
with_requires = not (
self._ignore_dependencies or has_ignore_dependencies(candidate)
)
return [r for r in candidate.iter_dependencies(with_requires) if r is not None]

@staticmethod
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/test_install_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,23 @@ def test_location_related_install_option_fails(script: PipTestEnvironment) -> No
expect_error=True,
)
assert "['--home'] from simple" in result.stderr


def test_install_options_no_deps(script: PipTestEnvironment) -> None:
create_basic_wheel_for_package(script, "A", "0.1.0", depends=["B==0.1.0"])
create_basic_wheel_for_package(script, "B", "0.1.0")

requirements_txt = script.scratch_path / "requirements.txt"
requirements_txt.write_text("A --no-deps")

script.pip(
"install",
"--no-cache-dir",
"--find-links",
script.scratch_path,
"-r",
requirements_txt,
"--only-binary=:all:",
)
script.assert_installed(A="0.1.0")
script.assert_not_installed("B")

0 comments on commit 7343577

Please sign in to comment.