summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2021-12-26 15:37:12 +0200
committerAlex Grönholm <alex.gronholm@nextday.fi>2021-12-26 15:46:10 +0200
commitdcac1db3a6b4be9e8d1d5173970f234ee29768e4 (patch)
treea2eebf846ad701656ad9f18ce074d6c5672a58cc /src
parent13458f5a62ad783402aacc8e3923b09e6c812983 (diff)
downloadwheel-git-dcac1db3a6b4be9e8d1d5173970f234ee29768e4.tar.gz
Added the first batch of type annotations
Diffstat (limited to 'src')
-rwxr-xr-xsrc/wheel/cli/convert.py2
-rw-r--r--src/wheel/cli/pack.py4
-rw-r--r--src/wheel/cli/unpack.py8
-rw-r--r--src/wheel/metadata.py23
-rw-r--r--src/wheel/util.py6
5 files changed, 26 insertions, 17 deletions
diff --git a/src/wheel/cli/convert.py b/src/wheel/cli/convert.py
index b2f685f..08239d9 100755
--- a/src/wheel/cli/convert.py
+++ b/src/wheel/cli/convert.py
@@ -36,7 +36,7 @@ class _bdist_wheel_tag(bdist_wheel):
return bdist_wheel.get_tag(self)
-def egg2wheel(egg_path, dest_dir):
+def egg2wheel(egg_path: str, dest_dir: str):
filename = os.path.basename(egg_path)
match = egg_info_re.match(filename)
if not match:
diff --git a/src/wheel/cli/pack.py b/src/wheel/cli/pack.py
index 349f722..b50bf22 100644
--- a/src/wheel/cli/pack.py
+++ b/src/wheel/cli/pack.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import os.path
import re
@@ -8,7 +10,7 @@ DIST_INFO_RE = re.compile(r"^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))\.dist-inf
BUILD_NUM_RE = re.compile(br"Build: (\d\w*)$")
-def pack(directory, dest_dir, build_number):
+def pack(directory: str, dest_dir: str, build_number: str | None):
"""Repack a previously unpacked wheel directory into a new wheel file.
The .dist-info/WHEEL file must contain one or more tags so that the target
diff --git a/src/wheel/cli/unpack.py b/src/wheel/cli/unpack.py
index ffd0e81..c6409d4 100644
--- a/src/wheel/cli/unpack.py
+++ b/src/wheel/cli/unpack.py
@@ -1,9 +1,11 @@
-import os.path
+from __future__ import annotations
+
+from pathlib import Path
from ..wheelfile import WheelFile
-def unpack(path, dest="."):
+def unpack(path: str, dest: str = ".") -> None:
"""Unpack a wheel.
Wheel content will be unpacked to {dest}/{name}-{ver}, where {name}
@@ -14,7 +16,7 @@ def unpack(path, dest="."):
"""
with WheelFile(path) as wf:
namever = wf.parsed_filename.group("namever")
- destination = os.path.join(dest, namever)
+ destination = Path(dest) / namever
print(f"Unpacking to: {destination}...", end="", flush=True)
wf.extractall(destination)
diff --git a/src/wheel/metadata.py b/src/wheel/metadata.py
index 254fbd8..71e887e 100644
--- a/src/wheel/metadata.py
+++ b/src/wheel/metadata.py
@@ -1,15 +1,18 @@
"""
Tools for converting old- to new-style metadata.
"""
+from __future__ import annotations
import os.path
import textwrap
+from email.message import Message
from email.parser import Parser
+from typing import Iterator, Tuple
-import pkg_resources
+from pkg_resources import Requirement, safe_extra, split_sections
-def requires_to_requires_dist(requirement):
+def requires_to_requires_dist(requirement: Requirement) -> str:
"""Return the version specifier for a requirement in PEP 345/566 fashion."""
if getattr(requirement, "url", None):
return " @ " + requirement.url
@@ -24,10 +27,10 @@ def requires_to_requires_dist(requirement):
return ""
-def convert_requirements(requirements):
+def convert_requirements(requirements: list[str]) -> Iterator[str]:
"""Yield Requires-Dist: strings for parsed requirements strings."""
for req in requirements:
- parsed_requirement = pkg_resources.Requirement.parse(req)
+ parsed_requirement = Requirement.parse(req)
spec = requires_to_requires_dist(parsed_requirement)
extras = ",".join(sorted(parsed_requirement.extras))
if extras:
@@ -36,7 +39,9 @@ def convert_requirements(requirements):
yield parsed_requirement.project_name + extras + spec
-def generate_requirements(extras_require):
+def generate_requirements(
+ extras_require: dict[str, list[str]]
+) -> Iterator[Tuple[str, str]]:
"""
Convert requirements from a setup()-style dictionary to
('Requires-Dist', 'requirement') and ('Provides-Extra', 'extra') tuples.
@@ -50,7 +55,7 @@ def generate_requirements(extras_require):
if ":" in extra: # setuptools extra:condition syntax
extra, condition = extra.split(":", 1)
- extra = pkg_resources.safe_extra(extra)
+ extra = safe_extra(extra)
if extra:
yield "Provides-Extra", extra
if condition:
@@ -64,7 +69,7 @@ def generate_requirements(extras_require):
yield "Requires-Dist", new_req + condition
-def pkginfo_to_metadata(egg_info_path, pkginfo_path):
+def pkginfo_to_metadata(egg_info_path: str, pkginfo_path: str) -> Message:
"""
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
"""
@@ -80,9 +85,7 @@ def pkginfo_to_metadata(egg_info_path, pkginfo_path):
with open(requires_path) as requires_file:
requires = requires_file.read()
- parsed_requirements = sorted(
- pkg_resources.split_sections(requires), key=lambda x: x[0] or ""
- )
+ parsed_requirements = sorted(split_sections(requires), key=lambda x: x[0] or "")
for extra, reqs in parsed_requirements:
for key, value in generate_requirements({extra: reqs}):
if (key, value) not in pkg_info.items():
diff --git a/src/wheel/util.py b/src/wheel/util.py
index f17cafd..4c37127 100644
--- a/src/wheel/util.py
+++ b/src/wheel/util.py
@@ -1,12 +1,14 @@
+from __future__ import annotations
+
import base64
-def urlsafe_b64encode(data):
+def urlsafe_b64encode(data: bytes) -> bytes:
"""urlsafe_b64encode without padding"""
return base64.urlsafe_b64encode(data).rstrip(b"=")
-def urlsafe_b64decode(data):
+def urlsafe_b64decode(data: bytes) -> bytes:
"""urlsafe_b64decode without padding"""
pad = b"=" * (4 - (len(data) & 3))
return base64.urlsafe_b64decode(data + pad)