|
1 | 1 | import email.message
|
2 | 2 | import logging
|
3 | 3 | from typing import Collection, Iterable, Iterator, List, NamedTuple, Optional
|
| 4 | +from zipfile import BadZipFile |
4 | 5 |
|
5 | 6 | from pip._vendor import pkg_resources
|
6 | 7 | from pip._vendor.packaging.requirements import Requirement
|
7 | 8 | from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
8 | 9 | from pip._vendor.packaging.version import parse as parse_version
|
9 | 10 |
|
| 11 | +from pip._internal.exceptions import InvalidWheel |
10 | 12 | from pip._internal.utils import misc # TODO: Move definition here.
|
11 | 13 | from pip._internal.utils.packaging import get_installer, get_metadata
|
12 | 14 | from pip._internal.utils.wheel import pkg_resources_distribution_for_wheel
|
@@ -34,8 +36,16 @@ def __init__(self, dist: pkg_resources.Distribution) -> None:
|
34 | 36 |
|
35 | 37 | @classmethod
|
36 | 38 | def from_wheel(cls, wheel: Wheel, name: str) -> "Distribution":
|
37 |
| - with wheel.as_zipfile() as zf: |
38 |
| - dist = pkg_resources_distribution_for_wheel(zf, name, wheel.location) |
| 39 | + """Load the distribution from a given wheel. |
| 40 | +
|
| 41 | + :raises InvalidWheel: Whenever loading of the wheel causes a |
| 42 | + :py:exc:`zipfile.BadZipFile` exception to be thrown. |
| 43 | + """ |
| 44 | + try: |
| 45 | + with wheel.as_zipfile() as zf: |
| 46 | + dist = pkg_resources_distribution_for_wheel(zf, name, wheel.location) |
| 47 | + except BadZipFile as e: |
| 48 | + raise InvalidWheel(wheel.location, name) from e |
39 | 49 | return cls(dist)
|
40 | 50 |
|
41 | 51 | @property
|
|
0 commit comments