Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply more ruff rules #633

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
2 changes: 1 addition & 1 deletion src/wheel/_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion src/wheel/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
# 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}"

Check warning on line 234 in src/wheel/cli/convert.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/cli/convert.py#L234

Added line #L234 was not covered by tests
if root_is_purelib:
bw = bdist_wheel(Distribution())
else:
Expand Down
5 changes: 4 additions & 1 deletion src/wheel/cli/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 12 in src/wheel/cli/tags.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/cli/tags.py#L12

Added line #L12 was not covered by tests


def _compute_tags(original_tags: Iterable[str], new_tags: str | None) -> set[str]:
"""Add or replace tags. Supports dot-separated tags"""
Expand Down
4 changes: 2 additions & 2 deletions src/wheel/macosx_libfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 49 in src/wheel/macosx_libfile.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/macosx_libfile.py#L49

Added line #L49 was not covered by tests
from typing import Union

StrPath = Union[str, os.PathLike[str]]
Expand Down Expand Up @@ -436,7 +436,7 @@
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:
Expand Down
20 changes: 10 additions & 10 deletions src/wheel/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 18 in src/wheel/metadata.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/metadata.py#L18

Added line #L18 was not covered by tests


def _nonblank(str: str) -> bool | Literal[""]:
return str and not str.startswith("#")
Expand Down Expand Up @@ -88,16 +90,14 @@
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]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading