|
4 | 4 |
|
5 | 5 | from __future__ import annotations
|
6 | 6 |
|
7 |
| -import re |
8 | 7 | from collections.abc import Iterable
|
9 | 8 |
|
10 | 9 | from pip._vendor.packaging.tags import Tag
|
11 |
| -from pip._vendor.packaging.utils import BuildTag, parse_wheel_filename |
12 | 10 | from pip._vendor.packaging.utils import (
|
13 | 11 | InvalidWheelFilename as _PackagingInvalidWheelFilename,
|
14 | 12 | )
|
| 13 | +from pip._vendor.packaging.utils import parse_wheel_filename |
15 | 14 |
|
16 | 15 | from pip._internal.exceptions import InvalidWheelFilename
|
17 |
| -from pip._internal.utils.deprecation import deprecated |
18 | 16 |
|
19 | 17 |
|
20 | 18 | class Wheel:
|
21 | 19 | """A wheel file"""
|
22 | 20 |
|
23 |
| - legacy_wheel_file_re = re.compile( |
24 |
| - r"""^(?P<namever>(?P<name>[^\s-]+?)-(?P<ver>[^\s-]*?)) |
25 |
| - ((-(?P<build>\d[^-]*?))?-(?P<pyver>[^\s-]+?)-(?P<abi>[^\s-]+?)-(?P<plat>[^\s-]+?) |
26 |
| - \.whl|\.dist-info)$""", |
27 |
| - re.VERBOSE, |
28 |
| - ) |
29 |
| - |
30 | 21 | def __init__(self, filename: str) -> None:
|
31 | 22 | self.filename = filename
|
32 | 23 |
|
33 |
| - # To make mypy happy specify type hints that can come from either |
34 |
| - # parse_wheel_filename or the legacy_wheel_file_re match. |
35 |
| - self.name: str |
36 |
| - self._build_tag: BuildTag | None = None |
37 |
| - |
38 | 24 | try:
|
39 | 25 | wheel_info = parse_wheel_filename(filename)
|
40 |
| - self.name, _version, self._build_tag, self.file_tags = wheel_info |
41 |
| - self.version = str(_version) |
42 | 26 | except _PackagingInvalidWheelFilename as e:
|
43 |
| - # Check if the wheel filename is in the legacy format |
44 |
| - legacy_wheel_info = self.legacy_wheel_file_re.match(filename) |
45 |
| - if not legacy_wheel_info: |
46 |
| - raise InvalidWheelFilename(e.args[0]) from None |
47 |
| - |
48 |
| - deprecated( |
49 |
| - reason=( |
50 |
| - f"Wheel filename {filename!r} is not correctly normalised. " |
51 |
| - "Future versions of pip will raise the following error:\n" |
52 |
| - f"{e.args[0]}\n\n" |
53 |
| - ), |
54 |
| - replacement=( |
55 |
| - "to rename the wheel to use a correctly normalised " |
56 |
| - "name (this may require updating the version in " |
57 |
| - "the project metadata)" |
58 |
| - ), |
59 |
| - gone_in="25.3", |
60 |
| - issue=12938, |
61 |
| - ) |
62 |
| - |
63 |
| - self.name = legacy_wheel_info.group("name").replace("_", "-") |
64 |
| - self.version = legacy_wheel_info.group("ver").replace("_", "-") |
65 |
| - |
66 |
| - # Generate the file tags from the legacy wheel filename |
67 |
| - pyversions = legacy_wheel_info.group("pyver").split(".") |
68 |
| - abis = legacy_wheel_info.group("abi").split(".") |
69 |
| - plats = legacy_wheel_info.group("plat").split(".") |
70 |
| - self.file_tags = frozenset( |
71 |
| - Tag(interpreter=py, abi=abi, platform=plat) |
72 |
| - for py in pyversions |
73 |
| - for abi in abis |
74 |
| - for plat in plats |
75 |
| - ) |
76 |
| - |
77 |
| - @property |
78 |
| - def build_tag(self) -> BuildTag: |
79 |
| - if self._build_tag is not None: |
80 |
| - return self._build_tag |
81 |
| - |
82 |
| - # Parse the build tag from the legacy wheel filename |
83 |
| - legacy_wheel_info = self.legacy_wheel_file_re.match(self.filename) |
84 |
| - assert legacy_wheel_info is not None, "guaranteed by filename validation" |
85 |
| - build_tag = legacy_wheel_info.group("build") |
86 |
| - match = re.match(r"^(\d+)(.*)$", build_tag) |
87 |
| - assert match is not None, "guaranteed by filename validation" |
88 |
| - build_tag_groups = match.groups() |
89 |
| - self._build_tag = (int(build_tag_groups[0]), build_tag_groups[1]) |
90 |
| - |
91 |
| - return self._build_tag |
| 27 | + raise InvalidWheelFilename(e.args[0]) from None |
| 28 | + |
| 29 | + self.name, _version, self.build_tag, self.file_tags = wheel_info |
| 30 | + self.version = str(_version) |
92 | 31 |
|
93 | 32 | def get_formatted_file_tags(self) -> list[str]:
|
94 | 33 | """Return the wheel's tags as a sorted list of strings."""
|
|
0 commit comments