Skip to content

Avoid preparing metadata when pip download with --ignore-requires-python --no-deps #9311

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1884-0.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid preparing metadata when both ``--no-deps`` and ``--ignore-requires-python`` are provided to ``pip download``.
4 changes: 2 additions & 2 deletions src/pip/_internal/resolution/resolvelib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def source_link(self):
# type: () -> Optional[Link]
raise NotImplementedError("Override in subclass")

def iter_dependencies(self, with_requires):
# type: (bool) -> Iterable[Optional[Requirement]]
def iter_dependencies(self, with_requires, ignore_requires_python):
Copy link
Member

@pradyunsg pradyunsg Dec 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def iter_dependencies(self, with_requires, ignore_requires_python):
def iter_dependencies(self, with_requires, with_requires_python):

For consistency internally in the pip._internal.resolution.resolvelib package?

# type: (bool, bool) -> Iterable[Optional[Requirement]]
raise NotImplementedError("Override in subclass")

def get_install_requirement(self):
Expand Down
19 changes: 10 additions & 9 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ def _get_requires_python_dependency(self):
return None
return self._factory.make_requires_python_requirement(spec)

def iter_dependencies(self, with_requires):
# type: (bool) -> Iterable[Optional[Requirement]]
def iter_dependencies(self, with_requires, ignore_requires_python):
# type: (bool, bool) -> Iterable[Optional[Requirement]]
requires = self.dist.requires() if with_requires else ()
for r in requires:
yield self._factory.make_requirement_from_spec(str(r), self._ireq)
yield self._get_requires_python_dependency()
if not ignore_requires_python:
yield self._get_requires_python_dependency()

def get_install_requirement(self):
# type: () -> Optional[InstallRequirement]
Expand Down Expand Up @@ -418,8 +419,8 @@ def format_for_error(self):
# type: () -> str
return "{} {} (Installed)".format(self.name, self.version)

def iter_dependencies(self, with_requires):
# type: (bool) -> Iterable[Optional[Requirement]]
def iter_dependencies(self, with_requires, ignore_requires_python):
# type: (bool, bool) -> Iterable[Optional[Requirement]]
if not with_requires:
return
for r in self.dist.requires():
Expand Down Expand Up @@ -529,8 +530,8 @@ def source_link(self):
# type: () -> Optional[Link]
return self.base.source_link

def iter_dependencies(self, with_requires):
# type: (bool) -> Iterable[Optional[Requirement]]
def iter_dependencies(self, with_requires, ignore_requires_python):
# type: (bool, bool) -> Iterable[Optional[Requirement]]
factory = self.base._factory

# Add a dependency on the exact base
Expand Down Expand Up @@ -606,8 +607,8 @@ def format_for_error(self):
# type: () -> str
return "Python {}".format(self.version)

def iter_dependencies(self, with_requires):
# type: (bool) -> Iterable[Optional[Requirement]]
def iter_dependencies(self, with_requires, ignore_requires_python):
# type: (bool, bool) -> Iterable[Optional[Requirement]]
return ()

def get_install_requirement(self):
Expand Down
4 changes: 1 addition & 3 deletions src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def __init__(
use_user_site, # type: bool
force_reinstall, # type: bool
ignore_installed, # type: bool
ignore_requires_python, # type: bool
py_version_info=None, # type: Optional[Tuple[int, ...]]
):
# type: (...) -> None
Expand All @@ -92,7 +91,6 @@ def __init__(
self._make_install_req_from_spec = make_install_req
self._use_user_site = use_user_site
self._force_reinstall = force_reinstall
self._ignore_requires_python = ignore_requires_python

self._link_candidate_cache = {} # type: Cache[LinkCandidate]
self._editable_candidate_cache = {} # type: Cache[EditableCandidate]
Expand Down Expand Up @@ -298,7 +296,7 @@ def make_requirement_from_spec(

def make_requires_python_requirement(self, specifier):
# type: (Optional[SpecifierSet]) -> Optional[Requirement]
if self._ignore_requires_python or specifier is None:
if specifier is None:
return None
return RequiresPythonRequirement(specifier, self._python_candidate)

Expand Down
5 changes: 4 additions & 1 deletion src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ def __init__(
factory, # type: Factory
constraints, # type: Dict[str, Constraint]
ignore_dependencies, # type: bool
ignore_requires_python, # type: bool
upgrade_strategy, # type: str
user_requested, # type: Set[str]
):
# type: (...) -> None
self._factory = factory
self._constraints = constraints
self._ignore_dependencies = ignore_dependencies
self._ignore_requires_python = ignore_requires_python
self._upgrade_strategy = upgrade_strategy
self._user_requested = user_requested

Expand Down Expand Up @@ -167,8 +169,9 @@ def is_satisfied_by(self, requirement, candidate):
def get_dependencies(self, candidate):
# type: (Candidate) -> Sequence[Requirement]
with_requires = not self._ignore_dependencies
ignore_requires_python = self._ignore_requires_python
return [
r
for r in candidate.iter_dependencies(with_requires)
for r in candidate.iter_dependencies(with_requires, ignore_requires_python)
if r is not None
]
3 changes: 2 additions & 1 deletion src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def __init__(
use_user_site=use_user_site,
force_reinstall=force_reinstall,
ignore_installed=ignore_installed,
ignore_requires_python=ignore_requires_python,
py_version_info=py_version_info,
)
self.ignore_dependencies = ignore_dependencies
self.ignore_requires_python = ignore_requires_python
self.upgrade_strategy = upgrade_strategy
self._result = None # type: Optional[Result]

Expand Down Expand Up @@ -107,6 +107,7 @@ def resolve(self, root_reqs, check_supported_wheels):
factory=self.factory,
constraints=constraints,
ignore_dependencies=self.ignore_dependencies,
ignore_requires_python=self.ignore_requires_python,
upgrade_strategy=self.upgrade_strategy,
user_requested=user_requested,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/resolution_resolvelib/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def factory(finder, preparer):
use_user_site=False,
force_reinstall=False,
ignore_installed=False,
ignore_requires_python=False,
py_version_info=None,
)

Expand All @@ -68,6 +67,7 @@ def provider(factory):
factory=factory,
constraints={},
ignore_dependencies=False,
ignore_requires_python=False,
upgrade_strategy="to-satisfy-only",
user_requested=set(),
)