Skip to content

Commit

Permalink
chore: some cleanup from ruff --preview checks
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Feb 12, 2025
1 parent 9a44319 commit 2c489f7
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 42 deletions.
2 changes: 1 addition & 1 deletion bin/update_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Image:

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

Expand Down
5 changes: 3 additions & 2 deletions bin/update_pythons.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import copy
import difflib
import logging
import operator
import tomllib
from collections.abc import Mapping, MutableMapping
from pathlib import Path
Expand Down Expand Up @@ -133,7 +134,7 @@ def get_arch_file(self, release: Mapping[str, Any]) -> str:

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

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

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

if not releases:
msg = f"PyPy macOS {self.arch} not found for {spec}!"
Expand Down
2 changes: 1 addition & 1 deletion cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def main_inner(global_options: GlobalOptions) -> None:
parser.add_argument(
"package_dir",
metavar="PACKAGE",
default=Path("."),
default=Path(),
type=Path,
nargs="?",
help="""
Expand Down
6 changes: 3 additions & 3 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def build(options: Options, tmp_path: Path) -> None:
# and not the repo code)
test_command_prepared = prepare_command(
build_options.test_command,
project=Path(".").resolve(),
project=Path.cwd(),
package=build_options.package_dir.resolve(),
wheel=repaired_wheel,
)
Expand All @@ -734,7 +734,7 @@ def build(options: Options, tmp_path: Path) -> None:
)
else:
# There are no test sources. Run the tests in the project directory.
test_cwd = Path(".").resolve()
test_cwd = Path.cwd()

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

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

Expand Down
25 changes: 14 additions & 11 deletions cibuildwheel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def defaults() -> CommandLineArguments:
only=None,
config_file="",
output_dir=Path("wheelhouse"),
package_dir=Path("."),
package_dir=Path(),
print_build_identifiers=False,
debug_traceback=False,
enable=[],
Expand Down Expand Up @@ -184,7 +184,7 @@ class ListFormat(OptionFormat):

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

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

def format_table(self, table: SettingTable) -> str:
@staticmethod
def format_table(table: SettingTable) -> str:

Check warning on line 269 in cibuildwheel/options.py

View workflow job for this annotation

GitHub Actions / Linters (mypy, flake8, etc.)

W0221

Number of parameters was 2 in 'OptionFormat.format_table' and is now 1 in overriding 'EnvironmentFormat.format_table' method
return " ".join(f'{k}="{v}"' for k, v in table.items())

def merge_values(self, before: str, after: str) -> str:
@staticmethod
def merge_values(before: str, after: str) -> str:

Check warning on line 273 in cibuildwheel/options.py

View workflow job for this annotation

GitHub Actions / Linters (mypy, flake8, etc.)

W0221

Number of parameters was 3 in 'OptionFormat.merge_values' and is now 2 in overriding 'EnvironmentFormat.merge_values' method
return f"{before} {after}"


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

if dependency_versions == "pinned":
dependency_constraints: None | (
DependencyConstraints
) = DependencyConstraints.with_defaults()
dependency_constraints: DependencyConstraints | None = (
DependencyConstraints.with_defaults()
)
elif dependency_versions == "latest":
dependency_constraints = None
else:
Expand Down Expand Up @@ -932,13 +933,15 @@ def option_summary(

return result

def indent_if_multiline(self, value: str, indent: str) -> str:
@staticmethod
def indent_if_multiline(value: str, indent: str) -> str:
if "\n" in value:
return "\n" + textwrap.indent(value.strip(), indent)
else:
return value

def option_summary_value(self, option_value: Any) -> str:
@staticmethod
def option_summary_value(option_value: Any) -> str:
if hasattr(option_value, "options_summary"):
option_value = option_value.options_summary()

Expand Down
10 changes: 5 additions & 5 deletions cibuildwheel/pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ def build(options: Options, tmp_path: Path) -> None:
# directory.
oldmounts = ""
extra_mounts = [str(identifier_tmp_dir)]
if str(Path(".").resolve()).startswith("/tmp"):
extra_mounts.append(str(Path(".").resolve()))
if str(Path.cwd()).startswith("/tmp"):
extra_mounts.append(str(Path.cwd()))

if "_PYODIDE_EXTRA_MOUNTS" in env:
oldmounts = env["_PYODIDE_EXTRA_MOUNTS"] + ":"
Expand Down Expand Up @@ -413,7 +413,7 @@ def build(options: Options, tmp_path: Path) -> None:
# and not the repo code)
test_command_prepared = prepare_command(
build_options.test_command,
project=Path(".").resolve(),
project=Path.cwd(),
package=build_options.package_dir.resolve(),
)

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

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

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

Expand Down
3 changes: 1 addition & 2 deletions cibuildwheel/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def __call__(self, build_id: str) -> bool:
# Filter build selectors by python_requires if set
if self.requires_python is not None:
py_ver_str = build_id.split("-")[0]
if py_ver_str.endswith("t"):
py_ver_str = py_ver_str[:-1]
py_ver_str = py_ver_str.removesuffix("t")
major = int(py_ver_str[2])
minor = int(py_ver_str[3:])
version = Version(f"{major}.{minor}.99")
Expand Down
3 changes: 2 additions & 1 deletion cibuildwheel/util/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def __init__(self, version_str: str) -> None:
# Normalize by removing trailing zeros
self.version_parts = self._remove_trailing_zeros(self.version_parts)

def _remove_trailing_zeros(self, parts: tuple[int, ...]) -> tuple[int, ...]:
@staticmethod
def _remove_trailing_zeros(parts: tuple[int, ...]) -> tuple[int, ...]:
# Remove trailing zeros for accurate comparisons
# without this, "3.0" would be considered greater than "3"
while parts and parts[-1] == 0:
Expand Down
6 changes: 3 additions & 3 deletions cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def build(options: Options, tmp_path: Path) -> None:
# and not the repo code)
test_command_prepared = prepare_command(
build_options.test_command,
project=Path(".").resolve(),
project=Path.cwd(),
package=options.globals.package_dir.resolve(),
wheel=repaired_wheel,
)
Expand All @@ -563,7 +563,7 @@ def build(options: Options, tmp_path: Path) -> None:
)
else:
# There are no test sources. Run the tests in the project directory.
test_cwd = Path(".").resolve()
test_cwd = Path.cwd()

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

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

Expand Down
12 changes: 6 additions & 6 deletions test/test_manylinuxXXXX_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def test(manylinux_image, tmp_path):
"CIBW_MANYLINUX_PYPY_AARCH64_IMAGE": manylinux_image,
"CIBW_MANYLINUX_PYPY_I686_IMAGE": manylinux_image,
}
if manylinux_image in {"manylinux1"}:
if manylinux_image == "manylinux1":
# We don't have a manylinux1 image for PyPy & CPython 3.10 and above
add_env["CIBW_SKIP"] = "pp* cp31*"
if manylinux_image in {"manylinux2010"}:
if manylinux_image == "manylinux2010":
# We don't have a manylinux2010 image for PyPy 3.9+, CPython 3.11+
add_env["CIBW_SKIP"] = "pp39* pp31* cp311* cp312* cp313*"
if manylinux_image in {"manylinux_2_24"}:
if manylinux_image == "manylinux_2_24":
# We don't have a manylinux_2_24 image for PyPy 3.10+, CPython 3.12+
add_env["CIBW_SKIP"] = "pp31* cp312* cp313*"
if manylinux_image in {"manylinux_2_28", "manylinux_2_34"} and platform.machine() == "x86_64":
Expand All @@ -125,11 +125,11 @@ def test(manylinux_image, tmp_path):
manylinux_versions=platform_tag_map.get(manylinux_image, [manylinux_image]),
musllinux_versions=[],
)
if manylinux_image in {"manylinux1"}:
if manylinux_image == "manylinux1":
# remove PyPy & CPython 3.10 and above
expected_wheels = [w for w in expected_wheels if "-pp" not in w and "-cp31" not in w]

if manylinux_image in {"manylinux2010"}:
if manylinux_image == "manylinux2010":
# remove PyPy 3.9+ & CPython 3.11
expected_wheels = [
w
Expand All @@ -141,7 +141,7 @@ def test(manylinux_image, tmp_path):
and "-cp313" not in w
]

if manylinux_image in {"manylinux_2_24"}:
if manylinux_image == "manylinux_2_24":
# remove PyPy 3.10+ & CPython 3.11 and above
expected_wheels = [
w
Expand Down
6 changes: 3 additions & 3 deletions unit_test/architecture_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def platform_machine(request, monkeypatch):


def test_arch_auto(platform_machine):
platform_name, machine_name = platform_machine
_, machine_name = platform_machine

arch_set = Architecture.auto_archs("linux")
expected = {
Expand All @@ -55,7 +55,7 @@ def test_arch_auto(platform_machine):


def test_arch_auto64(platform_machine):
platform_name, machine_name = platform_machine
_, machine_name = platform_machine

arch_set = Architecture.parse_config("auto64", "linux")
expected = {"32": set(), "64": {Architecture.x86_64}, "arm": {Architecture.aarch64}}
Expand All @@ -71,7 +71,7 @@ def test_arch_auto64(platform_machine):


def test_arch_auto32(platform_machine):
platform_name, machine_name = platform_machine
_, machine_name = platform_machine

arch_set = Architecture.parse_config("auto32", "linux")
expected = {"32": {Architecture.i686}, "64": {Architecture.i686}, "arm": {Architecture.armv7l}}
Expand Down
4 changes: 2 additions & 2 deletions unit_test/oci_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def test_local_image(
container_engine: OCIContainerEngineConfig, platform: OCIPlatform, tmp_path: Path
) -> None:
if (
detect_ci_provider() in {CIProvider.travis_ci}
detect_ci_provider() == CIProvider.travis_ci
and pm != "x86_64"
and platform != DEFAULT_OCI_PLATFORM
):
Expand Down Expand Up @@ -584,7 +584,7 @@ def test_local_image(
@pytest.mark.parametrize("platform", list(OCIPlatform))
def test_multiarch_image(container_engine, platform):
if (
detect_ci_provider() in {CIProvider.travis_ci}
detect_ci_provider() == CIProvider.travis_ci
and pm != "x86_64"
and platform != DEFAULT_OCI_PLATFORM
):
Expand Down
4 changes: 2 additions & 2 deletions unit_test/projectfiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ def test_read_dep_groups():


def test_dep_group_no_file_error():
with pytest.raises(FileNotFoundError, match="pyproject.toml"):
with pytest.raises(FileNotFoundError, match=r"pyproject\.toml"):
resolve_dependency_groups(None, "test")


def test_dep_group_no_section_error():
with pytest.raises(KeyError, match="pyproject.toml"):
with pytest.raises(KeyError, match=r"pyproject\.toml"):
resolve_dependency_groups({}, "test")

0 comments on commit 2c489f7

Please sign in to comment.