diff --git a/news/8677.bugfix b/news/8677.bugfix new file mode 100644 index 00000000000..e9efd827977 --- /dev/null +++ b/news/8677.bugfix @@ -0,0 +1,2 @@ +New resolver: Correctly include the base package when specified with extras +in ``--no-deps`` mode. diff --git a/src/pip/_internal/resolution/resolvelib/base.py b/src/pip/_internal/resolution/resolvelib/base.py index a155a1101ad..9245747bf2b 100644 --- a/src/pip/_internal/resolution/resolvelib/base.py +++ b/src/pip/_internal/resolution/resolvelib/base.py @@ -69,8 +69,8 @@ def source_link(self): # type: () -> Optional[Link] raise NotImplementedError("Override in subclass") - def iter_dependencies(self): - # type: () -> Iterable[Optional[Requirement]] + def iter_dependencies(self, with_requires): + # type: (bool) -> Iterable[Optional[Requirement]] raise NotImplementedError("Override in subclass") def get_install_requirement(self): diff --git a/src/pip/_internal/resolution/resolvelib/candidates.py b/src/pip/_internal/resolution/resolvelib/candidates.py index c289bb5839c..46cc7e7a236 100644 --- a/src/pip/_internal/resolution/resolvelib/candidates.py +++ b/src/pip/_internal/resolution/resolvelib/candidates.py @@ -275,8 +275,10 @@ def _get_requires_python_specifier(self): return None return spec - def iter_dependencies(self): - # type: () -> Iterable[Optional[Requirement]] + def iter_dependencies(self, with_requires): + # type: (bool) -> Iterable[Optional[Requirement]] + if not with_requires: + return for r in self.dist.requires(): yield self._factory.make_requirement_from_spec(str(r), self._ireq) python_dep = self._factory.make_requires_python_requirement( @@ -420,8 +422,10 @@ def format_for_error(self): # type: () -> str return "{} {} (Installed)".format(self.name, self.version) - def iter_dependencies(self): - # type: () -> Iterable[Optional[Requirement]] + def iter_dependencies(self, with_requires): + # type: (bool) -> Iterable[Optional[Requirement]] + if not with_requires: + return for r in self.dist.requires(): yield self._factory.make_requirement_from_spec(str(r), self._ireq) @@ -519,10 +523,16 @@ def source_link(self): # type: () -> Optional[Link] return self.base.source_link - def iter_dependencies(self): - # type: () -> Iterable[Optional[Requirement]] + def iter_dependencies(self, with_requires): + # type: (bool) -> Iterable[Optional[Requirement]] factory = self.base._factory + # Add a dependency on the exact base + # (See note 2b in the class docstring) + yield factory.make_requirement_from_candidate(self.base) + if not with_requires: + return + # The user may have specified extras that the candidate doesn't # support. We ignore any unsupported extras here. valid_extras = self.extras.intersection(self.base.dist.extras) @@ -535,10 +545,6 @@ def iter_dependencies(self): extra ) - # Add a dependency on the exact base - # (See note 2b in the class docstring) - yield factory.make_requirement_from_candidate(self.base) - for r in self.base.dist.requires(valid_extras): requirement = factory.make_requirement_from_spec( str(r), self.base._ireq, valid_extras, @@ -585,8 +591,8 @@ def format_for_error(self): # type: () -> str return "Python {}".format(self.version) - def iter_dependencies(self): - # type: () -> Iterable[Optional[Requirement]] + def iter_dependencies(self, with_requires): + # type: (bool) -> Iterable[Optional[Requirement]] return () def get_install_requirement(self): diff --git a/src/pip/_internal/resolution/resolvelib/provider.py b/src/pip/_internal/resolution/resolvelib/provider.py index 72f16205981..b2eb9d06ea5 100644 --- a/src/pip/_internal/resolution/resolvelib/provider.py +++ b/src/pip/_internal/resolution/resolvelib/provider.py @@ -145,6 +145,9 @@ def is_satisfied_by(self, requirement, candidate): def get_dependencies(self, candidate): # type: (Candidate) -> Sequence[Requirement] - if self._ignore_dependencies: - return [] - return [r for r in candidate.iter_dependencies() if r is not None] + with_requires = not self._ignore_dependencies + return [ + r + for r in candidate.iter_dependencies(with_requires) + if r is not None + ] diff --git a/tests/yaml/extras.yml b/tests/yaml/extras.yml index 6e2a1b17e7b..ac68fae4979 100644 --- a/tests/yaml/extras.yml +++ b/tests/yaml/extras.yml @@ -40,3 +40,10 @@ cases: - E 1.0.0 - F 1.0.0 skip: old +- + request: + - install: D[extra_1] + options: --no-deps + response: + - state: + - D 1.0.0