@@ -19,27 +19,16 @@ load("@pythons_hub//:interpreters.bzl", "INTERPRETER_LABELS")
1919load ("@pythons_hub//:versions.bzl" , "MINOR_MAPPING" )
2020load ("@rules_python_internal//:rules_python_config.bzl" , rp_config = "config" )
2121load ("//python/private:auth.bzl" , "AUTH_ATTRS" )
22- load ("//python/private:full_version.bzl" , "full_version" )
2322load ("//python/private:normalize_name.bzl" , "normalize_name" )
2423load ("//python/private:repo_utils.bzl" , "repo_utils" )
25- load ("//python/private:version.bzl" , "version" )
26- load (":attrs.bzl" , "use_isolated" )
2724load (":evaluate_markers.bzl" , EVALUATE_MARKERS_SRCS = "SRCS" )
2825load (":hub_builder.bzl" , "hub_builder" )
2926load (":hub_repository.bzl" , "hub_repository" , "whl_config_settings_to_json" )
30- load (":parse_requirements.bzl" , "parse_requirements" )
3127load (":parse_whl_name.bzl" , "parse_whl_name" )
3228load (":pep508_env.bzl" , "env" )
3329load (":pip_repository_attrs.bzl" , "ATTRS" )
34- load (":requirements_files_by_platform.bzl" , "requirements_files_by_platform" )
3530load (":simpleapi_download.bzl" , "simpleapi_download" )
36- load (":whl_config_setting.bzl" , "whl_config_setting" )
3731load (":whl_library.bzl" , "whl_library" )
38- load (":whl_repo_name.bzl" , "pypi_repo_name" , "whl_repo_name" )
39-
40- def _major_minor_version (version_str ):
41- ver = version .parse (version_str )
42- return "{}.{}" .format (ver .release [0 ], ver .release [1 ])
4332
4433def _whl_mods_impl (whl_mods_dict ):
4534 """Implementation of the pip.whl_mods tag class.
@@ -66,216 +55,6 @@ def _whl_mods_impl(whl_mods_dict):
6655 whl_mods = whl_mods ,
6756 )
6857
69- def _create_whl_repos (
70- module_ctx ,
71- * ,
72- pip_attr ,
73- whl_overrides ,
74- hub ,
75- minor_mapping = MINOR_MAPPING ):
76- """create all of the whl repositories
77-
78- Args:
79- module_ctx: {type}`module_ctx`.
80- pip_attr: {type}`struct` - the struct that comes from the tag class iteration.
81- whl_overrides: {type}`dict[str, struct]` - per-wheel overrides.
82- hub: TODO.
83- minor_mapping: {type}`dict[str, str]` The dictionary needed to resolve the full
84- python version used to parse package METADATA files.
85- """
86- logger = repo_utils .logger (module_ctx , "pypi:create_whl_repos" )
87- interpreter = hub .detect_interpreter (pip_attr )
88-
89- whl_modifications = {}
90- if pip_attr .whl_modifications != None :
91- for mod , whl_name in pip_attr .whl_modifications .items ():
92- whl_modifications [normalize_name (whl_name )] = mod
93-
94- platforms = hub .platforms (pip_attr .python_version )
95- requirements_by_platform = parse_requirements (
96- module_ctx ,
97- requirements_by_platform = requirements_files_by_platform (
98- requirements_by_platform = pip_attr .requirements_by_platform ,
99- requirements_linux = pip_attr .requirements_linux ,
100- requirements_lock = pip_attr .requirements_lock ,
101- requirements_osx = pip_attr .requirements_darwin ,
102- requirements_windows = pip_attr .requirements_windows ,
103- extra_pip_args = pip_attr .extra_pip_args ,
104- platforms = sorted (platforms ), # here we only need keys
105- python_version = full_version (
106- version = pip_attr .python_version ,
107- minor_mapping = minor_mapping ,
108- ),
109- logger = logger ,
110- ),
111- platforms = platforms ,
112- extra_pip_args = pip_attr .extra_pip_args ,
113- get_index_urls = hub .get_index_urls (pip_attr .python_version ),
114- evaluate_markers = hub .evaluate_markers (pip_attr ),
115- logger = logger ,
116- )
117-
118- if pip_attr .experimental_requirement_cycles :
119- requirement_cycles = {
120- name : [normalize_name (whl_name ) for whl_name in whls ]
121- for name , whls in pip_attr .experimental_requirement_cycles .items ()
122- }
123-
124- whl_group_mapping = {
125- whl_name : group_name
126- for group_name , group_whls in requirement_cycles .items ()
127- for whl_name in group_whls
128- }
129- else :
130- whl_group_mapping = {}
131- requirement_cycles = {}
132- exposed_packages = {}
133- for whl in requirements_by_platform :
134- if whl .is_exposed :
135- exposed_packages [whl .name ] = None
136-
137- group_name = whl_group_mapping .get (whl .name )
138- group_deps = requirement_cycles .get (group_name , [])
139-
140- # Construct args separately so that the lock file can be smaller and does not include unused
141- # attrs.
142- whl_library_args = dict (
143- dep_template = "@{}//{{name}}:{{target}}" .format (hub .name ),
144- )
145- maybe_args = dict (
146- # The following values are safe to omit if they have false like values
147- add_libdir_to_library_search_path = pip_attr .add_libdir_to_library_search_path ,
148- annotation = whl_modifications .get (whl .name ),
149- download_only = pip_attr .download_only ,
150- enable_implicit_namespace_pkgs = pip_attr .enable_implicit_namespace_pkgs ,
151- environment = pip_attr .environment ,
152- envsubst = pip_attr .envsubst ,
153- group_deps = group_deps ,
154- group_name = group_name ,
155- pip_data_exclude = pip_attr .pip_data_exclude ,
156- python_interpreter = interpreter .path ,
157- python_interpreter_target = interpreter .target ,
158- whl_patches = {
159- p : json .encode (args )
160- for p , args in whl_overrides .get (whl .name , {}).items ()
161- },
162- )
163- if not hub .config .enable_pipstar :
164- maybe_args ["experimental_target_platforms" ] = pip_attr .experimental_target_platforms
165-
166- whl_library_args .update ({k : v for k , v in maybe_args .items () if v })
167- maybe_args_with_default = dict (
168- # The following values have defaults next to them
169- isolated = (use_isolated (module_ctx , pip_attr ), True ),
170- quiet = (pip_attr .quiet , True ),
171- timeout = (pip_attr .timeout , 600 ),
172- )
173- whl_library_args .update ({
174- k : v
175- for k , (v , default ) in maybe_args_with_default .items ()
176- if v != default
177- })
178-
179- for src in whl .srcs :
180- repo = _whl_repo (
181- src = src ,
182- whl_library_args = whl_library_args ,
183- download_only = pip_attr .download_only ,
184- netrc = hub .config .netrc or pip_attr .netrc ,
185- use_downloader = hub .use_downloader (pip_attr .python_version , whl .name ),
186- auth_patterns = hub .config .auth_patterns or pip_attr .auth_patterns ,
187- python_version = _major_minor_version (pip_attr .python_version ),
188- is_multiple_versions = whl .is_multiple_versions ,
189- enable_pipstar = hub .config .enable_pipstar ,
190- )
191- hub .add_whl_library (
192- python_version = pip_attr .python_version ,
193- whl = whl ,
194- repo = repo ,
195- )
196-
197- if hub .exposed_packages :
198- intersection = {}
199- for pkg in exposed_packages :
200- if pkg not in hub .exposed_packages :
201- continue
202- intersection [pkg ] = None
203- hub .exposed_packages .clear ()
204- exposed_packages = intersection
205-
206- hub .exposed_packages .update (exposed_packages )
207-
208- def _whl_repo (
209- * ,
210- src ,
211- whl_library_args ,
212- is_multiple_versions ,
213- download_only ,
214- netrc ,
215- auth_patterns ,
216- python_version ,
217- use_downloader ,
218- enable_pipstar = False ):
219- args = dict (whl_library_args )
220- args ["requirement" ] = src .requirement_line
221- is_whl = src .filename .endswith (".whl" )
222-
223- if src .extra_pip_args and not is_whl :
224- # pip is not used to download wheels and the python
225- # `whl_library` helpers are only extracting things, however
226- # for sdists, they will be built by `pip`, so we still
227- # need to pass the extra args there, so only pop this for whls
228- args ["extra_pip_args" ] = src .extra_pip_args
229-
230- if not src .url or (not is_whl and download_only ):
231- if download_only and use_downloader :
232- # If the user did not allow using sdists and we are using the downloader
233- # and we are not using simpleapi_skip for this
234- return None
235- else :
236- # Fallback to a pip-installed wheel
237- target_platforms = src .target_platforms if is_multiple_versions else []
238- return struct (
239- repo_name = pypi_repo_name (
240- normalize_name (src .distribution ),
241- * target_platforms
242- ),
243- args = args ,
244- config_setting = whl_config_setting (
245- version = python_version ,
246- target_platforms = target_platforms or None ,
247- ),
248- )
249-
250- # This is no-op because pip is not used to download the wheel.
251- args .pop ("download_only" , None )
252-
253- if netrc :
254- args ["netrc" ] = netrc
255- if auth_patterns :
256- args ["auth_patterns" ] = auth_patterns
257-
258- args ["urls" ] = [src .url ]
259- args ["sha256" ] = src .sha256
260- args ["filename" ] = src .filename
261- if not enable_pipstar :
262- args ["experimental_target_platforms" ] = [
263- # Get rid of the version for the target platforms because we are
264- # passing the interpreter any way. Ideally we should search of ways
265- # how to pass the target platforms through the hub repo.
266- p .partition ("_" )[2 ]
267- for p in src .target_platforms
268- ]
269-
270- return struct (
271- repo_name = whl_repo_name (src .filename , src .sha256 ),
272- args = args ,
273- config_setting = whl_config_setting (
274- version = python_version ,
275- target_platforms = src .target_platforms ,
276- ),
277- )
278-
27958def _plat (* , name , arch_name , os_name , config_settings = [], env = {}, marker = "" , whl_abi_tags = [], whl_platform_tags = []):
28059 # NOTE @aignas 2025-07-08: the least preferred is the first item in the list
28160 if "any" not in whl_platform_tags :
@@ -482,6 +261,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
482261 config = config ,
483262 simpleapi_download_fn = simpleapi_download ,
484263 simpleapi_cache = simpleapi_cache ,
264+ # TODO @aignas 2025-09-06: do not use kwargs
485265 minor_mapping = kwargs .get ("minor_mapping" , MINOR_MAPPING ),
486266 evaluate_markers_fn = kwargs .get ("evaluate_markers" , None ),
487267 available_interpreters = kwargs .get ("available_interpreters" , INTERPRETER_LABELS ),
@@ -508,12 +288,10 @@ You cannot use both the additive_build_content and additive_build_content_file a
508288 builder .add (pip_attr = pip_attr )
509289
510290 # TODO @aignas 2025-05-19: express pip.parse as a series of configure calls
511- _create_whl_repos (
291+ builder . create_whl_repos (
512292 module_ctx ,
513- hub = builder ,
514293 pip_attr = pip_attr ,
515294 whl_overrides = whl_overrides ,
516- minor_mapping = kwargs .get ("minor_mapping" , MINOR_MAPPING ),
517295 )
518296
519297 for hub in pip_hub_map .values ():
0 commit comments