Skip to content

Commit e1baa60

Browse files
authored
chore: enable more Ruff checks (#2654)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 1f2f8b2 commit e1baa60

File tree

16 files changed

+51
-37
lines changed

16 files changed

+51
-37
lines changed

bin/bump_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def bump_version() -> None:
6868
sys.exit(1)
6969

7070
# fmt: off
71-
print( 'Current version:', current_version)
72-
new_version = input(' New version: ').strip()
71+
print( "Current version:", current_version)
72+
new_version = input(" New version: ").strip()
7373
# fmt: on
7474

7575
try:

cibuildwheel/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
314314
if args.only:
315315
return _compute_platform_only(args.only)
316316
elif platform_option_value != "auto":
317-
return typing.cast(PlatformName, platform_option_value)
317+
return typing.cast("PlatformName", platform_option_value)
318318

319319
return native_platform()
320320

cibuildwheel/extra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def dump_python_configurations(
4141

4242
def _json_request(request: urllib.request.Request, timeout: int = 30) -> dict[str, Any]:
4343
with urllib.request.urlopen(request, timeout=timeout) as response:
44-
return typing.cast(dict[str, Any], json.load(response))
44+
return typing.cast("dict[str, Any]", json.load(response))
4545

4646

4747
def github_api_request(path: str, *, max_retries: int = 3) -> dict[str, Any]:
@@ -98,4 +98,4 @@ def get_pyodide_xbuildenv_info() -> PyodideXBuildEnvInfo:
9898
"https://pyodide.github.io/pyodide/api/pyodide-cross-build-environments.json"
9999
)
100100
with urllib.request.urlopen(xbuildenv_info_url) as response:
101-
return typing.cast(PyodideXBuildEnvInfo, json.loads(response.read().decode("utf-8")))
101+
return typing.cast("PyodideXBuildEnvInfo", json.loads(response.read().decode("utf-8")))

cibuildwheel/frontend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def from_config_string(cls, config_string: str) -> Self:
2424
msg = f"Unrecognised build frontend {name!r}, must be one of {names}"
2525
raise ValueError(msg)
2626

27-
name = typing.cast(BuildFrontendName, name)
27+
name = typing.cast("BuildFrontendName", name)
2828

2929
args = config_dict.get("args") or []
3030
return cls(name=name, args=args)

cibuildwheel/oci_container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def from_config_string(cls, config_string: str) -> Self:
7878
msg = f"unknown container engine {name}"
7979
raise ValueError(msg)
8080

81-
name = typing.cast(ContainerEngineName, name)
81+
name = typing.cast("ContainerEngineName", name)
8282
# some flexibility in the option names to cope with TOML conventions
8383
create_args = config_dict.get("create_args") or config_dict.get("create-args") or []
8484
disable_host_mount_options = (
@@ -515,7 +515,7 @@ def get_environment(self) -> dict[str, str]:
515515
capture_output=True,
516516
)
517517
)
518-
return typing.cast(dict[str, str], env)
518+
return typing.cast("dict[str, str]", env)
519519

520520
def environment_executor(self, command: Sequence[str], environment: dict[str, str]) -> str:
521521
# used as an EnvironmentExecutor to evaluate commands and capture output

cibuildwheel/platforms/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
from __future__ import annotations
22

33
import sys
4-
from collections.abc import Sequence
5-
from pathlib import Path
6-
from typing import Final, Protocol
4+
from typing import TYPE_CHECKING, Final, Protocol
75

86
from cibuildwheel import errors
9-
from cibuildwheel.architecture import Architecture
10-
from cibuildwheel.options import Options
117
from cibuildwheel.platforms import android, ios, linux, macos, pyodide, windows
12-
from cibuildwheel.selector import BuildSelector
13-
from cibuildwheel.typing import GenericPythonConfiguration, PlatformName
8+
9+
if TYPE_CHECKING:
10+
from collections.abc import Sequence
11+
from pathlib import Path
12+
13+
from cibuildwheel.architecture import Architecture
14+
from cibuildwheel.options import Options
15+
from cibuildwheel.selector import BuildSelector
16+
from cibuildwheel.typing import GenericPythonConfiguration, PlatformName
1417

1518

1619
class PlatformModule(Protocol):

cibuildwheel/platforms/ios.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@
88
import subprocess
99
import sys
1010
import textwrap
11-
from collections.abc import Sequence, Set
1211
from pathlib import Path
13-
from typing import assert_never
12+
from typing import TYPE_CHECKING, assert_never
1413

1514
from filelock import FileLock
1615

1716
from .. import errors
18-
from ..architecture import Architecture
19-
from ..environment import ParsedEnvironment
2017
from ..frontend import (
2118
BuildFrontendName,
2219
get_build_frontend_extra_flags,
2320
)
2421
from ..logger import log
25-
from ..options import Options
26-
from ..selector import BuildSelector
2722
from ..util import resources
2823
from ..util.cmd import call, shell, split_command
2924
from ..util.file import (
@@ -39,6 +34,14 @@
3934
from ..venv import constraint_flags, virtualenv
4035
from .macos import install_cpython as install_build_cpython
4136

37+
if TYPE_CHECKING:
38+
from collections.abc import Sequence, Set
39+
40+
from ..architecture import Architecture
41+
from ..environment import ParsedEnvironment
42+
from ..options import Options
43+
from ..selector import BuildSelector
44+
4245

4346
@dataclasses.dataclass(frozen=True, kw_only=True)
4447
class PythonConfiguration:

cibuildwheel/platforms/linux.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections import OrderedDict
77
from collections.abc import Iterable, Iterator, Sequence, Set
88
from pathlib import Path, PurePath, PurePosixPath
9-
from typing import assert_never
9+
from typing import TYPE_CHECKING, assert_never
1010

1111
from .. import errors
1212
from ..architecture import Architecture
@@ -15,12 +15,14 @@
1515
from ..oci_container import OCIContainer, OCIContainerEngineConfig, OCIPlatform
1616
from ..options import BuildOptions, Options
1717
from ..selector import BuildSelector
18-
from ..typing import PathOrStr
1918
from ..util import resources
2019
from ..util.file import copy_test_sources
2120
from ..util.helpers import prepare_command, unwrap
2221
from ..util.packaging import find_compatible_wheel
2322

23+
if TYPE_CHECKING:
24+
from ..typing import PathOrStr
25+
2426
ARCHITECTURE_OCI_PLATFORM_MAP = {
2527
Architecture.x86_64: OCIPlatform.AMD64,
2628
Architecture.i686: OCIPlatform.i386,

cibuildwheel/platforms/macos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def get_macos_version() -> tuple[int, int]:
6060
capture_stdout=True,
6161
)
6262
version = tuple(map(int, version_str.split(".")[:2]))
63-
return typing.cast(tuple[int, int], version)
63+
return typing.cast("tuple[int, int]", version)
6464

6565

6666
@functools.cache

cibuildwheel/platforms/pyodide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_all_xbuildenv_version_info(env: dict[str, str]) -> list[PyodideXBuildEnv
130130
msg = f"Invalid xbuildenvs info, got {xbuildenvs_info}"
131131
raise ValueError(msg)
132132

133-
return typing.cast(list[PyodideXBuildEnvInfo], xbuildenvs_info["environments"])
133+
return typing.cast("list[PyodideXBuildEnvInfo]", xbuildenvs_info["environments"])
134134

135135

136136
def get_xbuildenv_version_info(

0 commit comments

Comments
 (0)