Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions scripts/update_distributions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# /// script
# dependencies = [
# "httpx",
# "httpx2",
# "packaging",
# "rich",
# ]
# ///
import os
from collections import defaultdict
from contextlib import suppress
from itertools import count
from pathlib import Path
from urllib.parse import urlparse, parse_qs

import httpx
import httpx2
from rich.progress import Progress
from packaging.version import Version

RELEASES_URL = 'https://api.github.com/repos/astral-sh/python-build-standalone/releases'
Expand All @@ -30,16 +34,22 @@ def get_assets():

headers = {'Authorization': f'Bearer {token}', 'X-GitHub-Api-Version': '2022-11-28'}

page = 1
while True:
print(f'Fetching page {page}...')
response = httpx.get(RELEASES_URL, headers=headers, timeout=60, params={'page': page, 'per_page': 5})
progress = Progress()
task = progress.add_task("Updating distributions...")
progress.start()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop the manually started progress display

Starting Progress manually without a matching stop() leaves Rich's live display active when the generator finishes or raises, so running this script in an interactive terminal can leave the cursor hidden and terminal rendering state unrestored. Wrap the pagination loop in a with Progress() as progress: block or stop it in a finally clause.

Useful? React with 👍 / 👎.

for page in count(1):
response = httpx2.get(RELEASES_URL, headers=headers, timeout=60, params={'page': page, 'per_page': 5})
releases = response.json()
if not response.is_success:
import json

formatted = json.dumps(releases, indent=2)
raise httpx.NetworkError(formatted)
raise httpx2.NetworkError(formatted)

if last_link := response.links.get('last'):
query = parse_qs(urlparse(last_link['url']).query)
if last_page := next(iter(query.get('page', ())), None):
progress.update(task, total=int(last_page))

if not releases:
break
Expand All @@ -48,12 +58,9 @@ def get_assets():
for asset in release['assets']:
yield asset['name'], asset['browser_download_url']

page += 1

progress.advance(task, 1)

def main():
print('Updating distributions...')

lines = Path('build.rs').read_text('utf-8').splitlines()
start = end = -1
for i, line in enumerate(lines):
Expand Down Expand Up @@ -96,8 +103,8 @@ def main():
raw_version, _, release = release_data.partition('+')
version = Version(raw_version)

# Skip prereleases for now
if version.pre is not None:
# Skip non-rc prereleases for now
if version.pre is not None and version.pre[0] != "rc":
continue

variant_start = 3 if 'apple' in remaining else 4
Expand Down Expand Up @@ -141,7 +148,7 @@ def main():
arch = 'powerpc64'

distribution = (minor_version_parts, os_name, arch, abi, variant_cpu, variant_gil)
distributions[distribution].append((((version.major, Version.minor, version.micro), date), url))
distributions[distribution].append((((version.major, version.minor, version.micro), date), url))

flattened_distributions = defaultdict(list)
for (
Expand Down
Loading