@@ -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,16 @@ 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
+ platforms [candidate ].tripple .partition ("_" )[- 1 ]: None
339
+ for p in repo .args ["experimental_target_platforms" ]
340
+ for candidate in platforms
341
+ if candidate .endswith (p )
342
+ }),
343
+ }
323
344
whl_map .setdefault (whl .name , {})[repo .config_setting ] = repo_name
324
345
325
346
return struct (
@@ -385,7 +406,7 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
385
406
),
386
407
)
387
408
388
- def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , override = False ):
409
+ def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , marker , override = False ):
389
410
"""Set the value in the config if the value is provided"""
390
411
config .setdefault ("platforms" , {})
391
412
if platform and (os_name or arch_name or config_settings or platform_tags or env ):
@@ -406,21 +427,25 @@ def _configure(config, *, platform, os_name, arch_name, config_settings, env = {
406
427
# the lowest priority one needs to be the first one
407
428
platform_tags = ["any" ] + platform_tags
408
429
430
+ want_abis = want_abis or [
431
+ "cp{0}{1}" ,
432
+ "abi3" ,
433
+ "none" ,
434
+ ]
435
+ env = {
436
+ # default to this
437
+ "implementation_name" : "cpython" ,
438
+ } | env
439
+
409
440
config ["platforms" ][platform ] = struct (
410
441
name = platform .replace ("-" , "_" ).lower (),
411
- os_name = os_name ,
412
442
arch_name = arch_name ,
413
443
config_settings = config_settings ,
414
- want_abis = want_abis or [
415
- "cp{0}{1}" ,
416
- "abi3" ,
417
- "none" ,
418
- ],
444
+ env = env ,
445
+ marker = marker ,
446
+ os_name = os_name ,
419
447
platform_tags = platform_tags ,
420
- env = {
421
- # default to this
422
- "implementation_name" : "cpython" ,
423
- } | env ,
448
+ want_abis = want_abis ,
424
449
)
425
450
else :
426
451
config ["platforms" ].pop (platform )
@@ -491,6 +516,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
491
516
env = tag .env ,
492
517
os_name = tag .os_name ,
493
518
platform = tag .platform ,
519
+ marker = tag .marker ,
494
520
platform_tags = tag .platform_tags ,
495
521
want_abis = tag .want_abis ,
496
522
override = mod .is_root ,
@@ -823,6 +849,12 @@ Supported keys:
823
849
::::{note}
824
850
This is only used if the {envvar}`RULES_PYTHON_ENABLE_PIPSTAR` is enabled.
825
851
::::
852
+ """ ,
853
+ ),
854
+ "marker" : attr .string (
855
+ doc = """\
856
+ A marker which will be evaluated to disable the target platform for certain python versions. This
857
+ is especially useful when defining freethreaded platform variants.
826
858
""" ,
827
859
),
828
860
# The values for PEP508 env marker evaluation during the lock file parsing
0 commit comments