Skip to content

Commit e85bd8b

Browse files
committed
fix: use py3.8 compatible annotations and cleanup imports
1 parent 331a7af commit e85bd8b

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

python/pip_install/tools/wheel_installer/wheel.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
"""Utility class to inspect an extracted wheel directory"""
1616

17-
from __future__ import annotations
18-
1917
import email
2018
from collections import defaultdict
2119
from dataclasses import dataclass, field
2220
from enum import Enum, unique
21+
from pathlib import Path
22+
from typing import Dict, List, Optional, Set, Tuple
2323

2424
import installer
2525
import pkg_resources
@@ -33,7 +33,7 @@ class OS(Enum):
3333
windows = 3
3434

3535
@staticmethod
36-
def from_tag(tag: str) -> OS:
36+
def from_tag(tag: str) -> "OS":
3737
if tag.startswith("linux"):
3838
return OS.linux
3939
elif tag.startswith("manylinux"):
@@ -89,7 +89,7 @@ def __str__(self) -> str:
8989
return self.os.name.lower() + "_" + self.arch.name.lower()
9090

9191
@classmethod
92-
def from_tag(cls, tag: str) -> Platform:
92+
def from_tag(cls, tag: str) -> "Platform":
9393
return cls(
9494
os=OS.from_tag(tag),
9595
arch=Arch.from_tag(tag),
@@ -161,18 +161,18 @@ def _default_select():
161161

162162
@dataclass
163163
class Deps:
164-
deps: set[str] = field(default_factory=set)
165-
select: dict[Platform, set[str]] = field(default_factory=_default_select)
164+
deps: Set[str] = field(default_factory=set)
165+
select: Dict[Platform, Set[str]] = field(default_factory=_default_select)
166166

167-
def add(self, dep: str, platform: Platform | None = None):
167+
def add(self, dep: str, platform: Optional[Platform] = None):
168168
if platform:
169169
self.select[platform].add(dep)
170170
else:
171171
self.deps.add(dep)
172172
for p, deps in self.select.items():
173173
self.select[p] = deps - {dep}
174174

175-
def build(self, all_platforms: list[Platform]) -> Deps:
175+
def build(self, all_platforms: List[Platform]) -> "Deps":
176176
# Move deps to common deps if they are present for all platforms
177177
common_deps = None
178178
for plat in all_platforms:
@@ -192,7 +192,7 @@ def build(self, all_platforms: list[Platform]) -> Deps:
192192
class Wheel:
193193
"""Representation of the compressed .whl file"""
194194

195-
def __init__(self, path: str):
195+
def __init__(self, path: Path):
196196
self._path = path
197197

198198
@property
@@ -217,13 +217,13 @@ def version(self) -> str:
217217
# TODO Also available as installer.sources.WheelSource.version
218218
return str(self.metadata["Version"])
219219

220-
def entry_points(self) -> dict[str, tuple[str, str]]:
220+
def entry_points(self) -> Dict[str, Tuple[str, str]]:
221221
"""Returns the entrypoints defined in the current wheel
222222
223223
See https://packaging.python.org/specifications/entry-points/ for more info
224224
225225
Returns:
226-
dict[str, tuple[str, str]]: A mapping of the entry point's name to it's module and attribute
226+
Dict[str, Tuple[str, str]]: A mapping of the entry point's name to it's module and attribute
227227
"""
228228
with installer.sources.WheelFile.open(self.path) as wheel_source:
229229
if "entry_points.txt" not in wheel_source.dist_info_filenames:
@@ -239,7 +239,7 @@ def entry_points(self) -> dict[str, tuple[str, str]]:
239239
return entry_points_mapping
240240

241241
def dependencies(
242-
self, extras_requested: set[str] = None, platforms=list[Platform]
242+
self, extras_requested: Set[str] = None, platforms=List[Platform]
243243
) -> Deps:
244244
# NOTE @aignas 2023-12-04: if the wheel is a platform specific wheel, we only include deps for that platform
245245
_, _, platform_tag = self._path.name.rpartition("-")

python/pip_install/tools/wheel_installer/wheel_installer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@
1414

1515
"""Build and/or fetch a single wheel based on the requirement passed in"""
1616

17-
import argparse
1817
import errno
1918
import glob
2019
import json
2120
import os
2221
import re
23-
import shutil
2422
import subprocess
2523
import sys
26-
import textwrap
2724
from pathlib import Path
2825
from tempfile import NamedTemporaryFile
29-
from typing import Dict, Iterable, List, Optional, Set, Tuple
26+
from typing import Dict, List, Optional, Set, Tuple
3027

3128
from pip._vendor.packaging.utils import canonicalize_name
3229

@@ -108,7 +105,7 @@ def _extract_wheel(
108105
wheel_file: str,
109106
extras: Dict[str, Set[str]],
110107
enable_implicit_namespace_pkgs: bool,
111-
platforms: list[wheel.Platform],
108+
platforms: List[wheel.Platform],
112109
installation_dir: Path = Path("."),
113110
) -> None:
114111
"""Extracts wheel into given directory and creates py_library and filegroup targets.

0 commit comments

Comments
 (0)