@@ -66,7 +66,7 @@ def _whl_mods_impl(whl_mods_dict):
6666 whl_mods = whl_mods ,
6767 )
6868
69- def _add_whl_repos (
69+ def _create_whl_repos (
7070 module_ctx ,
7171 * ,
7272 pip_attr ,
@@ -82,6 +82,17 @@ def _add_whl_repos(
8282 hub: TODO.
8383 minor_mapping: {type}`dict[str, str]` The dictionary needed to resolve the full
8484 python version used to parse package METADATA files.
85+
86+ Returns a {type}`struct` with the following attributes:
87+ whl_map: {type}`dict[str, list[struct]]` the output is keyed by the
88+ normalized package name and the values are the instances of the
89+ {bzl:obj}`whl_config_setting` return values.
90+ exposed_packages: {type}`dict[str, Any]` this is just a way to
91+ represent a set of string values.
92+ whl_libraries: {type}`dict[str, dict[str, Any]]` the keys are the
93+ aparent repository names for the hub repo and the values are the
94+ arguments that will be passed to {bzl:obj}`whl_library` repository
95+ rule.
8596 """
8697 logger = repo_utils .logger (module_ctx , "pypi:create_whl_repos" )
8798 interpreter = hub .detect_interpreter (pip_attr )
@@ -115,7 +126,6 @@ def _add_whl_repos(
115126 logger = logger ,
116127 )
117128
118- exposed_packages = {}
119129 if pip_attr .experimental_requirement_cycles :
120130 requirement_cycles = {
121131 name : [normalize_name (whl_name ) for whl_name in whls ]
@@ -130,6 +140,7 @@ def _add_whl_repos(
130140 else :
131141 whl_group_mapping = {}
132142 requirement_cycles = {}
143+ exposed_packages = {}
133144 for whl in requirements_by_platform :
134145 if whl .is_exposed :
135146 exposed_packages [whl .name ] = None
@@ -194,17 +205,13 @@ def _add_whl_repos(
194205 repo = repo ,
195206 )
196207
197- if not hub .exposed_packages :
198- hub .exposed_packages .update (exposed_packages )
199- else :
200- intersection = {}
201- for pkg in exposed_packages :
202- if pkg not in hub .exposed_packages :
203- continue
204- intersection [pkg ] = None
205-
206- hub .exposed_packages .clear ()
207- hub .exposed_packages .update (intersection )
208+ return struct (
209+ exposed_packages = exposed_packages ,
210+ extra_aliases = {
211+ whl_name : {alias : True for alias in aliases }
212+ for whl_name , aliases in pip_attr .extra_hub_aliases .items ()
213+ },
214+ )
208215
209216def _whl_repo (
210217 * ,
@@ -509,23 +516,40 @@ You cannot use both the additive_build_content and additive_build_content_file a
509516 builder .add (pip_attr = pip_attr )
510517
511518 # TODO @aignas 2025-05-19: express pip.parse as a series of configure calls
512- _add_whl_repos (
519+ out = _create_whl_repos (
513520 module_ctx ,
514521 hub = builder ,
515522 pip_attr = pip_attr ,
516523 whl_overrides = whl_overrides ,
517524 minor_mapping = kwargs .get ("minor_mapping" , MINOR_MAPPING ),
518525 )
519526
527+ extra_aliases .setdefault (hub_name , {})
528+ for whl_name , aliases in out .extra_aliases .items ():
529+ extra_aliases [hub_name ].setdefault (whl_name , {}).update (aliases )
530+
531+ if hub_name not in exposed_packages :
532+ exposed_packages [hub_name ] = out .exposed_packages
533+ else :
534+ intersection = {}
535+ for pkg in out .exposed_packages :
536+ if pkg not in exposed_packages [hub_name ]:
537+ continue
538+ intersection [pkg ] = None
539+ exposed_packages [hub_name ] = intersection
540+
541+ # TODO @aignas 2024-04-05: how do we support different requirement
542+ # cycles for different abis/oses? For now we will need the users to
543+ # assume the same groups across all versions/platforms until we start
544+ # using an alternative cycle resolution strategy.
545+ hub_group_map [hub_name ] = pip_attr .experimental_requirement_cycles
546+
520547 for hub in pip_hub_map .values ():
521548 hub_whl_map .setdefault (hub .name , {})
522549 for key , settings in hub .whl_map .items ():
523550 for setting , repo in settings .items ():
524551 hub_whl_map [hub .name ].setdefault (key , {}).setdefault (repo , []).append (setting )
525552
526- for whl_name , aliases in hub .extra_aliases .items ():
527- extra_aliases [hub .name ].setdefault (whl_name , {}).update (aliases )
528-
529553 whl_libraries .update (hub .whl_libraries )
530554 for whl_name , lib in hub .whl_libraries .items ():
531555 if whl_name in lib :
@@ -534,9 +558,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
534558 # replicate whl_libraries.update(out.whl_libraries)
535559 whl_libraries [whl_name ] = lib
536560
537- hub_group_map [hub .name ] = hub .group_map
538- exposed_packages [hub .name ] = hub .exposed_packages
539-
540561 return struct (
541562 # We sort so that the lock-file remains the same no matter the order of how the
542563 # args are manipulated in the code going before.
0 commit comments