8000 Merge pull request #1476 from henryiii/henryiii/chore/ruff_ex · pypa/cibuildwheel@dfbc6c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfbc6c3

Browse files
authored
Merge pull request #1476 from henryiii/henryiii/chore/ruff_ex
chore: ruff and typing updates
2 parents 440e18c + 8c5f89c commit dfbc6c3

19 files changed

+112
-92
lines changed

bin/inspect_all_known_projects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from __future__ import annotations
1616

1717
import ast
18+
from collections.abc import Iterable, Iterator
1819
from pathlib import Path
19-
from typing import Iterator
2020

2121
import click
2222
import yaml
@@ -97,7 +97,7 @@ def save(self, filename: Path | str) -> None:
9797
with open(filename, "w") as f:
9898
yaml.safe_dump(self.contents, f, default_flow_style=False)
9999

100-
def on_each(self, repos: list[str]) -> Iterator[tuple[str, str, str | None]]:
100+
def on_each(self, repos: Iterable[str]) -> Iterator[tuple[str, str, str | None]]:
101101
for repo in repos:
102102
print(f"[bold]{repo}:")
103103
for filename in sorted(self.contents, reverse=True):

bin/projects.py

100644100755
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import textwrap
1717
import urllib.request
1818
import xml.dom.minidom
19+
from collections.abc import Iterable, Mapping, Sequence
1920
from datetime import datetime
2021
from io import StringIO
2122
from pathlib import Path
@@ -42,7 +43,7 @@
4243
class Project:
4344
NAME: int = 0
4445

45-
def __init__(self, config: dict[str, Any], github: Github | None = None):
46+
def __init__(self, config: Mapping[str, Any], github: Github | None = None):
4647
try:
4748
self.name: str = config["name"]
4849
self.gh: str = config["gh"]
@@ -149,7 +150,7 @@ def path_for_icon(icon_name: str, relative_to: Path | None = None) -> Path:
149150

150151

151152
def get_projects(
152-
config: list[dict[str, Any]],
153+
config: Iterable[Mapping[str, Any]],
153154
*,
154155
online: bool = True,
155156
auth: str | None = None,
@@ -163,7 +164,7 @@ def get_projects(
163164
return sorted((Project(item, github) for item in config), reverse=online)
164165

165166

166-
def render_projects(projects: list[Project], *, dest_path: Path, include_info: bool = True):
167+
def render_projects(projects: Sequence[Project], *, dest_path: Path, include_info: bool = True):
167168
io = StringIO()
168169
print = functools.partial(builtins.print, file=io)
169170

@@ -191,7 +192,7 @@ def render_projects(projects: list[Project], *, dest_path: Path, include_info: b
191192
def insert_projects_table(
192193
file: Path,
193194
*,
194-
projects: list[Project],
195+
projects: Sequence[Project],
195196
input_filename: str,
196197
include_info: bool = True,
197198
):

bin/update_how_it_works_image.py

100644100755
File mode changed.

bin/update_pythons.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import difflib
77
import logging
88
import sys
9+
from collections.abc import Mapping, MutableMapping
910
from pathlib import Path
1011
from typing import Any, Union
1112

@@ -93,7 +94,7 @@ def update_version_windows(self, spec: Specifier) -> ConfigWinCP | None:
9394
unsorted_versions = spec.filter(self.version_dict)
9495
versions = sorted(unsorted_versions, reverse=True)
9596

96-
log.debug(f"Windows {self.arch} {spec} has {', '.join(str(v) for v in versions)}")
97+
log.debug("Windows %s %s has %s", self.arch, spec, ", ".join(str(v) for v in versions))
9798

9899
if not versions:
99100
return None
@@ -124,7 +125,7 @@ def __init__(self, arch_str: ArchStr):
124125
]
125126
self.arch = arch_str
126127

127-
def get_arch_file(self, release: dict[str, Any]) -> str:
128+
def get_arch_file(self, release: Mapping[str, Any]) -> str:
128129
urls: list[str] = [
129130
rf["download_url"]
130131
for rf in release["files"]
@@ -250,11 +251,11 @@ def __init__(self) -> None:
250251
self.macos_pypy = PyPyVersions("64")
251252
self.macos_pypy_arm64 = PyPyVersions("ARM64")
252253

253-
def update_config(self, config: dict[str, str]) -> None:
254+
def update_config(self, config: MutableMapping[str, str]) -> None:
254255
identifier = config["identifier"]
255256
version = Version(config["version"])
256257
spec = Specifier(f"=={version.major}.{version.minor}.*")
257-
log.info(f"Reading in '{identifier}' -> {spec} @ {version}")
258+
log.info("Reading in %r -> %s @ %s", str(identifier), spec, version)
258259
orig_config = copy.copy(config)
259260
config_update: AnyConfig | None = None
260261

@@ -282,7 +283,7 @@ def update_config(self, config: dict[str, str]) -> None:
282283
config.update(**config_update)
283284

284285
if config != orig_config:
285-
log.info(f" Updated {orig_config} to {config}")
286+
log.info(" Updated %s to %s", orig_config, config)
286287

287288

288289
@click.command()

bin/update_virtualenv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def git_ls_remote_versions(url) -> list[VersionTuple]:
5454
try:
5555
version = Version(version_string)
5656
if version.is_devrelease:
57-
log.info(f"Ignoring development release '{version}'")
57+
log.info("Ignoring development release %r", str(version))
5858
continue
5959
if version.is_prerelease:
60-
log.info(f"Ignoring pre-release '{version}'")
60+
log.info("Ignoring pre-release %r", str(version))
6161
continue
6262
versions.append(VersionTuple(version, version_string))
6363
except InvalidVersion:
64-
log.warning(f"Ignoring ref '{ref}'")
64+
log.warning("Ignoring ref %r", ref)
6565
versions.sort(reverse=True)
6666
return versions
6767

cibuildwheel/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tarfile
88
import textwrap
99
import typing
10-
from collections.abc import Sequence, Set
10+
from collections.abc import Iterable, Sequence, Set
1111
from pathlib import Path
1212
from tempfile import mkdtemp
1313

@@ -337,7 +337,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
337337
log.warning(f"Can't delete temporary folder '{tmp_path}'")
338338

339339

340-
def print_preamble(platform: str, options: Options, identifiers: list[str]) -> None:
340+
def print_preamble(platform: str, options: Options, identifiers: Sequence[str]) -> None:
341341
print(
342342
textwrap.dedent(
343343
"""
@@ -377,7 +377,7 @@ def get_build_identifiers(
377377
return [config.identifier < 10000 span class=pl-k>for config in python_configurations]
378378

379379

380-
def detect_warnings(*, options: Options, identifiers: list[str]) -> list[str]:
380+
def detect_warnings(*, options: Options, identifiers: Iterable[str]) -> list[str]:
381381
warnings = []
382382

383383
# warn about deprecated {python} and {pip}

cibuildwheel/architecture.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import platform as platform_module
55
import re
66
import sys
7+
from collections.abc import Set
78
from enum import Enum
89

910
from .typing import Final, Literal, PlatformName, assert_never
@@ -132,7 +133,7 @@ def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> set[A
132133

133134
def allowed_architectures_check(
134135
platform: PlatformName,
135-
architectures: set[Architecture],
136+
architectures: Set[Architecture],
136137
) -> None:
137138
allowed_architectures = Architecture.all_archs(platform)
138139

cibuildwheel/bashlex_eval.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
from __future__ import annotations
22

33
import subprocess
4+
from collections.abc import Iterable, Mapping, Sequence
45
from dataclasses import dataclass
5-
from typing import Callable, Dict, List, Sequence
6+
from typing import Callable, Dict, List # noqa: TID251
67

78
import bashlex
89

910
# a function 10000 that takes a command and the environment, and returns the result
1011
EnvironmentExecutor = Callable[[List[str], Dict[str, str]], str]
1112

1213

13-
def local_environment_executor(command: list[str], env: dict[str, str]) -> str:
14+
def local_environment_executor(command: Sequence[str], env: Mapping[str, str]) -> str:
1415
return subprocess.run(command, env=env, text=True, stdout=subprocess.PIPE, check=True).stdout
1516

1617

@@ -22,7 +23,7 @@ class NodeExecutionContext:
2223

2324

2425
def evaluate(
25-
value: str, environment: dict[str, str], executor: EnvironmentExecutor | None = None
26+
value: str, environment: Mapping[str, str], executor: EnvironmentExecutor | None = None
2627
) -> str:
2728
if not value:
2829
# empty string evaluates to empty string
@@ -40,7 +41,9 @@ def evaluate(
4041
return evaluate_node(
4142
value_word_node,
4243
context=NodeExecutionContext(
43-
environment=environment, input=value, executor=executor or local_environment_executor
44+
environment=dict(environment),
45+
input=value,
46+
executor=executor or local_environment_executor,
4447
),
4548
)
4649

@@ -105,7 +108,7 @@ def evaluate_nodes_as_compound_command(
105108

106109

107110
def evaluate_nodes_as_simple_command(
108-
nodes: list[bashlex.ast.node], context: NodeExecutionContext
111+
nodes: Iterable[bashlex.ast.node], context: NodeExecutionContext
109112
) -> str:
110113
command = [evaluate_node(part, context=context) for part in nodes]
111114
return context.executor(command, context.environment)

cibuildwheel/environment.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import dataclasses
4-
from typing import Any, Mapping, Sequence
4+
from collections.abc import Mapping, Sequence
5+
from typing import Any
56

67
import bashlex
78
import bashlex.errors
@@ -54,7 +55,7 @@ class EnvironmentAssignment(Protocol):
5455
def evaluated_value(
5556
self,
5657
*,
57-
environment: dict[str, str],
58+
environment: Mapping[str, str],
5859
executor: bashlex_eval.EnvironmentExecutor | None = None,
5960
) -> str:
6061
"""Returns the value of this assignment, as evaluated in the environment"""
@@ -91,7 +92,7 @@ def __init__(self, assignment: str):
9192

9293
def evaluated_value(
9394
self,
94-
environment: dict[str, str],
95+
environment: Mapping[str, str],
9596
executor: bashlex_eval.EnvironmentExecutor | None = None,
9697
) -> str:
9798
return bashlex_eval.evaluate(self.value, environment=environment, executor=executor)

cibuildwheel/extra.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
from collections.abc import Mapping, Sequence
78
from io import StringIO
89

910
from .typing import Protocol
@@ -16,7 +17,9 @@ def __str__(self) -> str:
1617
...
1718

1819

19-
def dump_python_configurations(inp: dict[str, dict[str, list[dict[str, Printable]]]]) -> str:
20+
def dump_python_configurations(
21+
inp: Mapping[str, Mapping[str, Sequence[Mapping[str, Printable]]]]
22+
) -> str:
2023
output = < 42FB span class=pl-en>StringIO()
2124
for header, values in inp.items():
2225
output.write(f"[{header}]\n")

0 commit comments

Comments
 (0)
0