@@ -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 (":requirements_files_by_platform.bzl" , "requirements_files_by_platform" )
35
36
load (":simpleapi_download.bzl" , "simpleapi_download" )
@@ -83,8 +84,13 @@ def _platforms(*, python_version, minor_mapping, config):
83
84
os = values .os_name ,
84
85
arch = values .arch_name ,
85
86
)) | values .env
87
+
88
+ if values .marker and not evaluate (values .marker , env = env_ ):
89
+ continue
90
+
86
91
platforms [key ] = struct (
87
92
env = env_ ,
93
+ tripple = "{}_{}_{}" .format (abi , values .os_name , values .arch_name ),
88
94
want_abis = [
89
95
v .format (* python_version .split ("." ))
90
96
for v in values .want_abis
@@ -190,17 +196,19 @@ def _create_whl_repos(
190
196
whl_group_mapping = {}
191
197
requirement_cycles = {}
192
198
199
+ platforms = _platforms (
200
+ python_version = pip_attr .python_version ,
201
+ minor_mapping = minor_mapping ,
202
+ config = config ,
203
+ )
204
+
193
205
if evaluate_markers :
194
206
# This is most likely unit tests
195
207
pass
196
208
elif config .enable_pipstar :
197
209
evaluate_markers = lambda _ , requirements : evaluate_markers_star (
198
210
requirements = requirements ,
199
- platforms = _platforms (
200
- python_version = pip_attr .python_version ,
201
- minor_mapping = minor_mapping ,
202
- config = config ,
203
- ),
211
+ platforms = platforms ,
204
212
)
205
213
else :
206
214
# NOTE @aignas 2024-08-02: , we will execute any interpreter that we find either
@@ -219,7 +227,14 @@ def _create_whl_repos(
219
227
# spin up a Python interpreter.
220
228
evaluate_markers = lambda module_ctx , requirements : evaluate_markers_py (
221
229
module_ctx ,
222
- requirements = requirements ,
230
+ requirements = {
231
+ k : {
232
+ # TODO @aignas 2025-07-06: should we leave this as is?
233
+ p : platforms [p ].tripple
234
+ for p in plats
235
+ }
236
+ for k , plats in requirements .items ()
237
+ },
223
238
python_interpreter = pip_attr .python_interpreter ,
224
239
python_interpreter_target = python_interpreter_target ,
225
240
srcs = pip_attr ._evaluate_markers_srcs ,
@@ -235,18 +250,14 @@ def _create_whl_repos(
235
250
requirements_osx = pip_attr .requirements_darwin ,
236
251
requirements_windows = pip_attr .requirements_windows ,
237
252
extra_pip_args = pip_attr .extra_pip_args ,
238
- platforms = sorted (config . platforms ), # here we only need keys
253
+ platforms = sorted (platforms ), # here we only need keys
239
254
python_version = full_version (
240
255
version = pip_attr .python_version ,
241
256
minor_mapping = minor_mapping ,
242
257
),
243
258
logger = logger ,
244
259
),
245
- platforms = _platforms (
246
- python_version = pip_attr .python_version ,
247
- minor_mapping = minor_mapping ,
248
- config = config ,
249
- ),
260
+ platforms = platforms ,
250
261
extra_pip_args = pip_attr .extra_pip_args ,
251
262
get_index_urls = get_index_urls ,
252
263
evaluate_markers = evaluate_markers ,
@@ -320,6 +331,17 @@ def _create_whl_repos(
320
331
))
321
332
322
333
whl_libraries [repo_name ] = repo .args
334
+ if "experimental_target_platforms" in repo .args :
335
+ whl_libraries [repo_name ] |= {
336
+ "experimental_target_platforms" : sorted ({
337
+ # TODO @aignas 2025-07-07: this should be solved in a better way
338
+ # TODO @aignas 2025-07-07: add a unit test
339
+ platforms [candidate ].tripple .partition ("_" )[- 1 ]: None
340
+ for p in repo .args ["experimental_target_platforms" ]
341
+ for candidate in platforms
342
+ if candidate .endswith (p )
343
+ }),
344
+ }
323
345
whl_map .setdefault (whl .name , {})[repo .config_setting ] = repo_name
324
346
325
347
return struct (
@@ -385,7 +407,7 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
385
407
),
386
408
)
387
409
388
- def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , override = False ):
410
+ def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , marker , override = False ):
389
411
"""Set the value in the config if the value is provided"""
390
412
config .setdefault ("platforms" , {})
391
413
if platform and (os_name or arch_name or config_settings or platform_tags or env ):
@@ -406,21 +428,25 @@ def _configure(config, *, platform, os_name, arch_name, config_settings, env = {
406
428
# the lowest priority one needs to be the first one
407
429
platform_tags = ["any" ] + platform_tags
408
430
431
+ want_abis = want_abis or [
432
+ "cp{0}{1}" ,
433
+ "abi3" ,
434
+ "none" ,
435
+ ]
436
+ env = {
437
+ # default to this
438
+ "implementation_name" : "cpython" ,
439
+ } | env
440
+
409
441
config ["platforms" ][platform ] = struct (
410
442
name = platform .replace ("-" , "_" ).lower (),
411
- os_name = os_name ,
412
443
arch_name = arch_name ,
413
444
config_settings = config_settings ,
414
- want_abis = want_abis or [
415
- "cp{0}{1}" ,
416
- "abi3" ,
417
- "none" ,
418
- ],
445
+ env = env ,
446
+ marker = marker ,
447
+ os_name = os_name ,
419
448
platform_tags = platform_tags ,
420
- env = {
421
- # default to this
422
- "implementation_name" : "cpython" ,
423
- } | env ,
449
+ want_abis = want_abis ,
424
450
)
425
451
else :
426
452
config ["platforms" ].pop (platform )
@@ -491,6 +517,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
491
517
env = tag .env ,
492
518
os_name = tag .os_name ,
493
519
platform = tag .platform ,
520
+ marker = tag .marker ,
494
521
platform_tags = tag .platform_tags ,
495
522
want_abis = tag .want_abis ,
496
523
override = mod .is_root ,
@@ -823,6 +850,12 @@ Supported keys:
823
850
::::{note}
824
851
This is only used if the {envvar}`RULES_PYTHON_ENABLE_PIPSTAR` is enabled.
825
852
::::
853
+ """ ,
854
+ ),
855
+ "marker" : attr .string (
856
+ doc = """\
857
+ A marker which will be evaluated to disable the target platform for certain python versions. This
858
+ is especially useful when defining freethreaded platform variants.
826
859
""" ,
827
860
),
828
861
# The values for PEP508 env marker evaluation during the lock file parsing
0 commit comments