@@ -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,15 @@ 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
+ abi = abi ,
94
+ os_name = values .os_name ,
95
+ arch_name = values .arch_name ,
88
96
want_abis = [
89
97
v .format (* python_version .split ("." ))
90
98
for v in values .want_abis
@@ -190,17 +198,19 @@ def _create_whl_repos(
190
198
whl_group_mapping = {}
191
199
requirement_cycles = {}
192
200
201
+ platforms = _platforms (
202
+ python_version = pip_attr .python_version ,
203
+ minor_mapping = minor_mapping ,
204
+ config = config ,
205
+ )
206
+
193
207
if evaluate_markers :
194
208
# This is most likely unit tests
195
209
pass
196
210
elif config .enable_pipstar :
197
211
evaluate_markers = lambda _ , requirements : evaluate_markers_star (
198
212
requirements = requirements ,
199
- platforms = _platforms (
200
- python_version = pip_attr .python_version ,
201
- minor_mapping = minor_mapping ,
202
- config = config ,
203
- ),
213
+ platforms = platforms ,
204
214
)
205
215
else :
206
216
# NOTE @aignas 2024-08-02: , we will execute any interpreter that we find either
@@ -219,7 +229,18 @@ def _create_whl_repos(
219
229
# spin up a Python interpreter.
220
230
evaluate_markers = lambda module_ctx , requirements : evaluate_markers_py (
221
231
module_ctx ,
222
- requirements = requirements ,
232
+ requirements = {
233
+ k : {
234
+ # TODO @aignas 2025-07-06: should we leave this as is?
235
+ p : "{abi}_{os}_{cpu}" .format (
236
+ abi = platforms [p ].abi ,
237
+ os = platforms [p ].os_name ,
238
+ cpu = platforms [p ].arch_name ,
239
+ )
240
+ for p in plats
241
+ }
242
+ for k , plats in requirements .items ()
243
+ },
223
244
python_interpreter = pip_attr .python_interpreter ,
224
245
python_interpreter_target = python_interpreter_target ,
225
246
srcs = pip_attr ._evaluate_markers_srcs ,
@@ -235,18 +256,14 @@ def _create_whl_repos(
235
256
requirements_osx = pip_attr .requirements_darwin ,
236
257
requirements_windows = pip_attr .requirements_windows ,
237
258
extra_pip_args = pip_attr .extra_pip_args ,
238
- platforms = sorted (config . platforms ), # here we only need keys
259
+ platforms = sorted (platforms ), # here we only need keys
239
260
python_version = full_version (
240
261
version = pip_attr .python_version ,
241
262
minor_mapping = minor_mapping ,
242
263
),
243
264
logger = logger ,
244
265
),
245
- platforms = _platforms (
246
- python_version = pip_attr .python_version ,
247
- minor_mapping = minor_mapping ,
248
- config = config ,
249
- ),
266
+ platforms = platforms ,
250
267
extra_pip_args = pip_attr .extra_pip_args ,
251
268
get_index_urls = get_index_urls ,
252
269
evaluate_markers = evaluate_markers ,
@@ -385,7 +402,7 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
385
402
),
386
403
)
387
404
388
- def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , override = False ):
405
+ def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , marker , override = False ):
389
406
"""Set the value in the config if the value is provided"""
390
407
config .setdefault ("platforms" , {})
391
408
if platform and (os_name or arch_name or config_settings or platform_tags or env ):
@@ -406,21 +423,25 @@ def _configure(config, *, platform, os_name, arch_name, config_settings, env = {
406
423
# the lowest priority one needs to be the first one
407
424
platform_tags = ["any" ] + platform_tags
408
425
426
+ want_abis = want_abis or [
427
+ "cp{0}{1}" ,
428
+ "abi3" ,
429
+ "none" ,
430
+ ]
431
+ env = {
432
+ # default to this
433
+ "implementation_name" : "cpython" ,
434
+ } | env
435
+
409
436
config ["platforms" ][platform ] = struct (
410
437
name = platform .replace ("-" , "_" ).lower (),
411
- os_name = os_name ,
412
438
arch_name = arch_name ,
413
439
config_settings = config_settings ,
414
- want_abis = want_abis or [
415
- "cp{0}{1}" ,
416
- "abi3" ,
417
- "none" ,
418
- ],
440
+ env = env ,
441
+ marker = marker ,
442
+ os_name = os_name ,
419
443
platform_tags = platform_tags ,
420
- env = {
421
- # default to this
422
- "implementation_name" : "cpython" ,
423
- } | env ,
444
+ want_abis = want_abis ,
424
445
)
425
446
else :
426
447
config ["platforms" ].pop (platform )
@@ -491,6 +512,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
491
512
env = tag .env ,
492
513
os_name = tag .os_name ,
493
514
platform = tag .platform ,
515
+ marker = tag .marker ,
494
516
platform_tags = tag .platform_tags ,
495
517
want_abis = tag .want_abis ,
496
518
override = mod .is_root ,
@@ -823,6 +845,12 @@ Supported keys:
823
845
::::{note}
824
846
This is only used if the {envvar}`RULES_PYTHON_ENABLE_PIPSTAR` is enabled.
825
847
::::
848
+ """ ,
849
+ ),
850
+ "marker" : attr .string (
851
+ doc = """\
852
+ A marker which will be evaluated to disable the target platform for certain python versions. This
853
+ is especially useful when defining freethreaded platform variants.
826
854
""" ,
827
855
),
828
856
# The values for PEP508 env marker evaluation during the lock file parsing
0 commit comments