From 6df84da3e7028a2cb008ae762b20ee9b481cf898 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 24 Mar 2026 23:51:49 -0400 Subject: [PATCH] chore: some cleanup and checks (#2792) * chore: clean up config a bit * chore: add an extra check * Apply suggestions from code review Co-authored-by: Henry Schreiner --- .gitignore | 7 +++++++ .pre-commit-config.yaml | 5 ++--- cibuildwheel/__main__.py | 1 - cibuildwheel/extra.py | 2 +- cibuildwheel/platforms/ios.py | 6 ++++-- cibuildwheel/util/packaging.py | 7 +++---- pyproject.toml | 8 +++----- unit_test/main_tests/main_options_test.py | 2 +- unit_test/oci_container_test.py | 18 ++++++++---------- unit_test/options_toml_test.py | 13 ++++++------- 10 files changed, 35 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index d61e9783..78a73045 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,10 @@ site/ # PyCharm .idea/ + +# Lockfiles +*.lock +*.pylock + +# OS files +.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c23cc7e6..a099e38e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: rev: 4924b0e01e032fea073ad04a1c5cfa7e4add0afb # frozen: v0.15.6 hooks: - id: ruff-check - args: ["--fix", "--show-fixes"] + args: ["--fix"] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy @@ -91,8 +91,7 @@ repos: - id: check-github-actions - id: check-github-workflows - id: check-gitlab-ci - # Disabled due to schema issue for now: - # - id: check-readthedocs + - id: check-readthedocs - id: check-travis - id: check-jsonschema name: Check projects diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index dcd9d43e..5b03265f 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -15,7 +15,6 @@ from tempfile import mkdtemp from typing import Any, Literal, TextIO import cibuildwheel -import cibuildwheel.util from cibuildwheel import errors from cibuildwheel.architecture import Architecture, allowed_architectures_check from cibuildwheel.ci import CIProvider, detect_ci_provider, fix_ansi_codes_for_github_actions diff --git a/cibuildwheel/extra.py b/cibuildwheel/extra.py index 0a28cc92..d075d321 100644 --- a/cibuildwheel/extra.py +++ b/cibuildwheel/extra.py @@ -62,7 +62,7 @@ def github_api_request(path: str, *, max_retries: int = 3) -> dict[str, Any]: # pylint: disable=E1101 if ( isinstance(e, urllib.error.HTTPError) - and (e.code == 403 or e.code == 429) + and (e.code in {403, 429}) and e.headers.get("x-ratelimit-remaining") == "0" ): reset_time = int(e.headers.get("x-ratelimit-reset", 0)) diff --git a/cibuildwheel/platforms/ios.py b/cibuildwheel/platforms/ios.py index 33e6899c..58432b09 100644 --- a/cibuildwheel/platforms/ios.py +++ b/cibuildwheel/platforms/ios.py @@ -274,7 +274,8 @@ def setup_python( build_frontend: BuildFrontendName, xbuild_tools: Sequence[str] | None, ) -> tuple[Path, dict[str, str]]: - if build_frontend == "build[uv]" or build_frontend == "uv": + # Not using set because mypy can't narrow it + if build_frontend == "build[uv]" or build_frontend == "uv": # noqa: PLR1714 msg = "uv doesn't support iOS" raise errors.FatalError(msg) @@ -431,7 +432,8 @@ def build(options: Options, tmp_path: Path) -> None: build_options = options.build_options(config.identifier) build_frontend = build_options.build_frontend # uv doesn't support iOS - if build_frontend.name == "build[uv]" or build_frontend.name == "uv": + # Not using set because mypy can't narrow it + if build_frontend.name == "build[uv]" or build_frontend.name == "uv": # noqa: PLR1714 msg = "uv doesn't support iOS" raise errors.FatalError(msg) diff --git a/cibuildwheel/util/packaging.py b/cibuildwheel/util/packaging.py index abb8badd..a068e829 100644 --- a/cibuildwheel/util/packaging.py +++ b/cibuildwheel/util/packaging.py @@ -169,10 +169,9 @@ def find_compatible_wheel(wheels: Sequence[T], identifier: str) -> T | None: elif platform.startswith("pyodide"): # each Pyodide version has its own platform tag continue - else: - # Windows should exactly match - if tag.platform != platform: - continue + # Windows should exactly match + elif tag.platform != platform: + continue # If all the filters above pass, then the wheel is a previously built compatible wheel. return wheel diff --git a/pyproject.toml b/pyproject.toml index 24323b03..7fd4b49f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -128,10 +128,8 @@ files = [ "noxfile.py", ] warn_unused_configs = true - strict = true disallow_untyped_defs = false - enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] warn_unreachable = false @@ -190,6 +188,7 @@ messages_control.disable = [ ] [tool.ruff] +show-fixes = true line-length = 100 [tool.ruff.lint] @@ -228,12 +227,11 @@ extend-select = [ "TC", # flake8-type-checking ] ignore = [ - "PLR", # Design related pylint codes + "PLR09", # Design related pylint codes + "PLR2004", # Magic value in comparison "RET504", "RET505", "RET508", # else after control flow "PT007", # Lists of tuples in Pytest "PYI025", # Set as AbstractSet - "ISC001", # Conflicts with formatter - "EXE003", # Ruff doesn't like uv? "PTH123", # open -> Path.open ] flake8-unused-arguments.ignore-variadic-names = true diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index 7c8a6dde..b518750b 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -184,7 +184,7 @@ def get_default_repair_command(platform: str) -> str: return "auditwheel repair -w {dest_dir} {wheel}" elif platform == "macos": return "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}" - elif platform == "windows" or platform == "pyodide": + elif platform in {"windows", "pyodide"}: return "" else: msg = f"Unknown platform: {platform!r}" diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index e500bd1b..24ba3ae2 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -539,11 +539,10 @@ def test_disable_host_mount( def test_local_image( container_engine: OCIContainerEngineConfig, platform: OCIPlatform, tmp_path: Path ) -> None: - if ( - detect_ci_provider() == CIProvider.travis_ci - and DEFAULT_OCI_PLATFORM != OCIPlatform.AMD64 - and platform != DEFAULT_OCI_PLATFORM - ): + if detect_ci_provider() == CIProvider.travis_ci and DEFAULT_OCI_PLATFORM not in { + OCIPlatform.AMD64, + platform, + }: pytest.skip("Skipping test because docker on this platform does not support QEMU") if container_engine.name == "podman" and platform == OCIPlatform.ARMV7: # both GHA & local macOS arm64 podman desktop are failing @@ -569,11 +568,10 @@ def test_local_image( @pytest.mark.parametrize("platform", list(OCIPlatform)) def test_multiarch_image(container_engine, platform): - if ( - detect_ci_provider() == CIProvider.travis_ci - and DEFAULT_OCI_PLATFORM != OCIPlatform.AMD64 - and platform != DEFAULT_OCI_PLATFORM - ): + if detect_ci_provider() == CIProvider.travis_ci and DEFAULT_OCI_PLATFORM not in { + OCIPlatform.AMD64, + platform, + }: pytest.skip("Skipping test because docker on this platform does not support QEMU") if container_engine.name == "podman" and platform == OCIPlatform.ARMV7: # both GHA & local macOS arm64 podman desktop are failing diff --git a/unit_test/options_toml_test.py b/unit_test/options_toml_test.py index 0fb19f63..c305b0ec 100644 --- a/unit_test/options_toml_test.py +++ b/unit_test/options_toml_test.py @@ -339,13 +339,12 @@ def test_resolve_cascade_merge_list(ignore_empty, rule): if not ignore_empty: assert answer == "b1 b2" - else: - if rule == InheritRule.PREPEND: - assert answer == "b1 b2 a1 a2" - elif rule == InheritRule.NONE: - assert answer == "b1 b2" - elif rule == InheritRule.APPEND: - assert answer == "a1 a2 b1 b2" + elif rule == InheritRule.PREPEND: + assert answer == "b1 b2 a1 a2" + elif rule == InheritRule.NONE: + assert answer == "b1 b2" + elif rule == InheritRule.APPEND: + assert answer == "a1 a2 b1 b2" @pytest.mark.parametrize("rule", [InheritRule.PREPEND, InheritRule.NONE, InheritRule.APPEND])