@@ -379,24 +379,88 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
379379def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, override = False ):
380380 """Set the value in the config if the value is provided"""
381381 config .setdefault ("platforms" , {})
382- if platform :
382+ if platform and ( os_name or arch_name or config_settings or env ) :
383383 if not override and config .get ("platforms" , {}).get (platform ):
384384 return
385385
386386 for key in env :
387387 if key not in _SUPPORTED_PEP508_KEYS :
388388 fail ("Unsupported key in the PEP508 environment: {}" .format (key ))
389389
390- config ["platforms" ][platform ] = struct (
391- name = platform .replace ("-" , "_" ).lower (),
392- os_name = os_name ,
393- arch_name = arch_name ,
394- config_settings = config_settings ,
395- env = env ,
396- )
397- else :
390+ config ["platforms" ].setdefault (platform , {})
391+ for key , value in {
392+ "arch_name" : arch_name ,
393+ "config_settings" : config_settings ,
394+ "env" : env ,
395+ "name" : platform .replace ("-" , "_" ).lower (),
396+ "os_name" : os_name ,
397+ }.items ():
398+ if not value :
399+ continue
400+
401+ if not override and config .get (key ):
402+ continue
403+
404+ config ["platforms" ][platform ][key ] = value
405+ elif platform and override :
398406 config ["platforms" ].pop (platform )
399407
408+ def _plat (* , name , arch_name , os_name , config_settings = [], env = {}):
409+ return struct (
410+ name = name ,
411+ arch_name = arch_name ,
412+ os_name = os_name ,
413+ config_settings = config_settings ,
414+ env = env ,
415+ )
416+
417+ def build_config (
418+ * ,
419+ module_ctx ,
420+ enable_pipstar ):
421+ """Parse 'configure' and 'default' extension tags
422+
423+ Args:
424+ module_ctx: {type}`module_ctx` module context.
425+ enable_pipstar: {type}`bool` a flag to enable dropping Python dependency for
426+ evaluation of the extension.
427+
428+ Returns:
429+ A struct with the configuration.
430+ """
431+ defaults = {
432+ "platforms" : {},
433+ }
434+ for mod in module_ctx .modules :
435+ if not (mod .is_root or mod .name == "rules_python" ):
436+ continue
437+
438+ for tag in mod .tags .default :
439+ _configure (
440+ defaults ,
441+ arch_name = tag .arch_name ,
442+ config_settings = tag .config_settings ,
443+ env = tag .env ,
444+ os_name = tag .os_name ,
445+ platform = tag .platform ,
446+ override = mod .is_root ,
447+ # TODO @aignas 2025-05-19: add more attr groups:
448+ # * for AUTH - the default `netrc` usage could be configured through a common
449+ # attribute.
450+ # * for index/downloader config. This includes all of those attributes for
451+ # overrides, etc. Index overrides per platform could be also used here.
452+ # * for whl selection - selecting preferences of which `platform_tag`s we should use
453+ # for what. We could also model the `cp313t` freethreaded as separate platforms.
454+ )
455+
456+ return struct (
457+ platforms = {
458+ name : _plat (** values )
459+ for name , values in defaults ["platforms" ].items ()
460+ },
461+ enable_pipstar = enable_pipstar ,
462+ )
463+
400464def parse_modules (
401465 module_ctx ,
402466 _fail = fail ,
@@ -447,33 +511,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
447511 srcs_exclude_glob = whl_mod .srcs_exclude_glob ,
448512 )
449513
450- defaults = {
451- "enable_pipstar" : enable_pipstar ,
452- "platforms" : {},
453- }
454- for mod in module_ctx .modules :
455- if not (mod .is_root or mod .name == "rules_python" ):
456- continue
457-
458- for tag in mod .tags .default :
459- _configure (
460- defaults ,
461- arch_name = tag .arch_name ,
462- config_settings = tag .config_settings ,
463- env = tag .env ,
464- os_name = tag .os_name ,
465- platform = tag .platform ,
466- override = mod .is_root ,
467- # TODO @aignas 2025-05-19: add more attr groups:
468- # * for AUTH - the default `netrc` usage could be configured through a common
469- # attribute.
470- # * for index/downloader config. This includes all of those attributes for
471- # overrides, etc. Index overrides per platform could be also used here.
472- # * for whl selection - selecting preferences of which `platform_tag`s we should use
473- # for what. We could also model the `cp313t` freethreaded as separate platforms.
474- )
475-
476- config = struct (** defaults )
514+ config = build_config (module_ctx = module_ctx , enable_pipstar = enable_pipstar )
477515
478516 # TODO @aignas 2025-06-03: Merge override API with the builder?
479517 _overriden_whl_set = {}
@@ -658,6 +696,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
658696 k : dict (sorted (args .items ()))
659697 for k , args in sorted (whl_libraries .items ())
660698 },
699+ config = config ,
661700 )
662701
663702def _pip_impl (module_ctx ):
0 commit comments