From 34b4f1e86e47792c683de9ef813ed4d614159846 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:48:01 -0400 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#2474) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.11.13 → v0.12.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.13...v0.12.0) - [github.com/pre-commit/mirrors-mypy: v1.16.0 → v1.16.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.16.0...v1.16.1) - [github.com/python-jsonschema/check-jsonschema: 0.33.0 → 0.33.1](https://github.com/python-jsonschema/check-jsonschema/compare/0.33.0...0.33.1) * chore: address new lints Signed-off-by: Henry Schreiner --------- Signed-off-by: Henry Schreiner Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Henry Schreiner --- .pre-commit-config.yaml | 6 ++--- bin/run_example_ci_configs.py | 2 +- cibuildwheel/environment.py | 9 +++---- cibuildwheel/resources/install_certifi.py | 2 +- cibuildwheel/util/helpers.py | 31 ++++++----------------- cibuildwheel/venv.py | 3 +-- pyproject.toml | 1 + unit_test/build_selector_test.py | 7 +++-- 8 files changed, 22 insertions(+), 39 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 94bf4a70..4f449ec0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,14 +14,14 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.13 + rev: v0.12.0 hooks: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.16.0 + rev: v1.16.1 hooks: - id: mypy name: mypy 3.11 on cibuildwheel/ @@ -80,7 +80,7 @@ repos: - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.33.0 + rev: 0.33.1 hooks: - id: check-dependabot - id: check-github-actions diff --git a/bin/run_example_ci_configs.py b/bin/run_example_ci_configs.py index a6bd1bd0..6eb6a4f0 100755 --- a/bin/run_example_ci_configs.py +++ b/bin/run_example_ci_configs.py @@ -28,7 +28,7 @@ def git_repo_has_changes() -> bool: def generate_basic_project(path: Path) -> None: sys.path.insert(0, "") - from test.test_projects.c import new_c_project + from test.test_projects.c import new_c_project # noqa: PLC0415 project = new_c_project() project.generate(path) diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index a9a3f862..4e603f99 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -73,12 +73,16 @@ class EnvironmentAssignmentRaw: return self.value +@dataclasses.dataclass class EnvironmentAssignmentBash: """ An environment variable, in bash syntax. The value can use bash constructs like "$OTHER_VAR" and "$(command arg1 arg2)". """ + name: str + value: str + def __init__(self, assignment: str): name, equals, value = assignment.partition("=") if not equals: @@ -96,11 +100,6 @@ class EnvironmentAssignmentBash: def __repr__(self) -> str: return f"{self.name}={self.value}" - def __eq__(self, other: object) -> bool: - if isinstance(other, EnvironmentAssignmentBash): - return self.name == other.name and self.value == other.value - return False - @dataclasses.dataclass(kw_only=True) class ParsedEnvironment: diff --git a/cibuildwheel/resources/install_certifi.py b/cibuildwheel/resources/install_certifi.py index 86052175..47f528cb 100644 --- a/cibuildwheel/resources/install_certifi.py +++ b/cibuildwheel/resources/install_certifi.py @@ -33,7 +33,7 @@ def main() -> None: [sys.executable, "-E", "-s", "-m", "pip", "install", "--upgrade", "certifi"] ) - import certifi + import certifi # noqa: PLC0415 # change working directory to the default SSL directory os.chdir(openssl_dir) diff --git a/cibuildwheel/util/helpers.py b/cibuildwheel/util/helpers.py index 363fd334..f2e017ef 100644 --- a/cibuildwheel/util/helpers.py +++ b/cibuildwheel/util/helpers.py @@ -1,3 +1,4 @@ +import dataclasses import itertools import os import re @@ -5,7 +6,6 @@ import shlex import textwrap from collections import defaultdict from collections.abc import Sequence -from functools import total_ordering from ..typing import PathOrStr @@ -140,19 +140,17 @@ def parse_key_value_string( return dict(result) -@total_ordering +@dataclasses.dataclass(order=True) class FlexibleVersion: - version_str: str - version_parts: tuple[int, ...] - suffix: str - - def __init__(self, version_str: str) -> None: - self.version_str = version_str + version_parts: tuple[int, ...] = dataclasses.field(init=False, repr=False) + suffix: str = dataclasses.field(init=False, repr=False) + version_str: str = dataclasses.field(compare=False) + def __post_init__(self) -> None: # Split into numeric parts and the optional suffix - match = re.match(r"^[v]?(\d+(\.\d+)*)(.*)$", version_str) + match = re.match(r"^[v]?(\d+(\.\d+)*)(.*)$", self.version_str) if not match: - msg = f"Invalid version string: {version_str}" + msg = f"Invalid version string: {self.version_str}" raise ValueError(msg) version_part, _, suffix = match.groups() @@ -172,18 +170,5 @@ class FlexibleVersion: parts = parts[:-1] return parts - def __eq__(self, other: object) -> bool: - if not isinstance(other, FlexibleVersion): - raise NotImplementedError() - return (self.version_parts, self.suffix) == (other.version_parts, other.suffix) - - def __lt__(self, other: object) -> bool: - if not isinstance(other, FlexibleVersion): - raise NotImplementedError() - return (self.version_parts, self.suffix) < (other.version_parts, other.suffix) - - def __repr__(self) -> str: - return f"FlexibleVersion('{self.version_str}')" - def __str__(self) -> str: return self.version_str diff --git a/cibuildwheel/venv.py b/cibuildwheel/venv.py index 567ba400..d004753c 100644 --- a/cibuildwheel/venv.py +++ b/cibuildwheel/venv.py @@ -157,8 +157,7 @@ def virtualenv( def find_uv() -> Path | None: # Prefer uv in our environment with contextlib.suppress(ImportError, FileNotFoundError): - # pylint: disable-next=import-outside-toplevel - from uv import find_uv_bin + from uv import find_uv_bin # noqa: PLC0415 return Path(find_uv_bin()) diff --git a/pyproject.toml b/pyproject.toml index 0b1ef884..8b8aa27c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -172,6 +172,7 @@ messages_control.disable = [ "unsubscriptable-object", "wrong-import-position", "unused-argument", # Handled by Ruff + "import-outside-toplevel", # Handled by Ruff "broad-exception-raised", # Could be improved eventually "consider-using-in", # MyPy can't narrow "in" ] diff --git a/unit_test/build_selector_test.py b/unit_test/build_selector_test.py index 0b29b388..601fe25f 100644 --- a/unit_test/build_selector_test.py +++ b/unit_test/build_selector_test.py @@ -1,5 +1,6 @@ from packaging.specifiers import SpecifierSet +import cibuildwheel.selector from cibuildwheel.selector import BuildSelector, EnableGroup @@ -224,10 +225,8 @@ def test_build_riscv64_enable(): def test_testing_selector(): - # local import to avoid pytest trying to collect this as a test class! - from cibuildwheel.selector import TestSelector - - test_selector = TestSelector(skip_config="cp36-*") + # This is not a global import to keep pytest from collecting it as a test + test_selector = cibuildwheel.selector.TestSelector(skip_config="cp36-*") assert not test_selector("cp36-win_amd64") assert test_selector("cp37-manylinux_x86_64")