Skip to content

Commit

Permalink
error (instead of warning) on unavailable extra
Browse files Browse the repository at this point in the history
  • Loading branch information
meejah committed Oct 2, 2024
1 parent 102d818 commit d50ea9a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/pip/_internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,26 @@ def __init__(self, *, distribution: "BaseDistribution") -> None:
),
hint_stmt=None,
)


class UnavailableExtra(InstallationError):
"""A requested extra is not available."""

def __init__(
self,
base: str,
version: str,
extra: str,
available_extras: List[str],
):
self.base = base
self.version = version
self.extra = extra
self.available_extras = available_extras

def __str__(self) -> str:
nice_available = " ".join(
'"{}", '.format(e)
for e in self.available_extras
)[:-2]
return f"{self.base} {self.version} does not provide the extra '{self.extra}'\n{self.base} provides extras: {nice_available}"
11 changes: 6 additions & 5 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
InstallationSubprocessError,
MetadataInconsistent,
MetadataInvalid,
UnavailableExtra,
)
from pip._internal.metadata import BaseDistribution
from pip._internal.models.link import Link, links_equivalent
Expand Down Expand Up @@ -508,11 +509,11 @@ def iter_dependencies(self, with_requires: bool) -> Iterable[Optional[Requiremen
valid_extras = self.extras.intersection(self.base.dist.iter_provided_extras())
invalid_extras = self.extras.difference(self.base.dist.iter_provided_extras())
for extra in sorted(invalid_extras):
logger.warning(
"%s %s does not provide the extra '%s'",
self.base.name,
self.version,
extra,
raise UnavailableExtra(
base=self.base.name,
version=self.version,
extra=extra,
available_extras=self.base.dist.iter_provided_extras(),
)

for r in self.base.dist.iter_dependencies(valid_extras):
Expand Down

0 comments on commit d50ea9a

Please sign in to comment.