11
11
import time
12
12
import traceback
13
13
import typing
14
- from collections .abc import Generator , Iterable , Sequence , Set
14
+ from collections .abc import Generator , Iterable , Sequence
15
15
from pathlib import Path
16
16
from tempfile import mkdtemp
17
- from typing import Any , Protocol , TextIO , assert_never
17
+ from typing import Any , TextIO
18
18
19
19
import cibuildwheel
20
- import cibuildwheel .linux
21
- import cibuildwheel .macos
22
- import cibuildwheel .pyodide
23
20
import cibuildwheel .util
24
- import cibuildwheel .windows
25
21
from cibuildwheel import errors
26
22
from cibuildwheel .architecture import Architecture , allowed_architectures_check
27
23
from cibuildwheel .ci import CIProvider , detect_ci_provider , fix_ansi_codes_for_github_actions
28
24
from cibuildwheel .logger import log
29
25
from cibuildwheel .options import CommandLineArguments , Options , compute_options
30
- from cibuildwheel .selector import BuildSelector , EnableGroup
31
- from cibuildwheel .typing import PLATFORMS , GenericPythonConfiguration , PlatformName
26
+ from cibuildwheel .platforms import ALL_PLATFORM_MODULES , get_build_identifiers , get_platform_module
27
+ from cibuildwheel .selector import BuildSelector , EnableGroup , selector_matches
28
+ from cibuildwheel .typing import PLATFORMS , PlatformName
32
29
from cibuildwheel .util .file import CIBW_CACHE_PATH
33
30
from cibuildwheel .util .helpers import strtobool
34
31
@@ -284,28 +281,6 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
284
281
return _compute_platform_auto ()
285
282
286
283
287
- class PlatformModule (Protocol ):
288
- # note that as per PEP544, the self argument is ignored when the protocol
289
- # is applied to a module
290
- def get_python_configurations (
291
- self , build_selector : BuildSelector , architectures : Set [Architecture ]
292
- ) -> Sequence [GenericPythonConfiguration ]: ...
293
-
294
- def build (self , options : Options , tmp_path : Path ) -> None : ...
295
-
296
-
297
- def get_platform_module (platform : PlatformName ) -> PlatformModule :
298
- if platform == "linux" :
299
- return cibuildwheel .linux
300
- if platform == "windows" :
301
- return cibuildwheel .windows
302
- if platform == "macos" :
303
- return cibuildwheel .macos
304
- if platform == "pyodide" :
305
- return cibuildwheel .pyodide
306
- assert_never (platform )
307
-
308
-
309
284
@contextlib .contextmanager
310
285
def print_new_wheels (msg : str , output_dir : Path ) -> Generator [None , None , None ]:
311
286
"""
@@ -445,15 +420,6 @@ def print_preamble(platform: str, options: Options, identifiers: Sequence[str])
445
420
print ("Here we go!\n " )
446
421
447
422
448
- def get_build_identifiers (
449
- platform_module : PlatformModule ,
450
- build_selector : BuildSelector ,
451
- architectures : Set [Architecture ],
452
- ) -> list [str ]:
453
- python_configurations = platform_module .get_python_configurations (build_selector , architectures )
454
- return [config .identifier for config in python_configurations ]
455
-
456
-
457
423
def detect_warnings (* , options : Options , identifiers : Iterable [str ]) -> list [str ]:
458
424
warnings = []
459
425
@@ -479,6 +445,48 @@ def detect_warnings(*, options: Options, identifiers: Iterable[str]) -> list[str
479
445
)
480
446
raise errors .ConfigurationError (msg )
481
447
448
+ build_selector = options .globals .build_selector
449
+ test_selector = options .globals .test_selector
450
+
451
+ warnings += check_for_invalid_selectors ("build" , build_selector .build_config , error = True )
452
+ warnings += check_for_invalid_selectors ("skip" , build_selector .skip_config )
453
+ warnings += check_for_invalid_selectors ("test_skip" , test_selector .skip_config )
454
+
455
+ return warnings
456
+
457
+
458
+ def check_for_invalid_selectors (
459
+ selector_name : str , selector_value : str , * , error : bool = False
460
+ ) -> list [str ]:
461
+ warnings = []
462
+
463
+ all_valid_identifiers = [
464
+ identifier
465
+ for name , module in ALL_PLATFORM_MODULES .items ()
466
+ for identifier in get_build_identifiers (
467
+ platform_module = module ,
468
+ architectures = Architecture .all_archs (name ),
469
+ build_selector = BuildSelector (build_config = "*" , skip_config = "" ),
470
+ )
471
+ ]
472
+
473
+ for selector in selector_value .split ():
474
+ if not any (selector_matches (selector , i ) for i in all_valid_identifiers ):
475
+ msg = f"Invalid `{ selector_name } ` selector: { selector !r} . "
476
+ error_type : type = errors .ConfigurationError
477
+
478
+ if "p2" in selector or "p35" in selector :
479
+ msg = f"cibuildwheel 3.x no longer supports Python < 3.8. Please use the 1.x series or update `{ selector_name } `"
480
+ error_type = errors .DeprecationError
481
+ if "p36" in selector or "p37" in selector :
482
+ msg = f"cibuildwheel 3.x no longer supports Python < 3.8. Please use the 2.x series or update `{ selector_name } `"
483
+ error_type = errors .DeprecationError
484
+
485
+ if error :
486
+ raise error_type (msg )
487
+
488
+ warnings .append (msg )
489
+
482
490
return warnings
483
491
484
492
0 commit comments