mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Update fetch-version-metadata
to only require the stdlib (#2838)
This commit is contained in:
parent
c11e9e5097
commit
f0b0e1943c
1 changed files with 14 additions and 38 deletions
|
@ -4,13 +4,9 @@ Fetch Python version metadata.
|
||||||
|
|
||||||
Generates the bootstrap `versions.json` file.
|
Generates the bootstrap `versions.json` file.
|
||||||
|
|
||||||
Installation:
|
|
||||||
|
|
||||||
pip install requests==2.31.0
|
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
scripts/bootstrap/fetch-versions
|
python fetch-version-metadata.py
|
||||||
|
|
||||||
Acknowledgements:
|
Acknowledgements:
|
||||||
|
|
||||||
|
@ -22,19 +18,13 @@ import argparse
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import urllib.error
|
||||||
|
import urllib.request
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
try:
|
|
||||||
import requests
|
|
||||||
except ImportError:
|
|
||||||
print("ERROR: requests is required; install with `pip install requests==2.31.0`")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
SELF_DIR = Path(__file__).parent
|
SELF_DIR = Path(__file__).parent
|
||||||
RELEASE_URL = "https://api.github.com/repos/indygreg/python-build-standalone/releases"
|
RELEASE_URL = "https://api.github.com/repos/indygreg/python-build-standalone/releases"
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
|
@ -129,11 +119,13 @@ def normalize_triple(triple):
|
||||||
return "%s-%s-%s" % (arch, platform, libc)
|
return "%s-%s-%s" % (arch, platform, libc)
|
||||||
|
|
||||||
|
|
||||||
def read_sha256(session, url):
|
def read_sha256(url):
|
||||||
resp = session.get(url + ".sha256")
|
try:
|
||||||
if not resp.ok:
|
resp = urllib.request.urlopen(url + ".sha256")
|
||||||
|
except urllib.error.HTTPError:
|
||||||
return None
|
return None
|
||||||
return resp.text.strip()
|
assert resp.status == 200
|
||||||
|
return resp.read().strip()
|
||||||
|
|
||||||
|
|
||||||
def sha256(path):
|
def sha256(path):
|
||||||
|
@ -159,32 +151,16 @@ def _sort_key(info):
|
||||||
return pref
|
return pref
|
||||||
|
|
||||||
|
|
||||||
def get_session() -> requests.Session:
|
def find():
|
||||||
session = requests.Session()
|
|
||||||
session.headers = HEADERS.copy()
|
|
||||||
|
|
||||||
token = os.environ.get("GITHUB_TOKEN")
|
|
||||||
if token:
|
|
||||||
session.headers["Authorization"] = "Bearer " + token
|
|
||||||
else:
|
|
||||||
logging.warning(
|
|
||||||
"An authentication token was not found at `GITHUB_TOKEN`, rate limits may be encountered.",
|
|
||||||
)
|
|
||||||
|
|
||||||
return session
|
|
||||||
|
|
||||||
|
|
||||||
def find(args):
|
|
||||||
"""
|
"""
|
||||||
Find available Python versions and write metadata to a file.
|
Find available Python versions and write metadata to a file.
|
||||||
"""
|
"""
|
||||||
results = {}
|
results = {}
|
||||||
session = get_session()
|
|
||||||
|
|
||||||
for page in range(1, 100):
|
for page in range(1, 100):
|
||||||
logging.debug("Reading release page %s...", page)
|
logging.debug("Reading release page %s...", page)
|
||||||
resp = session.get("%s?page=%d" % (RELEASE_URL, page))
|
resp = urllib.request.urlopen("%s?page=%d" % (RELEASE_URL, page))
|
||||||
rows = resp.json()
|
rows = json.loads(resp.read())
|
||||||
if not rows:
|
if not rows:
|
||||||
break
|
break
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
@ -226,7 +202,7 @@ def find(args):
|
||||||
for (arch, platform, libc), url in sorted(choices.items()):
|
for (arch, platform, libc), url in sorted(choices.items()):
|
||||||
key = "%s-%s.%s.%s-%s-%s-%s" % (interpreter, *py_ver, platform, arch, libc)
|
key = "%s-%s.%s.%s-%s-%s-%s" % (interpreter, *py_ver, platform, arch, libc)
|
||||||
logging.info("Found %s", key)
|
logging.info("Found %s", key)
|
||||||
sha256 = read_sha256(session, url)
|
sha256 = read_sha256(url)
|
||||||
|
|
||||||
final_results[key] = {
|
final_results[key] = {
|
||||||
"name": interpreter,
|
"name": interpreter,
|
||||||
|
@ -273,7 +249,7 @@ def main():
|
||||||
datefmt="%Y-%m-%d %H:%M:%S",
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
)
|
)
|
||||||
|
|
||||||
find(args)
|
find()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue