Skip to content

Commit 431bdba

Browse files
committed
yank: do not ignore
1 parent 36121e9 commit 431bdba

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

python/private/parse_requirements_add_dists.bzl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ by the parse_requirements function.
1818
1919
TODO @aignas 2024-05-23: The name is up for bikeshedding. For the time being I
2020
am keeping it together with parse_requirements.bzl.
21+
22+
TODO @aignas 2024-05-30: add unit tests.
2123
"""
2224

2325
load(":whl_target_platforms.bzl", "select_whls")
2426

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
2633
"""Populate dists based on the information from the PyPI index.
2734
2835
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
3138
requirements_by_platform: The result of parse_requirements function.
3239
index_urls: The result of simpleapi_download.
3340
python_version: The version of the python interpreter.
41+
warn: A function for printing warnings.
3442
"""
3543
for whl_name, requirements in requirements_by_platform.items():
3644
for requirement in requirements:
@@ -41,21 +49,33 @@ def parse_requirements_add_dists(requirements_by_platform, index_urls, python_ve
4149
# requirements by version instead of by sha256. This may be useful
4250
# for some projects.
4351
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-
4852
maybe_whl = index_urls[whl_name].whls.get(sha256)
49-
if maybe_whl and not maybe_whl.yanked:
53+
if maybe_whl:
5054
whls.append(maybe_whl)
5155
continue
5256

5357
maybe_sdist = index_urls[whl_name].sdists.get(sha256)
54-
if maybe_sdist and not maybe_sdist.yanked:
58+
if maybe_sdist:
5559
sdist = maybe_sdist
5660
continue
5761

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+
]))
5979

6080
# Filter out the wheels that are incompatible with the target_platforms.
6181
whls = select_whls(

0 commit comments

Comments
 (0)