|
7 | 7 | from __future__ import annotations |
8 | 8 |
|
9 | 9 | import argparse |
| 10 | +import json |
10 | 11 | import shutil |
11 | 12 | import sys |
| 13 | +import urllib.request |
12 | 14 | from pathlib import Path |
13 | 15 | from typing import TYPE_CHECKING |
14 | 16 |
|
@@ -312,15 +314,23 @@ def vendor_pyproject_metadata(session: nox.Session) -> None: |
312 | 314 | parser.add_argument("version", help="A tag or ref to vendor") |
313 | 315 | args = parser.parse_args(session.posargs) |
314 | 316 |
|
315 | | - session.run( |
316 | | - "curl", |
317 | | - "-o", |
318 | | - "src/scikit_build_core/_vendor/pyproject_metadata/__init__.py", |
319 | | - f"https://raw.githubusercontent.com/pypa/pyproject-metadata/{args.version}/pyproject_metadata/__init__.py", |
320 | | - ) |
321 | | - session.run( |
322 | | - "curl", |
323 | | - "-o", |
324 | | - "src/scikit_build_core/_vendor/pyproject_metadata/LICENSE", |
325 | | - f"https://raw.githubusercontent.com/pypa/pyproject-metadata/{args.version}/LICENSE", |
326 | | - ) |
| 317 | + repo = "pypa/pyproject-metadata" |
| 318 | + branch = args.version |
| 319 | + |
| 320 | + with urllib.request.urlopen( |
| 321 | + f"https://api.github.com/repos/{repo}/git/trees/{branch}?recursive=1" |
| 322 | + ) as response: |
| 323 | + info = json.loads(response.read().decode("utf-8")) |
| 324 | + |
| 325 | + files = { |
| 326 | + y: y for x in info["tree"] if (y := x["path"]).startswith("pyproject_metadata/") |
| 327 | + } |
| 328 | + files["pyproject_metadata/LICENSE"] = "LICENSE" |
| 329 | + for tgt_path, remote_path in files.items(): |
| 330 | + local_path = Path("src/scikit_build_core/_vendor").joinpath(tgt_path) |
| 331 | + print(f"Vendoring: {remote_path} -> {local_path}") |
| 332 | + with urllib.request.urlopen( |
| 333 | + f"https://raw.githubusercontent.com/{repo}/{branch}/{remote_path}" |
| 334 | + ) as response: |
| 335 | + txt = response.read() |
| 336 | + local_path.write_bytes(txt) |
0 commit comments