Skip to content

Commit bc3106a

Browse files
authored
fix: include Requires-Python info in printout (#1017)
1 parent b52698d commit bc3106a

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ repos:
5151
rev: v0.931
5252
hooks:
5353
- id: mypy
54+
name: mypy 3.6 on cibuildwheel/
5455
exclude: ^(bin|cibuildwheel/resources|docs)/.*py$
55-
args: ["--python-version=3.6", "--scripts-are-modules", "--show-error-codes"]
56+
args: ["--python-version=3.6", "--show-error-codes"]
5657
additional_dependencies: &mypy-dependencies
5758
- nox
5859
- packaging>=21.0
@@ -66,10 +67,15 @@ repos:
6667
- types-pyyaml
6768
- types-requests
6869
- bracex
70+
- dataclasses
6971
- id: mypy
7072
name: mypy 3.7+ on bin/
7173
files: ^((bin|docs)/.*py)$
72-
args: ["--python-version=3.7", "--scripts-are-modules", "--show-error-codes"]
74+
args: ["--python-version=3.7", "--show-error-codes"]
75+
additional_dependencies: *mypy-dependencies
76+
- id: mypy
77+
name: mypy 3.10
78+
args: ["--python-version=3.10", "--show-error-codes"]
7379
additional_dependencies: *mypy-dependencies
7480

7581
- repo: https://github.com/asottile/yesqa

cibuildwheel/util.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import dataclasses
23
import fnmatch
34
import itertools
45
import os
@@ -16,6 +17,7 @@
1617
from time import sleep
1718
from typing import (
1819
Any,
20+
ClassVar,
1921
Dict,
2022
Iterable,
2123
Iterator,
@@ -205,6 +207,8 @@ def selector_matches(patterns: str, string: str) -> bool:
205207
return any(fnmatch.fnmatch(string, pat) for pat in expanded_patterns)
206208

207209

210+
# Once we require Python 3.10+, we can add kw_only=True
211+
@dataclasses.dataclass
208212
class IdentifierSelector:
209213
"""
210214
This class holds a set of build/skip patterns. You call an instance with a
@@ -215,20 +219,12 @@ class IdentifierSelector:
215219
"""
216220

217221
# a pattern that skips prerelease versions, when include_prereleases is False.
218-
PRERELEASE_SKIP = ""
219-
220-
def __init__(
221-
self,
222-
*,
223-
build_config: str,
224-
skip_config: str,
225-
requires_python: Optional[SpecifierSet] = None,
226-
prerelease_pythons: bool = False,
227-
):
228-
self.build_config = build_config
229-
self.skip_config = skip_config
230-
self.requires_python = requires_python
231-
self.prerelease_pythons = prerelease_pythons
222+
PRERELEASE_SKIP: ClassVar[str] = ""
223+
224+
skip_config: str
225+
build_config: str
226+
requires_python: Optional[SpecifierSet] = None
227+
prerelease_pythons: bool = False
232228

233229
def __call__(self, build_id: str) -> bool:
234230
# Filter build selectors by python_requires if set
@@ -241,38 +237,25 @@ def __call__(self, build_id: str) -> bool:
241237
return False
242238

243239
# filter out the prerelease pythons if self.prerelease_pythons is False
244-
if not self.prerelease_pythons and selector_matches(
245-
BuildSelector.PRERELEASE_SKIP, build_id
246-
):
240+
if not self.prerelease_pythons and selector_matches(self.PRERELEASE_SKIP, build_id):
247241
return False
248242

249243
should_build = selector_matches(self.build_config, build_id)
250244
should_skip = selector_matches(self.skip_config, build_id)
251245

252246
return should_build and not should_skip
253247

254-
def __repr__(self) -> str:
255-
result = f"{self.__class__.__name__}(build_config={self.build_config!r}"
256-
257-
if self.skip_config:
258-
result += f", skip_config={self.skip_config!r}"
259-
if self.prerelease_pythons:
260-
result += ", prerelease_pythons=True"
261-
262-
result += ")"
263-
264-
return result
265-
266248

249+
@dataclasses.dataclass
267250
class BuildSelector(IdentifierSelector):
268251
pass
269252

270253

271254
# Note that requires-python is not needed for TestSelector, as you can't test
272255
# what you can't build.
256+
@dataclasses.dataclass
273257
class TestSelector(IdentifierSelector):
274-
def __init__(self, *, skip_config: str):
275-
super().__init__(build_config="*", skip_config=skip_config)
258+
build_config: str = "*"
276259

277260

278261
# Taken from https://stackoverflow.com/a/107717

0 commit comments

Comments
 (0)