diff --git a/pyproject.toml b/pyproject.toml index 6cf58061..e981b4e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,11 +96,16 @@ extend-exclude = ["src/wheel/vendored"] [tool.ruff.lint] extend-select = [ "B", # flake8-bugbear + "FLY", # flynt "G", # flake8-logging-format "I", # isort "ISC", # flake8-implicit-str-concat + "PERF", # Perflint "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PLC", # Pylint "RUF100", # unused noqa (yesqa) + "TCH", # flake8-type-checking "UP", # pyupgrade "W", # pycodestyle warnings ] diff --git a/src/wheel/_bdist_wheel.py b/src/wheel/_bdist_wheel.py index 3cc7165e..55ffa5ce 100644 --- a/src/wheel/_bdist_wheel.py +++ b/src/wheel/_bdist_wheel.py @@ -473,7 +473,7 @@ def write_wheelfile( for impl in impl_tag.split("."): for abi in abi_tag.split("."): for plat in plat_tag.split("."): - msg["Tag"] = "-".join((impl, abi, plat)) + msg["Tag"] = f"{impl}-{abi}-{plat}" wheelfile_path = os.path.join(wheelfile_base, "WHEEL") log.info(f"creating {wheelfile_path}") diff --git a/src/wheel/cli/convert.py b/src/wheel/cli/convert.py index 157a4a80..fc7f6e5b 100644 --- a/src/wheel/cli/convert.py +++ b/src/wheel/cli/convert.py @@ -231,7 +231,7 @@ def wininst2wheel(path: str, dest_dir: str) -> None: # CPython-specific. if arch != "any": pyver = pyver.replace("py", "cp") - wheel_name = "-".join((dist_info, pyver, abi, arch)) + wheel_name = f"{dist_info}-{pyver}-{abi}-{arch}" if root_is_purelib: bw = bdist_wheel(Distribution()) else: diff --git a/src/wheel/cli/tags.py b/src/wheel/cli/tags.py index 88da72e9..69478b03 100644 --- a/src/wheel/cli/tags.py +++ b/src/wheel/cli/tags.py @@ -3,11 +3,14 @@ import email.policy import itertools import os -from collections.abc import Iterable from email.parser import BytesParser +from typing import TYPE_CHECKING from ..wheelfile import WheelFile +if TYPE_CHECKING: + from collections.abc import Iterable + def _compute_tags(original_tags: Iterable[str], new_tags: str | None) -> set[str]: """Add or replace tags. Supports dot-separated tags""" diff --git a/src/wheel/macosx_libfile.py b/src/wheel/macosx_libfile.py index abdfc9ed..f321c1fd 100644 --- a/src/wheel/macosx_libfile.py +++ b/src/wheel/macosx_libfile.py @@ -43,10 +43,10 @@ import ctypes import os import sys -from io import BufferedIOBase from typing import TYPE_CHECKING if TYPE_CHECKING: + from io import BufferedIOBase from typing import Union StrPath = Union[str, os.PathLike[str]] @@ -436,7 +436,7 @@ def calculate_macosx_platform_tag(archive_root: StrPath, platform_tag: str) -> s versions_dict: dict[str, tuple[int, int]] = {} for dirpath, _dirnames, filenames in os.walk(archive_root): for filename in filenames: - if filename.endswith(".dylib") or filename.endswith(".so"): + if filename.endswith((".dylib", ".so")): lib_path = os.path.join(dirpath, filename) min_ver = extract_macosx_min_system_version(lib_path) if min_ver is not None: diff --git a/src/wheel/metadata.py b/src/wheel/metadata.py index b8098fa8..8f64b6ff 100644 --- a/src/wheel/metadata.py +++ b/src/wheel/metadata.py @@ -9,12 +9,14 @@ import os.path import re import textwrap -from email.message import Message from email.parser import Parser -from typing import Generator, Iterable, Iterator, Literal +from typing import TYPE_CHECKING, Generator, Iterable, Iterator, Literal from .vendored.packaging.requirements import Requirement +if TYPE_CHECKING: + from email.message import Message + def _nonblank(str: str) -> bool | Literal[""]: return str and not str.startswith("#") @@ -88,16 +90,14 @@ def safe_name(name: str) -> str: def requires_to_requires_dist(requirement: Requirement) -> str: """Return the version specifier for a requirement in PEP 345/566 fashion.""" if requirement.url: - return " @ " + requirement.url + return f" @ {requirement.url}" - requires_dist: list[str] = [] - for spec in requirement.specifier: - requires_dist.append(spec.operator + spec.version) + if requirement.specifier: + return " " + ",".join( + sorted(spec.operator + spec.version for spec in requirement.specifier) + ) - if requires_dist: - return " " + ",".join(sorted(requires_dist)) - else: - return "" + return "" def convert_requirements(requirements: list[str]) -> Iterator[str]: diff --git a/tests/test_bdist_wheel.py b/tests/test_bdist_wheel.py index fcb2dfc4..b16393d5 100644 --- a/tests/test_bdist_wheel.py +++ b/tests/test_bdist_wheel.py @@ -171,7 +171,7 @@ def test_licenses_override(dummy_dist, monkeypatch, tmp_path, config_file, confi ) with WheelFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf: license_files = { - "dummy_dist-1.0.dist-info/" + fname for fname in {"DUMMYFILE", "LICENSE"} + "dummy_dist-1.0.dist-info/" + fname for fname in ("DUMMYFILE", "LICENSE") } assert set(wf.namelist()) == DEFAULT_FILES | license_files