chore: some cleanup from ruff --preview checks

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
Henry Schreiner
2025-02-28 16:38:15 -05:00
committed by Henry Schreiner
parent 2f62696400
commit 183a7c3f1d
13 changed files with 46 additions and 42 deletions
+1 -1
View File
@@ -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)
+3 -2
View File
@@ -5,6 +5,7 @@ from __future__ import annotations
import copy
import difflib
import logging
import operator
import tomllib
from collections.abc import Mapping, MutableMapping
from pathlib import Path
@@ -133,7 +134,7 @@ class PyPyVersions:
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:
@@ -160,7 +161,7 @@ class PyPyVersions:
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}!"
+1 -1
View File
@@ -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="""
+3 -3
View File
@@ -710,7 +710,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,
)
@@ -728,7 +728,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)
@@ -738,7 +738,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)
+14 -11
View File
@@ -73,7 +73,7 @@ class CommandLineArguments:
only=None,
config_file="",
output_dir=Path("wheelhouse"),
package_dir=Path("."),
package_dir=Path(),
print_build_identifiers=False,
debug_traceback=False,
enable=[],
@@ -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)
@@ -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:
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:
return f"{before} {after}"
@@ -630,8 +632,7 @@ class Options:
)
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
@@ -737,9 +738,9 @@ class Options:
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:
@@ -932,13 +933,15 @@ class Options:
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()
+5 -5
View File
@@ -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"] + ":"
@@ -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(),
)
@@ -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)
@@ -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)
+1 -2
View File
@@ -53,8 +53,7 @@ class BuildSelector:
# 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")
+2 -1
View File
@@ -151,7 +151,8 @@ class FlexibleVersion:
# 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:
+3 -3
View File
@@ -546,7 +546,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,
)
@@ -560,7 +560,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)
@@ -570,7 +570,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)
+6 -6
View File
@@ -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":
@@ -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
@@ -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
+3 -3
View File
@@ -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 = {
@@ -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}}
@@ -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}}
+2 -2
View File
@@ -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
):
@@ -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
):
+2 -2
View File
@@ -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")