From 76b4ed2058eb205281cf1a01f078c6b0e0c0af93 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 24 Aug 2024 22:44:31 +0300 Subject: [PATCH 1/5] Apply ruff/Perflint rule PERF401 PERF401 Use a list comprehension to create a transformed list --- src/wheel/metadata.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/wheel/metadata.py b/src/wheel/metadata.py index b8098fa8..90d7a585 100644 --- a/src/wheel/metadata.py +++ b/src/wheel/metadata.py @@ -88,16 +88,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]: From 34b8386e2f47f10e14e21944554514c1ce8c1497 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:00:33 +0300 Subject: [PATCH 2/5] Apply ruff/flake8-pie rule PIE810 PIE810 Call `endswith` once with a `tuple` --- src/wheel/macosx_libfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wheel/macosx_libfile.py b/src/wheel/macosx_libfile.py index abdfc9ed..26d780a1 100644 --- a/src/wheel/macosx_libfile.py +++ b/src/wheel/macosx_libfile.py @@ -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: From 93c568db23efbe4b51dc9eb4d17644b33831985b Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:02:58 +0300 Subject: [PATCH 3/5] Apply ruff/Pylint rule PLC0208 PLC0208 Use a sequence type instead of a `set` when iterating over values --- tests/test_bdist_wheel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7abf08f685bf838814c765eae1529eb8cb03a8e9 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:08:09 +0300 Subject: [PATCH 4/5] Apply ruff/flynt rule FLY002 FLY002 Consider f-string instead of string join --- src/wheel/_bdist_wheel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wheel/_bdist_wheel.py b/src/wheel/_bdist_wheel.py index 88973ebf..327832ed 100644 --- a/src/wheel/_bdist_wheel.py +++ b/src/wheel/_bdist_wheel.py @@ -482,7 +482,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}") From 494b33c9448299b78a27d5f53a5e1af8e63c675d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:28:38 +0300 Subject: [PATCH 5/5] Enforce more ruff rules --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 5ed07b11..e3a1b236 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,10 +101,14 @@ 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) "UP", # pyupgrade "W", # pycodestyle warnings