@@ -327,17 +327,14 @@ def multiplatform_whl_aliases(*, aliases, default_version, **kwargs):
327
327
A dict with aliases to be used in the hub repo.
328
328
"""
329
329
330
- # TODO @aignas 2024-05-27: add unit tests
331
330
ret = []
332
- defaults = {}
331
+ versioned_additions = {}
333
332
for alias in aliases :
334
333
if not alias .filename :
335
334
ret .append (alias )
336
335
continue
337
336
338
- # TODO @aignas 2024-05-30: we need to segment the versions so that we
339
- # don't have duplicates
340
- config_settings , filename_defaults = get_filename_config_settings (
337
+ config_settings , all_versioned_settings = get_filename_config_settings (
341
338
# TODO @aignas 2024-05-27: pass the parsed whl to reduce the
342
339
# number of duplicate operations
343
340
filename = alias .filename ,
@@ -353,20 +350,53 @@ def multiplatform_whl_aliases(*, aliases, default_version, **kwargs):
353
350
version = alias .version ,
354
351
config_setting = "//_config" + setting ,
355
352
))
356
- for setting , version in filename_defaults .items ():
357
- a = whl_alias (
353
+
354
+ # Now for the versioned platform config settings, we need to select one
355
+ # that best fits the bill and if there are multiple wheels, e.g.
356
+ # manylinux_2_17_x86_64 and manylinux_2_28_x86_64, then we need to select
357
+ # the former when the glibc is in the range of [2.17, 2.28) and then chose
358
+ # the later if it is [2.28, ...). If the 2.28 wheel was not present in
359
+ # the hub, then we would need to use 2.17 for all the glibc version
360
+ # configurations.
361
+ #
362
+ # Here we add the version settings to a dict where we key the range of
363
+ # versions that the whl spans. If the wheel supports musl and glibc at
364
+ # the same time, we do this for each supported platform, hence the
365
+ # double dict.
366
+ for default_setting , versioned in all_versioned_settings .items ():
367
+ versions = sorted (versioned )
368
+ min_version = versions [0 ]
369
+ max_version = versions [- 1 ]
370
+
371
+ versioned_additions .setdefault (default_setting , {})[(min_version , max_version )] = struct (
358
372
repo = alias .repo ,
359
- version = alias .version ,
360
- config_setting = "//_config" + setting ,
373
+ python_version = alias .version ,
374
+ settings = versioned ,
361
375
)
362
- _ , has_version = defaults .setdefault (setting , (a , version ))
363
- if has_version > version :
364
- defaults [a ] = (a , version )
365
-
366
- ret .extend ([
367
- a
368
- for (a , _ ) in defaults .values ()
369
- ])
376
+
377
+ versioned = {}
378
+ for default_setting , candidates in versioned_additions .items ():
379
+ # Sort the candidates by the range of versions the span, so that we
380
+ # start with the lowest version.
381
+ for _ , candidate in sorted (candidates .items ()):
382
+ # Set the default with the first candidate, which gives us the highest
383
+ # compatibility. If the users want to use a higher-version than the default
384
+ # they can configure the glibc_version flag.
385
+ versioned .setdefault (default_setting , whl_alias (
386
+ version = candidate .python_version ,
387
+ config_setting = "//_config" + default_setting ,
388
+ repo = candidate .repo ,
389
+ ))
390
+
391
+ # We will be overwriting previously added entries, but that is intended.
392
+ for _ , setting in sorted (candidate .settings .items ()):
393
+ versioned [setting ] = whl_alias (
394
+ version = candidate .python_version ,
395
+ config_setting = "//_config" + setting ,
396
+ repo = candidate .repo ,
397
+ )
398
+
399
+ ret .extend (versioned .values ())
370
400
return ret
371
401
372
402
def _render_pip_config_settings (python_versions , target_platforms = [], osx_versions = [], glibc_versions = [], muslc_versions = []):
@@ -496,7 +526,7 @@ def get_filename_config_settings(
496
526
glibc_versions = sorted (glibc_versions )
497
527
muslc_versions = sorted (muslc_versions )
498
528
osx_versions = sorted (osx_versions )
499
- default_version_settings = {}
529
+ setting_supported_versions = {}
500
530
501
531
if filename .endswith (".whl" ):
502
532
parsed = parse_whl_name (filename )
@@ -522,7 +552,7 @@ def get_filename_config_settings(
522
552
glibc_versions = glibc_versions ,
523
553
muslc_versions = muslc_versions ,
524
554
osx_versions = osx_versions ,
525
- default_version_settings = default_version_settings ,
555
+ setting_supported_versions = setting_supported_versions ,
526
556
)
527
557
else :
528
558
prefixes = ["sdist" ]
@@ -537,21 +567,26 @@ def get_filename_config_settings(
537
567
else :
538
568
fail ("BUG: got no python_version and it is not default" )
539
569
540
- if suffixes :
541
- return [":is_{}_{}" .format (p , s ) for p in prefixes for s in suffixes ], {
542
- ":is_{}_{}" .format (p , suffix ): version
543
- for p in prefixes
544
- for suffix , version in default_version_settings .items ()
570
+ versioned = {
571
+ ":is_{}_{}" .format (p , suffix ): {
572
+ version : ":is_{}_{}" .format (p , setting )
573
+ for version , setting in versions .items ()
545
574
}
575
+ for p in prefixes
576
+ for suffix , versions in setting_supported_versions .items ()
577
+ }
578
+
579
+ if suffixes or versioned :
580
+ return [":is_{}_{}" .format (p , s ) for p in prefixes for s in suffixes ], versioned
546
581
else :
547
- return [":is_{}" .format (p ) for p in prefixes ], default_version_settings
582
+ return [":is_{}" .format (p ) for p in prefixes ], setting_supported_versions
548
583
549
584
def _whl_config_setting_sufixes (
550
585
platform_tag ,
551
586
glibc_versions ,
552
587
muslc_versions ,
553
588
osx_versions ,
554
- default_version_settings ):
589
+ setting_supported_versions ):
555
590
suffixes = []
556
591
for platform_tag in platform_tag .split ("." ):
557
592
for p in whl_target_platforms (platform_tag ):
@@ -573,20 +608,18 @@ def _whl_config_setting_sufixes(
573
608
fail ("Unsupported whl os: {}" .format (p .os ))
574
609
575
610
default_version_setting = "{}_{}" .format (prefix , suffix )
576
- min_version = default_version_settings . get ( default_version_setting )
611
+ supported_versions = {}
577
612
for v in versions :
578
613
if v == (0 , 0 ):
579
614
suffixes .append (default_version_setting )
580
615
elif v >= p .version :
581
- if not min_version or min_version > v :
582
- min_version = v
583
- suffixes .append ("{}_{}_{}_{}" .format (
616
+ supported_versions [v ] = "{}_{}_{}_{}" .format (
584
617
prefix ,
585
618
v [0 ],
586
619
v [1 ],
587
620
suffix ,
588
- ))
589
- if min_version :
590
- default_version_settings [default_version_setting ] = min_version
621
+ )
622
+ if supported_versions :
623
+ setting_supported_versions [default_version_setting ] = supported_versions
591
624
592
625
return suffixes
0 commit comments