@@ -25,10 +25,11 @@ load("//python/private:repo_utils.bzl", "repo_utils")
2525load ("//python/private:version.bzl" , "version" )
2626load ("//python/private:version_label.bzl" , "version_label" )
2727load (":attrs.bzl" , "use_isolated" )
28- load (":evaluate_markers.bzl" , "evaluate_markers_py" , EVALUATE_MARKERS_SRCS = "SRCS" )
28+ load (":evaluate_markers.bzl" , "evaluate_markers_py" , EVALUATE_MARKERS_SRCS = "SRCS" , evaluate_markers_star = "evaluate_markers" )
2929load (":hub_repository.bzl" , "hub_repository" , "whl_config_settings_to_json" )
3030load (":parse_requirements.bzl" , "parse_requirements" )
3131load (":parse_whl_name.bzl" , "parse_whl_name" )
32+ load (":pep508_env.bzl" , "env" )
3233load (":pip_repository_attrs.bzl" , "ATTRS" )
3334load (":requirements_files_by_platform.bzl" , "requirements_files_by_platform" )
3435load (":simpleapi_download.bzl" , "simpleapi_download" )
@@ -65,6 +66,19 @@ def _whl_mods_impl(whl_mods_dict):
6566 whl_mods = whl_mods ,
6667 )
6768
69+ def _platforms (* , python_version , minor_mapping , config ):
70+ platforms = {}
71+ python_version = full_version (
72+ version = python_version ,
73+ minor_mapping = minor_mapping ,
74+ )
75+ abi = "cp3{}" .format (python_version [2 :])
76+
77+ for platform , values in config ["platforms" ].items ():
78+ key = "{}_{}" .format (abi , platform )
79+ platforms [key ] = env (key ) | values .env
80+ return platforms
81+
6882def _create_whl_repos (
6983 module_ctx ,
7084 * ,
@@ -73,7 +87,7 @@ def _create_whl_repos(
7387 config ,
7488 available_interpreters = INTERPRETER_LABELS ,
7589 minor_mapping = MINOR_MAPPING ,
76- evaluate_markers = evaluate_markers_py ,
90+ evaluate_markers = None ,
7791 get_index_urls = None ,
7892 enable_pipstar = False ):
7993 """create all of the whl repositories
@@ -106,7 +120,11 @@ def _create_whl_repos(
106120 """
107121 logger = repo_utils .logger (module_ctx , "pypi:create_whl_repos" )
108122 python_interpreter_target = pip_attr .python_interpreter_target
109- platforms = config ["platforms" ]
123+ platforms = _platforms (
124+ python_version = pip_attr .python_version ,
125+ minor_mapping = minor_mapping ,
126+ config = config ,
127+ )
110128
111129 # containers to aggregate outputs from this function
112130 whl_map = {}
@@ -163,23 +181,14 @@ def _create_whl_repos(
163181 whl_group_mapping = {}
164182 requirement_cycles = {}
165183
166- requirements_by_platform = parse_requirements (
167- module_ctx ,
168- requirements_by_platform = requirements_files_by_platform (
169- requirements_by_platform = pip_attr .requirements_by_platform ,
170- requirements_linux = pip_attr .requirements_linux ,
171- requirements_lock = pip_attr .requirements_lock ,
172- requirements_osx = pip_attr .requirements_darwin ,
173- requirements_windows = pip_attr .requirements_windows ,
174- extra_pip_args = pip_attr .extra_pip_args ,
175- python_version = full_version (
176- version = pip_attr .python_version ,
177- minor_mapping = minor_mapping ,
178- ),
179- logger = logger ,
180- ),
181- extra_pip_args = pip_attr .extra_pip_args ,
182- get_index_urls = get_index_urls ,
184+ if evaluate_markers :
185+ pass
186+ elif enable_pipstar :
187+ evaluate_markers = lambda _ , requirements : evaluate_markers_star (
188+ requirements = requirements ,
189+ platforms = platforms ,
190+ )
191+ else :
183192 # NOTE @aignas 2024-08-02: , we will execute any interpreter that we find either
184193 # in the PATH or if specified as a label. We will configure the env
185194 # markers when evaluating the requirement lines based on the output
@@ -194,15 +203,39 @@ def _create_whl_repos(
194203 # instances to perform this manipulation. This function should be executed
195204 # only once by the underlying code to minimize the overhead needed to
196205 # spin up a Python interpreter.
197- evaluate_markers = lambda module_ctx , requirements : evaluate_markers (
206+ evaluate_markers = lambda module_ctx , requirements : evaluate_markers_py (
198207 module_ctx ,
199208 requirements = requirements ,
200209 python_interpreter = pip_attr .python_interpreter ,
201210 python_interpreter_target = python_interpreter_target ,
202211 srcs = pip_attr ._evaluate_markers_srcs ,
203212 logger = logger ,
204- ),
205- platforms = platforms ,
213+ )
214+
215+ requirements_by_platform = parse_requirements (
216+ module_ctx ,
217+ requirements_by_platform = {
218+ # TODO @aignas 2025-05-19: we probably want to pass the `platforms` to
219+ # `requirements_files_by_platform so that we can customize what exactly we can/want do.
220+ k : v
221+ for k , v in requirements_files_by_platform (
222+ requirements_by_platform = pip_attr .requirements_by_platform ,
223+ requirements_linux = pip_attr .requirements_linux ,
224+ requirements_lock = pip_attr .requirements_lock ,
225+ requirements_osx = pip_attr .requirements_darwin ,
226+ requirements_windows = pip_attr .requirements_windows ,
227+ extra_pip_args = pip_attr .extra_pip_args ,
228+ python_version = full_version (
229+ version = pip_attr .python_version ,
230+ minor_mapping = minor_mapping ,
231+ ),
232+ logger = logger ,
233+ ).items ()
234+ if k in platforms
235+ },
236+ extra_pip_args = pip_attr .extra_pip_args ,
237+ get_index_urls = get_index_urls ,
238+ evaluate_markers = evaluate_markers ,
206239 logger = logger ,
207240 )
208241
@@ -368,7 +401,7 @@ def _whl_repos(*, requirement, whl_library_args, download_only, netrc, auth_patt
368401
369402 return ret
370403
371- def _configure (config , * , platform , constraint_values , target_settings , override = False , ** values ):
404+ def _configure (config , * , platform , constraint_values , target_settings , os_name , arch_name , override = False , ** values ):
372405 """Set the value in the config if the value is provided"""
373406 for key , value in values .items ():
374407 if not value :
@@ -391,7 +424,13 @@ def _configure(config, *, platform, constraint_values, target_settings, override
391424 name = platform .replace ("-" , "_" ).lower (),
392425 constraint_values = constraint_values ,
393426 target_settings = target_settings ,
394- env = struct (), # ...
427+ os_name = os_name ,
428+ arch_name = arch_name ,
429+ env = {
430+ k [4 :]: v
431+ for k , v in values .items ()
432+ if k .startswith ("env_" ) and v
433+ },
395434 )
396435 else :
397436 config ["platforms" ].pop (platform )
@@ -760,6 +799,7 @@ A list of config_settings that must be satisfied by the target configuration in
760799platform to be matched during analysis phase.
761800""" ,
762801 ),
802+ "whls_limit" : attr .int (default = - 1 ),
763803}
764804
765805_configure_attrs = _default_attrs | {
0 commit comments