Refactor class hierarchy
Removes unnecessary overlap in functionality
This commit is contained in:
@@ -387,7 +387,7 @@ class Options:
|
|||||||
requires_python=requires_python,
|
requires_python=requires_python,
|
||||||
prerelease_pythons=prerelease_pythons,
|
prerelease_pythons=prerelease_pythons,
|
||||||
)
|
)
|
||||||
test_selector = TestSelector(skip_config=test_skip, prerelease_pythons=prerelease_pythons)
|
test_selector = TestSelector(skip_config=test_skip)
|
||||||
|
|
||||||
archs_config_str = args.archs or self.reader.get("archs", sep=" ")
|
archs_config_str = args.archs or self.reader.get("archs", sep=" ")
|
||||||
architectures = Architecture.parse_config(archs_config_str, platform=self.platform)
|
architectures = Architecture.parse_config(archs_config_str, platform=self.platform)
|
||||||
|
|||||||
+14
-14
@@ -234,21 +234,20 @@ def selector_matches(patterns: str, string: str) -> bool:
|
|||||||
|
|
||||||
# Once we require Python 3.10+, we can add kw_only=True
|
# Once we require Python 3.10+, we can add kw_only=True
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class IdentifierSelector:
|
class BuildSelector:
|
||||||
"""
|
"""
|
||||||
This class holds a set of build/skip patterns. You call an instance with a
|
This class holds a set of build/skip patterns. You call an instance with a
|
||||||
build identifier, and it returns True if that identifier should be
|
build identifier, and it returns True if that identifier should be
|
||||||
included. Only call this on valid identifiers, ones that have at least 2
|
included. Only call this on valid identifiers, ones that have at least 2
|
||||||
numeric digits before the first dash. If a pre-release version X.Y is present,
|
numeric digits before the first dash.
|
||||||
you can filter it with prerelease="XY".
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
build_config: str
|
||||||
|
skip_config: str
|
||||||
|
requires_python: Optional[SpecifierSet] = None
|
||||||
|
|
||||||
# a pattern that skips prerelease versions, when include_prereleases is False.
|
# a pattern that skips prerelease versions, when include_prereleases is False.
|
||||||
PRERELEASE_SKIP: ClassVar[str] = "cp311-*"
|
PRERELEASE_SKIP: ClassVar[str] = "cp311-*"
|
||||||
|
|
||||||
skip_config: str
|
|
||||||
build_config: str
|
|
||||||
requires_python: Optional[SpecifierSet] = None
|
|
||||||
prerelease_pythons: bool = False
|
prerelease_pythons: bool = False
|
||||||
|
|
||||||
def __call__(self, build_id: str) -> bool:
|
def __call__(self, build_id: str) -> bool:
|
||||||
@@ -272,15 +271,16 @@ class IdentifierSelector:
|
|||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class BuildSelector(IdentifierSelector):
|
class TestSelector:
|
||||||
pass
|
"""
|
||||||
|
A build selector that can only skip tests according to a skip pattern.
|
||||||
|
"""
|
||||||
|
|
||||||
|
skip_config: str
|
||||||
|
|
||||||
# Note that requires-python is not needed for TestSelector, as you can't test
|
def __call__(self, build_id: str) -> bool:
|
||||||
# what you can't build.
|
should_skip = selector_matches(self.skip_config, build_id)
|
||||||
@dataclasses.dataclass
|
return not should_skip
|
||||||
class TestSelector(IdentifierSelector):
|
|
||||||
build_config: str = "*"
|
|
||||||
|
|
||||||
|
|
||||||
# Taken from https://stackoverflow.com/a/107717
|
# Taken from https://stackoverflow.com/a/107717
|
||||||
|
|||||||
@@ -136,3 +136,14 @@ def test_build_limited_python_patch():
|
|||||||
|
|
||||||
assert build_selector("cp36-manylinux_x86_64")
|
assert build_selector("cp36-manylinux_x86_64")
|
||||||
assert build_selector("cp37-manylinux_x86_64")
|
assert build_selector("cp37-manylinux_x86_64")
|
||||||
|
|
||||||
|
|
||||||
|
def test_testing_selector():
|
||||||
|
# local import to avoid pytest trying to collect this as a test class!
|
||||||
|
from cibuildwheel.util import TestSelector
|
||||||
|
|
||||||
|
test_selector = TestSelector(skip_config="cp36-*")
|
||||||
|
|
||||||
|
assert not test_selector("cp36-win_amd64")
|
||||||
|
assert test_selector("cp37-manylinux_x86_64")
|
||||||
|
assert test_selector("cp311-manylinux_x86_64")
|
||||||
|
|||||||
Reference in New Issue
Block a user