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: enforce ruff PERF rules #2313

Open
wants to merge 4 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
3 changes: 1 addition & 2 deletions cibuildwheel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ def format_table(self, table: SettingTable) -> str:
if isinstance(v, str):
assignments.append((k, v))
elif isinstance(v, Sequence):
for inner_v in v:
assignments.append((k, str(inner_v)))
assignments.extend((k, str(inner_v)) for inner_v in v)
else:
assignments.append((k, str(v)))

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ extend-select = [
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"G", # flake8-logging-format
"PERF", # Perflint
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
Expand Down
31 changes: 21 additions & 10 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
This file is added to the PYTHONPATH in the test runner at bin/run_test.py.
"""

import functools
import os
import platform as pm
import subprocess
import sys
from collections.abc import Mapping, Sequence
from collections.abc import Callable, Generator, Mapping, Sequence
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any, Final
from typing import Any, Final, ParamSpec, TypeVar

import pytest

Expand Down Expand Up @@ -151,6 +152,19 @@ def _floor_macosx(*args: str) -> str:
return max(args, key=lambda x: tuple(map(int, x.split("."))))


P = ParamSpec("P")
R = TypeVar("R")


def _listify(func: Callable[P, Generator[R, None, None]]) -> Callable[P, list[R]]:
@functools.wraps(func)
def listify_return(*args: P.args, **kwargs: P.kwargs) -> list[R]:
return list(func(*args, **kwargs))

return listify_return


@_listify
def expected_wheels(
package_name: str,
package_version: str,
Expand All @@ -162,9 +176,9 @@ def expected_wheels(
include_universal2: bool = False,
single_python: bool = False,
single_arch: bool = False,
) -> list[str]:
) -> Generator[str, None, None]:
"""
Returns a list of expected wheels from a run of cibuildwheel.
Returns the expected wheels from a run of cibuildwheel.
"""
# per PEP 425 (https://www.python.org/dev/peps/pep-0425/), wheel files shall have name of the form
# {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl
Expand Down Expand Up @@ -240,13 +254,12 @@ def expected_wheels(
)
]

wheels = []

if platform == "pyodide":
assert len(python_abi_tags) == 1
python_abi_tag = python_abi_tags[0]
platform_tag = "pyodide_2024_0_wasm32"
return [f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"]
yield f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"
return

for python_abi_tag in python_abi_tags:
platform_tags = []
Expand Down Expand Up @@ -318,9 +331,7 @@ def expected_wheels(
raise Exception(msg)

for platform_tag in platform_tags:
wheels.append(f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl")

return wheels
yield f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"


def get_macos_version() -> tuple[int, int]:
Expand Down
Loading