@@ -380,24 +380,90 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
380
380
def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, override = False ):
381
381
"""Set the value in the config if the value is provided"""
382
382
config .setdefault ("platforms" , {})
383
- if platform :
383
+ if platform and ( os_name or arch_name or config_settings or env ) :
384
384
if not override and config .get ("platforms" , {}).get (platform ):
385
385
return
386
386
387
387
for key in env :
388
388
if key not in _SUPPORTED_PEP508_KEYS :
389
389
fail ("Unsupported key in the PEP508 environment: {}" .format (key ))
390
390
391
- config ["platforms" ][platform ] = struct (
392
- name = platform .replace ("-" , "_" ).lower (),
393
- os_name = os_name ,
394
- arch_name = arch_name ,
395
- config_settings = config_settings ,
396
- env = env ,
397
- )
391
+ config ["platforms" ].setdefault (platform , {})
392
+ for key , value in {
393
+ "arch_name" : arch_name ,
394
+ "config_settings" : config_settings ,
395
+ "env" : env ,
396
+ "name" : platform .replace ("-" , "_" ).lower (),
397
+ "os_name" : os_name ,
398
+ }.items ():
399
+ if not value :
400
+ continue
401
+
402
+ if not override and config .get (key ):
403
+ continue
404
+
405
+ config ["platforms" ][platform ][key ] = value
398
406
else :
399
407
config ["platforms" ].pop (platform )
400
408
409
+ def _plat (* , name , arch_name , os_name , config_settings = [], env = {}):
410
+ return struct (
411
+ name = name ,
412
+ arch_name = arch_name ,
413
+ os_name = os_name ,
414
+ config_settings = config_settings ,
415
+ env = env ,
416
+ )
417
+
418
+ def build_config (
419
+ * ,
420
+ module_ctx ,
421
+ enable_pipstar ):
422
+ """Parse 'configure' and 'default' extension tags
423
+
424
+ Args:
425
+ module_ctx: {type}`module_ctx` module context.
426
+ enable_pipstar: {type}`bool` a flag to enable dropping Python dependency for
427
+ evaluation of the extension.
428
+
429
+ Returns:
430
+ A struct with the configuration.
431
+ """
432
+ defaults = {
433
+ "platforms" : {},
434
+ }
435
+ for mod in module_ctx .modules :
436
+ if not (mod .is_root or mod .name == "rules_python" ):
437
+ continue
438
+
439
+ platform = None
440
+ for tag in mod .tags .default :
441
+ platform = tag .platform or platform
442
+ _configure (
443
+ defaults ,
444
+ arch_name = tag .arch_name ,
445
+ config_settings = tag .config_settings ,
446
+ env = tag .env ,
447
+ os_name = tag .os_name ,
448
+ platform = platform ,
449
+ override = mod .is_root ,
450
+ # TODO @aignas 2025-05-19: add more attr groups:
451
+ # * for AUTH - the default `netrc` usage could be configured through a common
452
+ # attribute.
453
+ # * for index/downloader config. This includes all of those attributes for
454
+ # overrides, etc. Index overrides per platform could be also used here.
455
+ # * for whl selection - selecting preferences of which `platform_tag`s we should use
456
+ # for what. We could also model the `cp313t` freethreaded as separate platforms.
457
+ )
458
+
459
+ return struct (
460
+ platforms = {
461
+ name : _plat (** values )
462
+ for name , values in defaults ["platforms" ].items ()
463
+ },
464
+ enable_pipstar = enable_pipstar ,
465
+ )
466
+
401
467
def parse_modules (
402
468
module_ctx ,
403
469
_fail = fail ,
@@ -448,33 +514,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
448
514
srcs_exclude_glob = whl_mod .srcs_exclude_glob ,
449
515
)
450
516
451
- defaults = {
452
- "enable_pipstar" : enable_pipstar ,
453
- "platforms" : {},
454
- }
455
- for mod in module_ctx .modules :
456
- if not (mod .is_root or mod .name == "rules_python" ):
457
- continue
458
-
459
- for tag in mod .tags .default :
460
- _configure (
461
- defaults ,
462
- arch_name = tag .arch_name ,
463
- config_settings = tag .config_settings ,
464
- env = tag .env ,
465
- os_name = tag .os_name ,
466
- platform = tag .platform ,
467
- override = mod .is_root ,
468
- # TODO @aignas 2025-05-19: add more attr groups:
469
- # * for AUTH - the default `netrc` usage could be configured through a common
470
- # attribute.
471
- # * for index/downloader config. This includes all of those attributes for
472
- # overrides, etc. Index overrides per platform could be also used here.
473
- # * for whl selection - selecting preferences of which `platform_tag`s we should use
474
- # for what. We could also model the `cp313t` freethreaded as separate platforms.
475
- )
476
-
477
- config = struct (** defaults )
517
+ config = build_config (module_ctx = module_ctx , enable_pipstar = enable_pipstar )
478
518
479
519
# TODO @aignas 2025-06-03: Merge override API with the builder?
480
520
_overriden_whl_set = {}
@@ -651,6 +691,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
651
691
k : dict (sorted (args .items ()))
652
692
for k , args in sorted (whl_libraries .items ())
653
693
},
694
+ config = config ,
654
695
)
655
696
656
697
def _pip_impl (module_ctx ):
0 commit comments