|
1 | 1 | import os |
2 | 2 | import re |
3 | 3 | import time |
4 | | -from typing import Dict, List |
| 4 | +from typing import Dict, List, NamedTuple |
5 | 5 | from urllib.parse import urljoin |
6 | 6 |
|
7 | 7 | import boto3 # type: ignore[import-untyped] |
|
919 | 919 | } |
920 | 920 |
|
921 | 921 |
|
| 922 | +class RetainedWheel(NamedTuple): |
| 923 | + filename: str |
| 924 | + url: str |
| 925 | + sha256: str |
| 926 | + |
| 927 | + |
| 928 | +# Wheels that download.pytorch.org still hosts but the upstream simple index has |
| 929 | +# stopped publishing, so mirroring alone drops them and pinned installs stop |
| 930 | +# resolving. Keyed by normalised package name. |
| 931 | +# |
| 932 | +# Only the channel root is injected: manage_v2.py copies a root package index |
| 933 | +# down into every accepted subdirectory for packages in its |
| 934 | +# PACKAGE_LINKS_ALLOW_LIST, so the CUDA targets inherit these links without |
| 935 | +# their conserved indexes being re-mirrored from upstream. |
| 936 | +RETAINED_WHEEL_PREFIXES = {"whl/nightly", "whl/test", "whl"} |
| 937 | +RETAINED_WHEELS: Dict[str, List[RetainedWheel]] = { |
| 938 | + "nvidia_cudnn_cu12": [ |
| 939 | + # Pinned by every torch 2.4.0-2.6.0 build; removed from pypi.nvidia.com |
| 940 | + # around 2026-08-12. See pytorch/pytorch#193491. |
| 941 | + RetainedWheel( |
| 942 | + filename="nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl", |
| 943 | + url=( |
| 944 | + "https://download.pytorch.org/whl/cu124/" |
| 945 | + "nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl" |
| 946 | + ), |
| 947 | + sha256="165764f44ef8c61fcdfdfdbe769d687e06374059fbb388b6c89ecb0e28793a6f", |
| 948 | + ), |
| 949 | + ], |
| 950 | +} |
| 951 | + |
| 952 | + |
922 | 953 | def is_nvidia_package(pkg_name: str) -> bool: |
923 | 954 | """Check if a package is from NVIDIA and is therefore CUDA-target only""" |
924 | 955 | return pkg_name.startswith("nvidia-") or pkg_name.startswith("cuda-") |
@@ -1136,6 +1167,36 @@ def append_preview_numpy_wheels(html: str, pkg_name: str, prefix: str) -> str: |
1136 | 1167 | return f"{html}\n{block}\n" |
1137 | 1168 |
|
1138 | 1169 |
|
| 1170 | +def append_retained_wheels(html: str, pkg_name: str, prefix: str) -> str: |
| 1171 | + """Merge :data:`RETAINED_WHEELS` links for *pkg_name* into *html*. |
| 1172 | +
|
| 1173 | + Limited to the channel roots in :data:`RETAINED_WHEEL_PREFIXES`. Wheels the |
| 1174 | + upstream index still lists are skipped, so this becomes a no-op if a version |
| 1175 | + is ever restored upstream. |
| 1176 | + """ |
| 1177 | + entries = RETAINED_WHEELS.get(normalize_pkg_name(pkg_name)) |
| 1178 | + if not entries or prefix not in RETAINED_WHEEL_PREFIXES: |
| 1179 | + return html |
| 1180 | + |
| 1181 | + additions = [ |
| 1182 | + f' <a href="{entry.url}#sha256={entry.sha256}">{entry.filename}</a><br/>' |
| 1183 | + for entry in entries |
| 1184 | + if entry.filename not in html |
| 1185 | + ] |
| 1186 | + |
| 1187 | + if not additions: |
| 1188 | + return html |
| 1189 | + |
| 1190 | + print( |
| 1191 | + f"INFO: Merging {len(additions)} retained wheel link(s) " |
| 1192 | + f"for {pkg_name} under {prefix}" |
| 1193 | + ) |
| 1194 | + block = "\n".join(additions) |
| 1195 | + if "</body>" in html: |
| 1196 | + return html.replace("</body>", f"{block}\n </body>", 1) |
| 1197 | + return f"{html}\n{block}\n" |
| 1198 | + |
| 1199 | + |
1139 | 1200 | def upload_package_using_simple_index( |
1140 | 1201 | pkg_name: str, |
1141 | 1202 | prefix: str, |
@@ -1168,6 +1229,9 @@ def upload_package_using_simple_index( |
1168 | 1229 | # published on the scientific-python nightly wheelhouse so pip can resolve them. |
1169 | 1230 | raw_html = append_preview_numpy_wheels(raw_html, pkg_name, prefix) |
1170 | 1231 |
|
| 1232 | + # Re-add wheels we still host that upstream has stopped publishing. |
| 1233 | + raw_html = append_retained_wheels(raw_html, pkg_name, prefix) |
| 1234 | + |
1171 | 1235 | # Upload modified index.html with absolute links |
1172 | 1236 | upload_index_html(pkg_name, prefix, raw_html, source_url, dry_run=dry_run) |
1173 | 1237 |
|
|
0 commit comments