@@ -377,26 +377,80 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
377
377
),
378
378
)
379
379
380
- def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, override = False ):
381
- """Set the value in the config if the value is provided"""
382
- config .setdefault ("platforms" , {})
383
- if platform :
384
- if not override and config .get ("platforms" , {}).get (platform ):
385
- return
380
+ def _plat (* , name , arch_name , os_name , config_settings = [], env = {}):
381
+ return struct (
382
+ name = name ,
383
+ arch_name = arch_name ,
384
+ os_name = os_name ,
385
+ config_settings = config_settings ,
386
+ env = env ,
387
+ )
386
388
389
+ def _configure (config , * , override = False , ** kwargs ):
390
+ """Set the value in the config if the value is provided"""
391
+ env = kwargs .get ("env" )
392
+ if env :
387
393
for key in env :
388
394
if key not in _SUPPORTED_PEP508_KEYS :
389
395
fail ("Unsupported key in the PEP508 environment: {}" .format (key ))
390
396
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
- )
398
- else :
399
- config ["platforms" ].pop (platform )
397
+ for key , value in kwargs .items ():
398
+ if value and (override or key not in config ):
399
+ config [key ] = value
400
+
401
+ def build_config (
402
+ * ,
403
+ module_ctx ,
404
+ enable_pipstar ):
405
+ """Parse 'configure' and 'default' extension tags
406
+
407
+ Args:
408
+ module_ctx: {type}`module_ctx` module context.
409
+ enable_pipstar: {type}`bool` a flag to enable dropping Python dependency for
410
+ evaluation of the extension.
411
+
412
+ Returns:
413
+ A struct with the configuration.
414
+ """
415
+ defaults = {
416
+ "platforms" : {},
417
+ }
418
+ for mod in module_ctx .modules :
419
+ if not (mod .is_root or mod .name == "rules_python" ):
420
+ continue
421
+
422
+ for tag in mod .tags .default :
423
+ platform = tag .platform
424
+ if platform :
425
+ specific_config = defaults ["platforms" ].setdefault (platform , {})
426
+ _configure (
427
+ specific_config ,
428
+ arch_name = tag .arch_name ,
429
+ config_settings = tag .config_settings ,
430
+ env = tag .env ,
431
+ os_name = tag .os_name ,
432
+ name = platform .replace ("-" , "_" ).lower (),
433
+ override = mod .is_root ,
434
+ )
435
+
436
+ if platform and not (tag .arch_name or tag .config_settings or tag .env or tag .os_name ):
437
+ defaults ["platforms" ].pop (platform )
438
+
439
+ # TODO @aignas 2025-05-19: add more attr groups:
440
+ # * for AUTH - the default `netrc` usage could be configured through a common
441
+ # attribute.
442
+ # * for index/downloader config. This includes all of those attributes for
443
+ # overrides, etc. Index overrides per platform could be also used here.
444
+ # * for whl selection - selecting preferences of which `platform_tag`s we should use
445
+ # for what. We could also model the `cp313t` freethreaded as separate platforms.
446
+
447
+ return struct (
448
+ platforms = {
449
+ name : _plat (** values )
450
+ for name , values in defaults ["platforms" ].items ()
451
+ },
452
+ enable_pipstar = enable_pipstar ,
453
+ )
400
454
401
455
def parse_modules (
402
456
module_ctx ,
@@ -448,33 +502,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
448
502
srcs_exclude_glob = whl_mod .srcs_exclude_glob ,
449
503
)
450
504
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 )
505
+ config = build_config (module_ctx = module_ctx , enable_pipstar = enable_pipstar )
478
506
479
507
# TODO @aignas 2025-06-03: Merge override API with the builder?
480
508
_overriden_whl_set = {}
@@ -659,6 +687,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
659
687
k : dict (sorted (args .items ()))
660
688
for k , args in sorted (whl_libraries .items ())
661
689
},
690
+ config = config ,
662
691
)
663
692
664
693
def _pip_impl (module_ctx ):
0 commit comments