Skip to content

Commit 64e75d8

Browse files
committed
chore: some cleanup from ruff --preview checks
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 2ae210c commit 64e75d8

File tree

13 files changed

+46
-42
lines changed

13 files changed

+46
-42
lines changed

bin/update_docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Image:
2222

2323
class PyPAImage(Image):
2424
def __init__(self, manylinux_version: str, platform: str, tag: str | None):
25-
platform_no_pypy = platform[5:] if platform.startswith("pypy_") else platform
25+
platform_no_pypy = platform.removeprefix("pypy_")
2626
image_name = f"quay.io/pypa/{manylinux_version}_{platform_no_pypy}"
2727
super().__init__(manylinux_version, platform, image_name, tag)
2828

bin/update_pythons.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
import difflib
77
import logging
8+
import operator
89
import tomllib
910
from collections.abc import Mapping, MutableMapping
1011
from pathlib import Path
@@ -133,7 +134,7 @@ def get_arch_file(self, release: Mapping[str, Any]) -> str:
133134

134135
def update_version_windows(self, spec: Specifier) -> ConfigWinCP:
135136
releases = [r for r in self.releases if spec.contains(r["python_version"])]
136-
releases = sorted(releases, key=lambda r: r["pypy_version"])
137+
releases = sorted(releases, key=operator.itemgetter("pypy_version"))
137138
releases = [r for r in releases if self.get_arch_file(r)]
138139

139140
if not releases:
@@ -160,7 +161,7 @@ def update_version_macos(self, spec: Specifier) -> ConfigMacOS:
160161
raise RuntimeError(msg)
161162

162163
releases = [r for r in self.releases if spec.contains(r["python_version"])]
163-
releases = sorted(releases, key=lambda r: r["pypy_version"])
164+
releases = sorted(releases, key=operator.itemgetter("pypy_version"))
164165

165166
if not releases:
166167
msg = f"PyPy macOS {self.arch} not found for {spec}!"

cibuildwheel/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def main_inner(global_options: GlobalOptions) -> None:
160160
parser.add_argument(
161161
"package_dir",
162162
metavar="PACKAGE",
163-
default=Path("."),
163+
default=Path(),
164164
type=Path,
165165
nargs="?",
166166
help="""

cibuildwheel/macos.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def build(options: Options, tmp_path: Path) -> None:
719719
# and not the repo code)
720720
test_command_prepared = prepare_command(
721721
build_options.test_command,
722-
project=Path(".").resolve(),
722+
project=Path.cwd(),
723723
package=build_options.package_dir.resolve(),
724724
wheel=repaired_wheel,
725725
)
@@ -734,7 +734,7 @@ def build(options: Options, tmp_path: Path) -> None:
734734
)
735735
else:
736736
# There are no test sources. Run the tests in the project directory.
737-
test_cwd = Path(".").resolve()
737+
test_cwd = Path.cwd()
738738

739739
shell_with_arch(test_command_prepared, cwd=test_cwd, env=virtualenv_env)
740740

@@ -744,7 +744,7 @@ def build(options: Options, tmp_path: Path) -> None:
744744
moved_wheel = move_file(repaired_wheel, output_wheel)
745745
if moved_wheel != output_wheel.resolve():
746746
log.warning(
747-
"{repaired_wheel} was moved to {moved_wheel} instead of {output_wheel}"
747+
f"{repaired_wheel} was moved to {moved_wheel} instead of {output_wheel}"
748748
)
749749
built_wheels.append(output_wheel)
750750

cibuildwheel/options.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def defaults() -> CommandLineArguments:
7373
only=None,
7474
config_file="",
7575
output_dir=Path("wheelhouse"),
76-
package_dir=Path("."),
76+
package_dir=Path(),
7777
print_build_identifiers=False,
7878
debug_traceback=False,
7979
enable=[],
@@ -184,7 +184,7 @@ class ListFormat(OptionFormat):
184184

185185
def __init__(self, sep: str, quote: Callable[[str], str] | None = None) -> None:
186186
self.sep = sep
187-
self.quote = quote if quote else lambda s: s
187+
self.quote = quote or (lambda s: s)
188188

189189
def format_list(self, value: SettingList) -> str:
190190
return self.sep.join(self.quote(str(v)) for v in value)
@@ -265,10 +265,12 @@ class EnvironmentFormat(OptionFormat):
265265
values may contain variables or command substitutions.
266266
"""
267267

268-
def format_table(self, table: SettingTable) -> str:
268+
@staticmethod
269+
def format_table(table: SettingTable) -> str:
269270
return " ".join(f'{k}="{v}"' for k, v in table.items())
270271

271-
def merge_values(self, before: str, after: str) -> str:
272+
@staticmethod
273+
def merge_values(before: str, after: str) -> str:
272274
return f"{before} {after}"
273275

274276

@@ -630,8 +632,7 @@ def globals(self) -> GlobalOptions:
630632
)
631633
try:
632634
enable = {EnableGroup(group) for group in enable_groups.split()}
633-
for command_line_group in args.enable:
634-
enable.add(EnableGroup(command_line_group))
635+
enable.update(EnableGroup(command_line_group) for command_line_group in args.enable)
635636
except ValueError as e:
636637
msg = f"Failed to parse enable group. {e}. Valid group names are: {', '.join(g.value for g in EnableGroup)}"
637638
raise errors.ConfigurationError(msg) from e
@@ -737,9 +738,9 @@ def build_options(self, identifier: str | None) -> BuildOptions:
737738
environment.add(env_var_name, self.env[env_var_name], prepend=True)
738739

739740
if dependency_versions == "pinned":
740-
dependency_constraints: None | (
741-
DependencyConstraints
742-
) = DependencyConstraints.with_defaults()
741+
dependency_constraints: DependencyConstraints | None = (
742+
DependencyConstraints.with_defaults()
743+
)
743744
elif dependency_versions == "latest":
744745
dependency_constraints = None
745746
else:
@@ -932,13 +933,15 @@ def option_summary(
932933

933934
return result
934935

935-
def indent_if_multiline(self, value: str, indent: str) -> str:
936+
@staticmethod
937+
def indent_if_multiline(value: str, indent: str) -> str:
936938
if "\n" in value:
937939
return "\n" + textwrap.indent(value.strip(), indent)
938940
else:
939941
return value
940942

941-
def option_summary_value(self, option_value: Any) -> str:
943+
@staticmethod
944+
def option_summary_value(option_value: Any) -> str:
942945
if hasattr(option_value, "options_summary"):
943946
option_value = option_value.options_summary()
944947

cibuildwheel/pyodide.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def build(options: Options, tmp_path: Path) -> None:
292292
# directory.
293293
oldmounts = ""
294294
extra_mounts = [str(identifier_tmp_dir)]
295-
if str(Path(".").resolve()).startswith("/tmp"):
296-
extra_mounts.append(str(Path(".").resolve()))
295+
if str(Path.cwd()).startswith("/tmp"):
296+
extra_mounts.append(str(Path.cwd()))
297297

298298
if "_PYODIDE_EXTRA_MOUNTS" in env:
299299
oldmounts = env["_PYODIDE_EXTRA_MOUNTS"] + ":"
@@ -413,7 +413,7 @@ def build(options: Options, tmp_path: Path) -> None:
413413
# and not the repo code)
414414
test_command_prepared = prepare_command(
415415
build_options.test_command,
416-
project=Path(".").resolve(),
416+
project=Path.cwd(),
417417
package=build_options.package_dir.resolve(),
418418
)
419419

@@ -427,7 +427,7 @@ def build(options: Options, tmp_path: Path) -> None:
427427
)
428428
else:
429429
# There are no test sources. Run the tests in the project directory.
430-
test_cwd = Path(".").resolve()
430+
test_cwd = Path.cwd()
431431

432432
shell(test_command_prepared, cwd=test_cwd, env=virtualenv_env)
433433

@@ -437,7 +437,7 @@ def build(options: Options, tmp_path: Path) -> None:
437437
moved_wheel = move_file(repaired_wheel, output_wheel)
438438
if moved_wheel != output_wheel.resolve():
439439
log.warning(
440-
"{repaired_wheel} was moved to {moved_wheel} instead of {output_wheel}"
440+
f"{repaired_wheel} was moved to {moved_wheel} instead of {output_wheel}"
441441
)
442442
built_wheels.append(output_wheel)
443443

cibuildwheel/selector.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def __call__(self, build_id: str) -> bool:
5353
# Filter build selectors by python_requires if set
5454
if self.requires_python is not None:
5555
py_ver_str = build_id.split("-")[0]
56-
if py_ver_str.endswith("t"):
57-
py_ver_str = py_ver_str[:-1]
56+
py_ver_str = py_ver_str.removesuffix("t")
5857
major = int(py_ver_str[2])
5958
minor = int(py_ver_str[3:])
6059
version = Version(f"{major}.{minor}.99")

cibuildwheel/util/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def __init__(self, version_str: str) -> None:
151151
# Normalize by removing trailing zeros
152152
self.version_parts = self._remove_trailing_zeros(self.version_parts)
153153

154-
def _remove_trailing_zeros(self, parts: tuple[int, ...]) -> tuple[int, ...]:
154+
@staticmethod
155+
def _remove_trailing_zeros(parts: tuple[int, ...]) -> tuple[int, ...]:
155156
# Remove trailing zeros for accurate comparisons
156157
# without this, "3.0" would be considered greater than "3"
157158
while parts and parts[-1] == 0:

cibuildwheel/windows.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def build(options: Options, tmp_path: Path) -> None:
549549
# and not the repo code)
550550
test_command_prepared = prepare_command(
551551
build_options.test_command,
552-
project=Path(".").resolve(),
552+
project=Path.cwd(),
553553
package=options.globals.package_dir.resolve(),
554554
wheel=repaired_wheel,
555555
)
@@ -563,7 +563,7 @@ def build(options: Options, tmp_path: Path) -> None:
563563
)
564564
else:
565565
# There are no test sources. Run the tests in the project directory.
566-
test_cwd = Path(".").resolve()
566+
test_cwd = Path.cwd()
567567

568568
shell(test_command_prepared, cwd=test_cwd, env=virtualenv_env)
569569

@@ -573,7 +573,7 @@ def build(options: Options, tmp_path: Path) -> None:
573573
moved_wheel = move_file(repaired_wheel, output_wheel)
574574
if moved_wheel != output_wheel.resolve():
575575
log.warning(
576-
"{repaired_wheel} was moved to {moved_wheel} instead of {output_wheel}"
576+
f"{repaired_wheel} was moved to {moved_wheel} instead of {output_wheel}"
577577
)
578578
built_wheels.append(output_wheel)
579579

test/test_manylinuxXXXX_only.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ def test(manylinux_image, tmp_path):
9696
"CIBW_MANYLINUX_PYPY_AARCH64_IMAGE": manylinux_image,
9797
"CIBW_MANYLINUX_PYPY_I686_IMAGE": manylinux_image,
9898
}
99-
if manylinux_image in {"manylinux1"}:
99+
if manylinux_image == "manylinux1":
100100
# We don't have a manylinux1 image for PyPy & CPython 3.10 and above
101101
add_env["CIBW_SKIP"] = "pp* cp31*"
102-
if manylinux_image in {"manylinux2010"}:
102+
if manylinux_image == "manylinux2010":
103103
# We don't have a manylinux2010 image for PyPy 3.9+, CPython 3.11+
104104
add_env["CIBW_SKIP"] = "pp39* pp31* cp311* cp312* cp313*"
105-
if manylinux_image in {"manylinux_2_24"}:
105+
if manylinux_image == "manylinux_2_24":
106106
# We don't have a manylinux_2_24 image for PyPy 3.10+, CPython 3.12+
107107
add_env["CIBW_SKIP"] = "pp31* cp312* cp313*"
108108
if manylinux_image in {"manylinux_2_28", "manylinux_2_34"} and platform.machine() == "x86_64":
@@ -125,11 +125,11 @@ def test(manylinux_image, tmp_path):
125125
manylinux_versions=platform_tag_map.get(manylinux_image, [manylinux_image]),
126126
musllinux_versions=[],
127127
)
128-
if manylinux_image in {"manylinux1"}:
128+
if manylinux_image == "manylinux1":
129129
# remove PyPy & CPython 3.10 and above
130130
expected_wheels = [w for w in expected_wheels if "-pp" not in w and "-cp31" not in w]
131131

132-
if manylinux_image in {"manylinux2010"}:
132+
if manylinux_image == "manylinux2010":
133133
# remove PyPy 3.9+ & CPython 3.11
134134
expected_wheels = [
135135
w
@@ -141,7 +141,7 @@ def test(manylinux_image, tmp_path):
141141
and "-cp313" not in w
142142
]
143143

144-
if manylinux_image in {"manylinux_2_24"}:
144+
if manylinux_image == "manylinux_2_24":
145145
# remove PyPy 3.10+ & CPython 3.11 and above
146146
expected_wheels = [
147147
w

0 commit comments

Comments
 (0)