Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup for 3.11 #2276

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
hooks:
- id: mypy
name: mypy 3.11 on cibuildwheel/
exclude: ^cibuildwheel/resources/.*py|bin/generate_schema.py$
exclude: ^cibuildwheel/resources/.*py$
args: ["--python-version=3.11"]
additional_dependencies: &mypy-dependencies
- bracex
Expand Down
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
35 changes: 12 additions & 23 deletions cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import annotations

import functools
import platform as platform_module
import re
import shutil
import subprocess
import sys
from collections.abc import Set
from enum import Enum
from enum import StrEnum, auto
from typing import Final, Literal, assert_never

from .typing import PlatformName
Expand Down Expand Up @@ -39,38 +38,28 @@ def _check_aarch32_el0() -> bool:
return check.returncode == 0 and check.stdout.startswith("armv")


@functools.total_ordering
class Architecture(Enum):
value: str

class Architecture(StrEnum):
# mac/linux archs
x86_64 = "x86_64"
x86_64 = auto()

# linux archs
i686 = "i686"
aarch64 = "aarch64"
ppc64le = "ppc64le"
s390x = "s390x"
armv7l = "armv7l"
i686 = auto()
aarch64 = auto()
ppc64le = auto()
s390x = auto()
armv7l = auto()

# mac archs
universal2 = "universal2"
arm64 = "arm64"
universal2 = auto()
arm64 = auto()

# windows archs
x86 = "x86"
x86 = auto()
AMD64 = "AMD64"
ARM64 = "ARM64"

# WebAssembly
wasm32 = "wasm32"

# Allow this to be sorted
def __lt__(self, other: Architecture) -> bool:
return self.value < other.value

def __str__(self) -> str:
return self.name
wasm32 = auto()

@staticmethod
def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
Expand Down
16 changes: 8 additions & 8 deletions cibuildwheel/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import typing
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Literal
from typing import Literal, get_args

from .logger import log
from .util.helpers import parse_key_value_string
Expand All @@ -21,8 +21,9 @@ class BuildFrontendConfig:
def from_config_string(config_string: str) -> BuildFrontendConfig:
config_dict = parse_key_value_string(config_string, ["name"], ["args"])
name = " ".join(config_dict["name"])
if name not in {"pip", "build", "build[uv]"}:
msg = f"Unrecognised build frontend {name!r}, only 'pip', 'build', and 'build[uv]' are supported"
if name not in get_args(BuildFrontendName):
names = ", ".join(repr(n) for n in get_args(BuildFrontendName))
msg = f"Unrecognised build frontend {name!r}, must be one of {names}"
raise ValueError(msg)

name = typing.cast(BuildFrontendName, name)
Expand All @@ -44,22 +45,21 @@ def _get_verbosity_flags(level: int, frontend: BuildFrontendName) -> list[str]:
if level < 0:
return ["-" + -level * "q"]
elif not 0 <= level < 2:
msg = f"build_verbosity {level} is not supported for build frontend. Ignoring."
msg = f"build_verbosity {level} is not supported for {frontend} frontend. Ignoring."
log.warning(msg)
return []


def _split_config_settings(config_settings: str, frontend: BuildFrontendName) -> list[str]:
def _split_config_settings(config_settings: str) -> list[str]:
config_settings_list = shlex.split(config_settings)
s = "s" if frontend == "pip" else ""
return [f"--config-setting{s}={setting}" for setting in config_settings_list]
return [f"-C{setting}" for setting in config_settings_list]


def get_build_frontend_extra_flags(
build_frontend: BuildFrontendConfig, verbosity_level: int, config_settings: str
) -> list[str]:
return [
*_split_config_settings(config_settings, build_frontend.name),
*_split_config_settings(config_settings),
*build_frontend.args,
*_get_verbosity_flags(verbosity_level, build_frontend.name),
]
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 @@
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 @@

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 @@
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 @@
)
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 @@
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 @@

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
2 changes: 1 addition & 1 deletion cibuildwheel/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


PlatformName = Literal["linux", "macos", "windows", "pyodide"]
PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows", "pyodide"}
PLATFORMS: Final[frozenset[PlatformName]] = frozenset(typing.get_args(PlatformName))


class GenericPythonConfiguration(Protocol):
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
Loading
Loading