|
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] |
|
227 | 227 | { |
228 | 228 | "project": "torch", |
229 | 229 | }, |
| 230 | + { |
| 231 | + "project": "torch", |
| 232 | + "target": "cu121", |
| 233 | + }, |
| 234 | + { |
| 235 | + "project": "torch", |
| 236 | + "target": "cu124", |
| 237 | + }, |
230 | 238 | { |
231 | 239 | "project": "torch", |
232 | 240 | "target": "cu126", |
|
919 | 927 | } |
920 | 928 |
|
921 | 929 |
|
| 930 | +class RetainedWheel(NamedTuple): |
| 931 | + filename: str |
| 932 | + url: str |
| 933 | + sha256: str |
| 934 | + targets: tuple[str, ...] |
| 935 | + |
| 936 | + |
| 937 | +# Wheels that download.pytorch.org still hosts but the upstream simple index has |
| 938 | +# stopped publishing, so mirroring alone drops them and pinned installs stop |
| 939 | +# resolving. Keyed by normalised package name; injected into the index for the |
| 940 | +# listed targets ("" is the channel root) on nightly, test and prod. |
| 941 | +RETAINED_WHEELS: Dict[str, List[RetainedWheel]] = { |
| 942 | + "nvidia_cudnn_cu12": [ |
| 943 | + RetainedWheel( |
| 944 | + filename="nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl", |
| 945 | + url=( |
| 946 | + "https://download.pytorch.org/whl/cu124/" |
| 947 | + "nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl" |
| 948 | + ), |
| 949 | + sha256="165764f44ef8c61fcdfdfdbe769d687e06374059fbb388b6c89ecb0e28793a6f", |
| 950 | + targets=("", "cu121", "cu124"), |
| 951 | + ), |
| 952 | + ], |
| 953 | +} |
| 954 | + |
| 955 | + |
922 | 956 | def is_nvidia_package(pkg_name: str) -> bool: |
923 | 957 | """Check if a package is from NVIDIA and is therefore CUDA-target only""" |
924 | 958 | return pkg_name.startswith("nvidia-") or pkg_name.startswith("cuda-") |
@@ -1136,6 +1170,39 @@ def append_preview_numpy_wheels(html: str, pkg_name: str, prefix: str) -> str: |
1136 | 1170 | return f"{html}\n{block}\n" |
1137 | 1171 |
|
1138 | 1172 |
|
| 1173 | +def append_retained_wheels(html: str, pkg_name: str, prefix: str) -> str: |
| 1174 | + """Merge :data:`RETAINED_WHEELS` links for *pkg_name* into *html*. |
| 1175 | +
|
| 1176 | + The target is the last segment of *prefix* ("whl/nightly/cu124" -> "cu124", |
| 1177 | + "whl/nightly" -> ""). Wheels the upstream index still lists are skipped, so |
| 1178 | + this becomes a no-op if a version is ever restored upstream. |
| 1179 | + """ |
| 1180 | + entries = RETAINED_WHEELS.get(normalize_pkg_name(pkg_name)) |
| 1181 | + if not entries: |
| 1182 | + return html |
| 1183 | + |
| 1184 | + last_segment = prefix.rsplit("/", 1)[-1] |
| 1185 | + target = last_segment if is_valid_target(last_segment) else "" |
| 1186 | + |
| 1187 | + additions = [ |
| 1188 | + f' <a href="{entry.url}#sha256={entry.sha256}">{entry.filename}</a><br/>' |
| 1189 | + for entry in entries |
| 1190 | + if target in entry.targets and entry.filename not in html |
| 1191 | + ] |
| 1192 | + |
| 1193 | + if not additions: |
| 1194 | + return html |
| 1195 | + |
| 1196 | + print( |
| 1197 | + f"INFO: Merging {len(additions)} retained wheel link(s) " |
| 1198 | + f"for {pkg_name} under {prefix}" |
| 1199 | + ) |
| 1200 | + block = "\n".join(additions) |
| 1201 | + if "</body>" in html: |
| 1202 | + return html.replace("</body>", f"{block}\n </body>", 1) |
| 1203 | + return f"{html}\n{block}\n" |
| 1204 | + |
| 1205 | + |
1139 | 1206 | def upload_package_using_simple_index( |
1140 | 1207 | pkg_name: str, |
1141 | 1208 | prefix: str, |
@@ -1168,6 +1235,9 @@ def upload_package_using_simple_index( |
1168 | 1235 | # published on the scientific-python nightly wheelhouse so pip can resolve them. |
1169 | 1236 | raw_html = append_preview_numpy_wheels(raw_html, pkg_name, prefix) |
1170 | 1237 |
|
| 1238 | + # Re-add wheels we still host that upstream has stopped publishing. |
| 1239 | + raw_html = append_retained_wheels(raw_html, pkg_name, prefix) |
| 1240 | + |
1171 | 1241 | # Upload modified index.html with absolute links |
1172 | 1242 | upload_index_html(pkg_name, prefix, raw_html, source_url, dry_run=dry_run) |
1173 | 1243 |
|
|
0 commit comments