@@ -78,11 +78,7 @@ def hub_builder(
7878 # buildifier: enable=uninitialized
7979 return self
8080
81- def _use_downloader (self , python_version , whl_name ):
82- return self ._use_downloader .get (python_version , {}).get (
83- normalize_name (whl_name ),
84- self ._get_index_urls .get (python_version ) != None ,
85- )
81+ ### PUBLIC methods
8682
8783def _build (self ):
8884 whl_map = {}
@@ -101,6 +97,108 @@ def _build(self):
10197 whl_libraries = self ._whl_libraries ,
10298 )
10399
100+ def _pip_parse (self , module_ctx , pip_attr , whl_overrides ):
101+ python_version = pip_attr .python_version
102+ if python_version in self ._platforms :
103+ fail ((
104+ "Duplicate pip python version '{version}' for hub " +
105+ "'{hub}' in module '{module}': the Python versions " +
106+ "used for a hub must be unique"
107+ ).format (
108+ hub = self .name ,
109+ module = self .module_name ,
110+ version = python_version ,
111+ ))
112+
113+ self ._platforms [python_version ] = _platforms (
114+ python_version = python_version ,
115+ minor_mapping = self ._minor_mapping ,
116+ config = self ._config ,
117+ )
118+ _set_index_urls (self , pip_attr )
119+ _add_group_map (self , pip_attr .experimental_requirement_cycles )
120+ _add_extra_aliases (self , pip_attr .extra_hub_aliases )
121+ _create_whl_repos (
122+ self ,
123+ module_ctx ,
124+ pip_attr = pip_attr ,
125+ whl_overrides = whl_overrides ,
126+ )
127+
128+ ### end of PUBLIC methods
129+ ### setters for build outputs
130+
131+ def _add_exposed_packages (self , exposed_packages ):
132+ if self ._exposed_packages :
133+ intersection = {}
134+ for pkg in exposed_packages :
135+ if pkg not in self ._exposed_packages :
136+ continue
137+ intersection [pkg ] = None
138+ self ._exposed_packages .clear ()
139+ exposed_packages = intersection
140+
141+ self ._exposed_packages .update (exposed_packages )
142+
143+ def _add_group_map (self , group_map ):
144+ # TODO @aignas 2024-04-05: how do we support different requirement
145+ # cycles for different abis/oses? For now we will need the users to
146+ # assume the same groups across all versions/platforms until we start
147+ # using an alternative cycle resolution strategy.
148+ self ._group_map .clear ()
149+ self ._group_map .update (group_map )
150+
151+ def _add_extra_aliases (self , extra_hub_aliases ):
152+ for whl_name , aliases in extra_hub_aliases .items ():
153+ self ._extra_aliases .setdefault (whl_name , {}).update (
154+ {alias : True for alias in aliases },
155+ )
156+
157+ def _add_whl_library (self , * , python_version , whl , repo ):
158+ if repo == None :
159+ # NOTE @aignas 2025-07-07: we guard against an edge-case where there
160+ # are more platforms defined than there are wheels for and users
161+ # disallow building from sdist.
162+ return
163+
164+ platforms = self ._platforms [python_version ]
165+
166+ # TODO @aignas 2025-06-29: we should not need the version in the repo_name if
167+ # we are using pipstar and we are downloading the wheel using the downloader
168+ repo_name = "{}_{}_{}" .format (self .name , version_label (python_version ), repo .repo_name )
169+
170+ if repo_name in self ._whl_libraries :
171+ fail ("attempting to create a duplicate library {} for {}" .format (
172+ repo_name ,
173+ whl .name ,
174+ ))
175+ self ._whl_libraries [repo_name ] = repo .args
176+
177+ if not self ._config .enable_pipstar and "experimental_target_platforms" in repo .args :
178+ self ._whl_libraries [repo_name ] |= {
179+ "experimental_target_platforms" : sorted ({
180+ # TODO @aignas 2025-07-07: this should be solved in a better way
181+ platforms [candidate ].triple .partition ("_" )[- 1 ]: None
182+ for p in repo .args ["experimental_target_platforms" ]
183+ for candidate in platforms
184+ if candidate .endswith (p )
185+ }),
186+ }
187+
188+ mapping = self ._whl_map .setdefault (whl .name , {})
189+ if repo .config_setting in mapping and mapping [repo .config_setting ] != repo_name :
190+ fail (
191+ "attempting to override an existing repo '{}' for config setting '{}' with a new repo '{}'" .format (
192+ mapping [repo .config_setting ],
193+ repo .config_setting ,
194+ repo_name ,
195+ ),
196+ )
197+ else :
198+ mapping [repo .config_setting ] = repo_name
199+
200+ ### end of setters, below we have various functions to implement the public methods
201+
104202def _set_index_urls (self , pip_attr ):
105203 if not pip_attr .experimental_index_url :
106204 if pip_attr .experimental_extra_index_urls :
@@ -213,49 +311,6 @@ def _platforms(*, python_version, minor_mapping, config):
213311 )
214312 return platforms
215313
216- def _add_whl_library (self , * , python_version , whl , repo ):
217- if repo == None :
218- # NOTE @aignas 2025-07-07: we guard against an edge-case where there
219- # are more platforms defined than there are wheels for and users
220- # disallow building from sdist.
221- return
222-
223- platforms = self ._platforms [python_version ]
224-
225- # TODO @aignas 2025-06-29: we should not need the version in the repo_name if
226- # we are using pipstar and we are downloading the wheel using the downloader
227- repo_name = "{}_{}_{}" .format (self .name , version_label (python_version ), repo .repo_name )
228-
229- if repo_name in self ._whl_libraries :
230- fail ("attempting to create a duplicate library {} for {}" .format (
231- repo_name ,
232- whl .name ,
233- ))
234- self ._whl_libraries [repo_name ] = repo .args
235-
236- if not self ._config .enable_pipstar and "experimental_target_platforms" in repo .args :
237- self ._whl_libraries [repo_name ] |= {
238- "experimental_target_platforms" : sorted ({
239- # TODO @aignas 2025-07-07: this should be solved in a better way
240- platforms [candidate ].triple .partition ("_" )[- 1 ]: None
241- for p in repo .args ["experimental_target_platforms" ]
242- for candidate in platforms
243- if candidate .endswith (p )
244- }),
245- }
246-
247- mapping = self ._whl_map .setdefault (whl .name , {})
248- if repo .config_setting in mapping and mapping [repo .config_setting ] != repo_name :
249- fail (
250- "attempting to override an existing repo '{}' for config setting '{}' with a new repo '{}'" .format (
251- mapping [repo .config_setting ],
252- repo .config_setting ,
253- repo_name ,
254- ),
255- )
256- else :
257- mapping [repo .config_setting ] = repo_name
258-
259314def _evaluate_markers (self , pip_attr ):
260315 if self ._evaluate_markers_fn :
261316 return self ._evaluate_markers_fn
@@ -425,18 +480,6 @@ def _create_whl_repos(
425480
426481 _add_exposed_packages (self , exposed_packages )
427482
428- def _add_exposed_packages (self , exposed_packages ):
429- if self ._exposed_packages :
430- intersection = {}
431- for pkg in exposed_packages :
432- if pkg not in self ._exposed_packages :
433- continue
434- intersection [pkg ] = None
435- self ._exposed_packages .clear ()
436- exposed_packages = intersection
437-
438- self ._exposed_packages .update (exposed_packages )
439-
440483def _whl_repo (
441484 * ,
442485 src ,
@@ -508,44 +551,8 @@ def _whl_repo(
508551 ),
509552 )
510553
511- def _add_group_map (self , group_map ):
512- # TODO @aignas 2024-04-05: how do we support different requirement
513- # cycles for different abis/oses? For now we will need the users to
514- # assume the same groups across all versions/platforms until we start
515- # using an alternative cycle resolution strategy.
516- self ._group_map .clear ()
517- self ._group_map .update (group_map )
518-
519- def _add_extra_aliases (self , extra_hub_aliases ):
520- for whl_name , aliases in extra_hub_aliases .items ():
521- self ._extra_aliases .setdefault (whl_name , {}).update (
522- {alias : True for alias in aliases },
523- )
524-
525- def _pip_parse (self , module_ctx , pip_attr , whl_overrides ):
526- python_version = pip_attr .python_version
527- if python_version in self ._platforms :
528- fail ((
529- "Duplicate pip python version '{version}' for hub " +
530- "'{hub}' in module '{module}': the Python versions " +
531- "used for a hub must be unique"
532- ).format (
533- hub = self .name ,
534- module = self .module_name ,
535- version = python_version ,
536- ))
537-
538- self ._platforms [python_version ] = _platforms (
539- python_version = python_version ,
540- minor_mapping = self ._minor_mapping ,
541- config = self ._config ,
542- )
543- _set_index_urls (self , pip_attr )
544- _add_group_map (self , pip_attr .experimental_requirement_cycles )
545- _add_extra_aliases (self , pip_attr .extra_hub_aliases )
546- _create_whl_repos (
547- self ,
548- module_ctx ,
549- pip_attr = pip_attr ,
550- whl_overrides = whl_overrides ,
554+ def _use_downloader (self , python_version , whl_name ):
555+ return self ._use_downloader .get (python_version , {}).get (
556+ normalize_name (whl_name ),
557+ self ._get_index_urls .get (python_version ) != None ,
551558 )
0 commit comments