Skip to content

Commit

Permalink
fix: use py3.8 compatible annotations and cleanup imports
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas committed Dec 4, 2023
1 parent 331a7af commit e85bd8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
24 changes: 12 additions & 12 deletions python/pip_install/tools/wheel_installer/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

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

from __future__ import annotations

import email
from collections import defaultdict
from dataclasses import dataclass, field
from enum import Enum, unique
from pathlib import Path
from typing import Dict, List, Optional, Set, Tuple

import installer
import pkg_resources
Expand All @@ -33,7 +33,7 @@ class OS(Enum):
windows = 3

@staticmethod
def from_tag(tag: str) -> OS:
def from_tag(tag: str) -> "OS":
if tag.startswith("linux"):
return OS.linux
elif tag.startswith("manylinux"):
Expand Down Expand Up @@ -89,7 +89,7 @@ def __str__(self) -> str:
return self.os.name.lower() + "_" + self.arch.name.lower()

@classmethod
def from_tag(cls, tag: str) -> Platform:
def from_tag(cls, tag: str) -> "Platform":
return cls(
os=OS.from_tag(tag),
arch=Arch.from_tag(tag),
Expand Down Expand Up @@ -161,18 +161,18 @@ def _default_select():

@dataclass
class Deps:
deps: set[str] = field(default_factory=set)
select: dict[Platform, set[str]] = field(default_factory=_default_select)
deps: Set[str] = field(default_factory=set)
select: Dict[Platform, Set[str]] = field(default_factory=_default_select)

def add(self, dep: str, platform: Platform | None = None):
def add(self, dep: str, platform: Optional[Platform] = None):
if platform:
self.select[platform].add(dep)
else:
self.deps.add(dep)
for p, deps in self.select.items():
self.select[p] = deps - {dep}

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

def __init__(self, path: str):
def __init__(self, path: Path):
self._path = path

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

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

def dependencies(
self, extras_requested: set[str] = None, platforms=list[Platform]
self, extras_requested: Set[str] = None, platforms=List[Platform]
) -> Deps:
# NOTE @aignas 2023-12-04: if the wheel is a platform specific wheel, we only include deps for that platform
_, _, platform_tag = self._path.name.rpartition("-")
Expand Down
7 changes: 2 additions & 5 deletions python/pip_install/tools/wheel_installer/wheel_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@

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

import argparse
import errno
import glob
import json
import os
import re
import shutil
import subprocess
import sys
import textwrap
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Dict, Iterable, List, Optional, Set, Tuple
from typing import Dict, List, Optional, Set, Tuple

from pip._vendor.packaging.utils import canonicalize_name

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

0 comments on commit e85bd8b

Please sign in to comment.