Return the Distribution for the given package name. :param name: The name of the distribution package to search for. :return: The Distribution instance (or subclass thereof) for the named package, if found. :raises PackageNotFoundError: When the named package's d
(cls, name: str)
| 450 | |
| 451 | @classmethod |
| 452 | def from_name(cls, name: str) -> Distribution: |
| 453 | """Return the Distribution for the given package name. |
| 454 | |
| 455 | :param name: The name of the distribution package to search for. |
| 456 | :return: The Distribution instance (or subclass thereof) for the named |
| 457 | package, if found. |
| 458 | :raises PackageNotFoundError: When the named package's distribution |
| 459 | metadata cannot be found. |
| 460 | :raises ValueError: When an invalid value is supplied for name. |
| 461 | """ |
| 462 | if not name: |
| 463 | raise ValueError("A distribution name is required.") |
| 464 | try: |
| 465 | return next(iter(cls._prefer_valid(cls.discover(name=name)))) |
| 466 | except StopIteration: |
| 467 | raise PackageNotFoundError(name) from None |
| 468 | |
| 469 | @classmethod |
| 470 | def discover( |