11import contextlib
2+ import dataclasses
23import fnmatch
34import itertools
45import os
1617from time import sleep
1718from 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
208212class 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
267250class 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
273257class 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