@@ -18,11 +18,18 @@ by the parse_requirements function.
18
18
19
19
TODO @aignas 2024-05-23: The name is up for bikeshedding. For the time being I
20
20
am keeping it together with parse_requirements.bzl.
21
+
22
+ TODO @aignas 2024-05-30: add unit tests.
21
23
"""
22
24
23
25
load (":whl_target_platforms.bzl" , "select_whls" )
24
26
25
- def parse_requirements_add_dists (requirements_by_platform , index_urls , python_version ):
27
+ def parse_requirements_add_dists (
28
+ requirements_by_platform ,
29
+ index_urls ,
30
+ python_version ,
31
+ * ,
32
+ warn = lambda msg : print ("[WARNING] {}" .format (msg ))): # buildifier: disable=print
26
33
"""Populate dists based on the information from the PyPI index.
27
34
28
35
This function will modify the given requirements_by_platform data structure.
@@ -31,6 +38,7 @@ def parse_requirements_add_dists(requirements_by_platform, index_urls, python_ve
31
38
requirements_by_platform: The result of parse_requirements function.
32
39
index_urls: The result of simpleapi_download.
33
40
python_version: The version of the python interpreter.
41
+ warn: A function for printing warnings.
34
42
"""
35
43
for whl_name , requirements in requirements_by_platform .items ():
36
44
for requirement in requirements :
@@ -41,21 +49,33 @@ def parse_requirements_add_dists(requirements_by_platform, index_urls, python_ve
41
49
# requirements by version instead of by sha256. This may be useful
42
50
# for some projects.
43
51
for sha256 in requirement .srcs .shas :
44
- # For now if the artifact is marked as yanked we just ignore it.
45
- #
46
- # See https://packaging.python.org/en/latest/specifications/simple-repository-api/#adding-yank-support-to-the-simple-api
47
-
48
52
maybe_whl = index_urls [whl_name ].whls .get (sha256 )
49
- if maybe_whl and not maybe_whl . yanked :
53
+ if maybe_whl :
50
54
whls .append (maybe_whl )
51
55
continue
52
56
53
57
maybe_sdist = index_urls [whl_name ].sdists .get (sha256 )
54
- if maybe_sdist and not maybe_sdist . yanked :
58
+ if maybe_sdist :
55
59
sdist = maybe_sdist
56
60
continue
57
61
58
- print ("WARNING: Could not find a whl or an sdist with sha256={}" .format (sha256 )) # buildifier: disable=print
62
+ warn ("Could not find a whl or an sdist with sha256={}" .format (sha256 ))
63
+
64
+ # For now if the artifact is marked as yanked we print a warning
65
+ # which is similar what uv is doing.
66
+ #
67
+ # See https://packaging.python.org/en/latest/specifications/simple-repository-api/#adding-yank-support-to-the-simple-api
68
+ yanked = {}
69
+ for dist in whls + [sdist ]:
70
+ if dist .yanked :
71
+ yanked .setdefault (dist .yanked , []).append (dist .filename )
72
+ if yanked :
73
+ warn ("\n " .join ([
74
+ "the following distributions got yanked:" ,
75
+ ] + [
76
+ "reason: {}\n {}" .format (reason , "\n " .join (sorted (dists )))
77
+ for reason , dists in yanked .items ()
78
+ ]))
59
79
60
80
# Filter out the wheels that are incompatible with the target_platforms.
61
81
whls = select_whls (
0 commit comments