@@ -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,17 @@ 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
+ p : "{abi}_{os}_{cpu}" .format (
235
+ abi = platforms [p ].abi ,
236
+ os = platforms [p ].os_name ,
237
+ cpu = platforms [p ].arch_name ,
238
+ )
239
+ for p in plats
240
+ }
241
+ for k , plats in requirements .items ()
242
+ },
223
243
python_interpreter = pip_attr .python_interpreter ,
224
244
python_interpreter_target = python_interpreter_target ,
225
245
srcs = pip_attr ._evaluate_markers_srcs ,
@@ -235,18 +255,14 @@ def _create_whl_repos(
235
255
requirements_osx = pip_attr .requirements_darwin ,
236
256
requirements_windows = pip_attr .requirements_windows ,
237
257
extra_pip_args = pip_attr .extra_pip_args ,
238
- platforms = sorted (config . platforms ), # here we only need keys
258
+ platforms = sorted (platforms ), # here we only need keys
239
259
python_version = full_version (
240
260
version = pip_attr .python_version ,
241
261
minor_mapping = minor_mapping ,
242
262
),
243
263
logger = logger ,
244
264
),
245
- platforms = _platforms (
246
- python_version = pip_attr .python_version ,
247
- minor_mapping = minor_mapping ,
248
- config = config ,
249
- ),
265
+ platforms = platforms ,
250
266
extra_pip_args = pip_attr .extra_pip_args ,
251
267
get_index_urls = get_index_urls ,
252
268
evaluate_markers = evaluate_markers ,
@@ -385,7 +401,7 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
385
401
),
386
402
)
387
403
388
- def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , override = False ):
404
+ def _configure (config , * , platform , os_name , arch_name , config_settings , env = {}, want_abis , platform_tags , marker , override = False ):
389
405
"""Set the value in the config if the value is provided"""
390
406
config .setdefault ("platforms" , {})
391
407
if platform and (os_name or arch_name or config_settings or platform_tags or env ):
@@ -406,21 +422,25 @@ def _configure(config, *, platform, os_name, arch_name, config_settings, env = {
406
422
# the lowest priority one needs to be the first one
407
423
platform_tags = ["any" ] + platform_tags
408
424
425
+ want_abis = want_abis or [
426
+ "cp{0}{1}" ,
427
+ "abi3" ,
428
+ "none" ,
429
+ ]
430
+ env = {
431
+ # default to this
432
+ "implementation_name" : "cpython" ,
433
+ } | env
434
+
409
435
config ["platforms" ][platform ] = struct (
410
436
name = platform .replace ("-" , "_" ).lower (),
411
- os_name = os_name ,
412
437
arch_name = arch_name ,
413
438
config_settings = config_settings ,
414
- want_abis = want_abis or [
415
- "cp{0}{1}" ,
416
- "abi3" ,
417
- "none" ,
418
- ],
439
+ env = env ,
440
+ marker = marker ,
441
+ os_name = os_name ,
419
442
platform_tags = platform_tags ,
420
- env = {
421
- # default to this
422
- "implementation_name" : "cpython" ,
423
- } | env ,
443
+ want_abis = want_abis ,
424
444
)
425
445
else :
426
446
config ["platforms" ].pop (platform )
@@ -491,6 +511,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
491
511
env = tag .env ,
492
512
os_name = tag .os_name ,
493
513
platform = tag .platform ,
514
+ marker = tag .marker ,
494
515
platform_tags = tag .platform_tags ,
495
516
want_abis = tag .want_abis ,
496
517
override = mod .is_root ,
@@ -823,6 +844,12 @@ Supported keys:
823
844
::::{note}
824
845
This is only used if the {envvar}`RULES_PYTHON_ENABLE_PIPSTAR` is enabled.
825
846
::::
847
+ """ ,
848
+ ),
849
+ "marker" : attr .string (
850
+ doc = """\
851
+ A marker which will be evaluated to disable the target platform for certain python versions. This
852
+ is especially useful when defining freethreaded platform variants.
826
853
""" ,
827
854
),
828
855
# The values for PEP508 env marker evaluation during the lock file parsing
0 commit comments