@@ -30,6 +30,7 @@ load(":hub_repository.bzl", "hub_repository", "whl_config_settings_to_json")
30
30
load (":parse_requirements.bzl" , "parse_requirements" )
31
31
load (":parse_whl_name.bzl" , "parse_whl_name" )
32
32
load (":pep508_env.bzl" , "env" )
33
+ load (":pep508_evaluate.bzl" , "evaluate" )
33
34
load (":pip_repository_attrs.bzl" , "ATTRS" )
34
35
load (":python_tag.bzl" , "python_tag" )
35
36
load (":requirements_files_by_platform.bzl" , "requirements_files_by_platform" )
@@ -80,21 +81,27 @@ def _platforms(*, python_version, minor_mapping, config):
80
81
for platform , values in config .platforms .items ():
81
82
# TODO @aignas 2025-07-07: this is probably doing the parsing of the version too
82
83
# many times.
83
- key = "{}{}{}.{}_ {}" .format (
84
+ abi = "{}{}{}.{}" .format (
84
85
python_tag (values .env ["implementation_name" ]),
85
86
python_version .release [0 ],
86
87
python_version .release [1 ],
87
88
python_version .release [2 ],
88
- platform ,
89
89
)
90
+ key = "{}_{}" .format (abi , platform )
91
+
92
+ env_ = env (
93
+ env = values .env ,
94
+ os = values .os_name ,
95
+ arch = values .arch_name ,
96
+ python_version = python_version .string ,
97
+ )
98
+
99
+ if values .marker and not evaluate (values .marker , env = env_ ):
100
+ continue
90
101
91
102
platforms [key ] = struct (
92
- env = env (
93
- env = values .env ,
94
- os = values .os_name ,
95
- arch = values .arch_name ,
96
- python_version = python_version .string ,
97
- ),
103
+ env = env_ ,
104
+ triple = "{}_{}_{}" .format (abi , values .os_name , values .arch_name ),
98
105
whl_abi_tags = [
99
106
v .format (
100
107
major = python_version .release [0 ],
@@ -203,17 +210,19 @@ def _create_whl_repos(
203
210
whl_group_mapping = {}
204
211
requirement_cycles = {}
205
212
213
+ platforms = _platforms (
214
+ python_version = pip_attr .python_version ,
215
+ minor_mapping = minor_mapping ,
216
+ config = config ,
217
+ )
218
+
206
219
if evaluate_markers :
207
220
# This is most likely unit tests
208
221
pass
209
222
elif config .enable_pipstar :
210
223
evaluate_markers = lambda _ , requirements : evaluate_markers_star (
211
224
requirements = requirements ,
212
- platforms = _platforms (
213
- python_version = pip_attr .python_version ,
214
- minor_mapping = minor_mapping ,
215
- config = config ,
216
- ),
225
+ platforms = platforms ,
217
226
)
218
227
else :
219
228
# NOTE @aignas 2024-08-02: , we will execute any interpreter that we find either
@@ -232,7 +241,13 @@ def _create_whl_repos(
232
241
# spin up a Python interpreter.
233
242
evaluate_markers = lambda module_ctx , requirements : evaluate_markers_py (
234
243
module_ctx ,
235
- requirements = requirements ,
244
+ requirements = {
245
+ k : {
246
+ p : platforms [p ].triple
247
+ for p in plats
248
+ }
249
+ for k , plats in requirements .items ()
250
+ },
236
251
python_interpreter = pip_attr .python_interpreter ,
237
252
python_interpreter_target = python_interpreter_target ,
238
253
srcs = pip_attr ._evaluate_markers_srcs ,
@@ -248,18 +263,14 @@ def _create_whl_repos(
248
263
requirements_osx = pip_attr .requirements_darwin ,
249
264
requirements_windows = pip_attr .requirements_windows ,
250
265
extra_pip_args = pip_attr .extra_pip_args ,
251
- platforms = sorted (config . platforms ), # here we only need keys
266
+ platforms = sorted (platforms ), # here we only need keys
252
267
python_version = full_version (
253
268
version = pip_attr .python_version ,
254
269
minor_mapping = minor_mapping ,
255
270
),
256
271
logger = logger ,
257
272
),
258
- platforms = _platforms (
259
- python_version = pip_attr .python_version ,
260
- minor_mapping = minor_mapping ,
261
- config = config ,
262
- ),
273
+ platforms = platforms ,
263
274
extra_pip_args = pip_attr .extra_pip_args ,
264
275
get_index_urls = get_index_urls ,
265
276
evaluate_markers = evaluate_markers ,
@@ -344,8 +355,19 @@ def _create_whl_repos(
344
355
repo_name ,
345
356
whl .name ,
346
357
))
347
-
348
358
whl_libraries [repo_name ] = repo .args
359
+
360
+ if not config .enable_pipstar and "experimental_target_platforms" in repo .args :
361
+ whl_libraries [repo_name ] |= {
362
+ "experimental_target_platforms" : sorted ({
363
+ # TODO @aignas 2025-07-07: this should be solved in a better way
364
+ platforms [candidate ].triple .partition ("_" )[- 1 ]: None
365
+ for p in repo .args ["experimental_target_platforms" ]
366
+ for candidate in platforms
367
+ if candidate .endswith (p )
368
+ }),
369
+ }
370
+
349
371
mapping = whl_map .setdefault (whl .name , {})
350
372
if repo .config_setting in mapping and mapping [repo .config_setting ] != repo_name :
351
373
fail (
@@ -436,7 +458,7 @@ def _whl_repo(
436
458
),
437
459
)
438
460
439
- def _plat (* , name , arch_name , os_name , config_settings = [], env = {}, whl_abi_tags = [], whl_platform_tags = []):
461
+ def _plat (* , name , arch_name , os_name , config_settings = [], env = {}, marker = "" , whl_abi_tags = [], whl_platform_tags = []):
440
462
# NOTE @aignas 2025-07-08: the least preferred is the first item in the list
441
463
if "any" not in whl_platform_tags :
442
464
# the lowest priority one needs to be the first one
@@ -456,6 +478,7 @@ def _plat(*, name, arch_name, os_name, config_settings = [], env = {}, whl_abi_t
456
478
# defaults for env
457
479
"implementation_name" : "cpython" ,
458
480
} | env ,
481
+ marker = marker ,
459
482
whl_abi_tags = whl_abi_tags ,
460
483
whl_platform_tags = whl_platform_tags ,
461
484
)
@@ -503,13 +526,14 @@ def build_config(
503
526
config_settings = tag .config_settings ,
504
527
env = tag .env ,
505
528
os_name = tag .os_name ,
529
+ marker = tag .marker ,
506
530
name = platform .replace ("-" , "_" ).lower (),
507
531
whl_abi_tags = tag .whl_abi_tags ,
508
532
whl_platform_tags = tag .whl_platform_tags ,
509
533
override = mod .is_root ,
510
534
)
511
535
512
- if platform and not (tag .arch_name or tag .config_settings or tag .env or tag .os_name or tag .whl_abi_tags or tag .whl_platform_tags ):
536
+ if platform and not (tag .arch_name or tag .config_settings or tag .env or tag .os_name or tag .whl_abi_tags or tag .whl_platform_tags or tag . marker ):
513
537
defaults ["platforms" ].pop (platform )
514
538
515
539
_configure (
@@ -916,6 +940,20 @@ Supported keys:
916
940
::::{note}
917
941
This is only used if the {envvar}`RULES_PYTHON_ENABLE_PIPSTAR` is enabled.
918
942
::::
943
+ """ ,
944
+ ),
945
+ "marker" : attr .string (
946
+ doc = """\
947
+ An environment marker expression that is used to enable/disable platforms for specific python
948
+ versions, operating systems or CPU architectures.
949
+
950
+ If specified, the expression is evaluated during the `bzlmod` extension evaluation phase and if it
951
+ evaluates to `True`, then the platform will be used to construct the hub repositories, otherwise, it
952
+ will be skipped.
953
+
954
+ This is especially useful for setting up freethreaded platform variants only for particular Python
955
+ versions for which the interpreter builds are available. However, this could be also used for other
956
+ things, such as setting up platforms for different `libc` variants.
919
957
""" ,
920
958
),
921
959
# The values for PEP508 env marker evaluation during the lock file parsing
0 commit comments