Skip to content

Commit 552b837

Browse files
committed
Merge pull request #8678 from uranusjr/new-resolver-no-deps-extras-install-self
1 parent 4a39344 commit 552b837

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

news/8677.bugfix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
New resolver: Correctly include the base package when specified with extras
2+
in ``--no-deps`` mode.

src/pip/_internal/resolution/resolvelib/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def source_link(self):
6969
# type: () -> Optional[Link]
7070
raise NotImplementedError("Override in subclass")
7171

72-
def iter_dependencies(self):
73-
# type: () -> Iterable[Optional[Requirement]]
72+
def iter_dependencies(self, with_requires):
73+
# type: (bool) -> Iterable[Optional[Requirement]]
7474
raise NotImplementedError("Override in subclass")
7575

7676
def get_install_requirement(self):

src/pip/_internal/resolution/resolvelib/candidates.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ def _get_requires_python_specifier(self):
275275
return None
276276
return spec
277277

278-
def iter_dependencies(self):
279-
# type: () -> Iterable[Optional[Requirement]]
278+
def iter_dependencies(self, with_requires):
279+
# type: (bool) -> Iterable[Optional[Requirement]]
280+
if not with_requires:
281+
return
280282
for r in self.dist.requires():
281283
yield self._factory.make_requirement_from_spec(str(r), self._ireq)
282284
python_dep = self._factory.make_requires_python_requirement(
@@ -420,8 +422,10 @@ def format_for_error(self):
420422
# type: () -> str
421423
return "{} {} (Installed)".format(self.name, self.version)
422424

423-
def iter_dependencies(self):
424-
# type: () -> Iterable[Optional[Requirement]]
425+
def iter_dependencies(self, with_requires):
426+
# type: (bool) -> Iterable[Optional[Requirement]]
427+
if not with_requires:
428+
return
425429
for r in self.dist.requires():
426430
yield self._factory.make_requirement_from_spec(str(r), self._ireq)
427431

@@ -519,10 +523,16 @@ def source_link(self):
519523
# type: () -> Optional[Link]
520524
return self.base.source_link
521525

522-
def iter_dependencies(self):
523-
# type: () -> Iterable[Optional[Requirement]]
526+
def iter_dependencies(self, with_requires):
527+
# type: (bool) -> Iterable[Optional[Requirement]]
524528
factory = self.base._factory
525529

530+
# Add a dependency on the exact base
531+
# (See note 2b in the class docstring)
532+
yield factory.make_requirement_from_candidate(self.base)
533+
if not with_requires:
534+
return
535+
526536
# The user may have specified extras that the candidate doesn't
527537
# support. We ignore any unsupported extras here.
528538
valid_extras = self.extras.intersection(self.base.dist.extras)
@@ -535,10 +545,6 @@ def iter_dependencies(self):
535545
extra
536546
)
537547

538-
# Add a dependency on the exact base
539-
# (See note 2b in the class docstring)
540-
yield factory.make_requirement_from_candidate(self.base)
541-
542548
for r in self.base.dist.requires(valid_extras):
543549
requirement = factory.make_requirement_from_spec(
544550
str(r), self.base._ireq, valid_extras,
@@ -585,8 +591,8 @@ def format_for_error(self):
585591
# type: () -> str
586592
return "Python {}".format(self.version)
587593

588-
def iter_dependencies(self):
589-
# type: () -> Iterable[Optional[Requirement]]
594+
def iter_dependencies(self, with_requires):
595+
# type: (bool) -> Iterable[Optional[Requirement]]
590596
return ()
591597

592598
def get_install_requirement(self):

src/pip/_internal/resolution/resolvelib/provider.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def is_satisfied_by(self, requirement, candidate):
145145

146146
def get_dependencies(self, candidate):
147147
# type: (Candidate) -> Sequence[Requirement]
148-
if self._ignore_dependencies:
149-
return []
150-
return [r for r in candidate.iter_dependencies() if r is not None]
148+
with_requires = not self._ignore_dependencies
149+
return [
150+
r
151+
for r in candidate.iter_dependencies(with_requires)
152+
if r is not None
153+
]

tests/yaml/extras.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ cases:
4040
- E 1.0.0
4141
- F 1.0.0
4242
skip: old
43+
-
44+
request:
45+
- install: D[extra_1]
46+
options: --no-deps
47+
response:
48+
- state:
49+
- D 1.0.0

0 commit comments

Comments
 (0)