Skip to content

Commit e8ef3a8

Browse files
committed
Fix download statistics
`just download-stats*` are failing with an HTTP 504 Gateway Timeout on GitHub's servers. We can work around this by reducing the requested number of releases per page. As part of this, we adopt a 3rd party package for querying the GitHub API because I was too lazy to implement pagination manually. Also, since pagination is enabled, the counts reported by these commands are now accurate and don't implicitly truncate at the most recent 10 releases.
1 parent cf3c7ea commit e8ef3a8

File tree

6 files changed

+728
-41
lines changed

6 files changed

+728
-41
lines changed

pythonbuild/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import urllib.request
2424
import zipfile
2525

26+
import github
2627
import yaml
2728
import zstandard
2829

@@ -653,21 +654,20 @@ def validate_python_json(info, extension_modules):
653654

654655

655656
def release_download_statistics(mode="by_asset"):
656-
with urllib.request.urlopen(
657-
"https://api.github.com/repos/astral-sh/python-build-standalone/releases"
658-
) as fh:
659-
data = json.load(fh)
660-
661657
by_tag = collections.Counter()
662658
by_build = collections.Counter()
663659
by_build_install_only = collections.Counter()
664660

665-
for release in data:
666-
tag = release["tag_name"]
661+
# Default paging settings time out. Reduce page size as a workaround.
662+
gh = github.Github(per_page=5)
663+
664+
repo = gh.get_repo("astral-sh/python-build-standalone")
665+
for release in repo.get_releases():
666+
tag = release.tag_name
667667

668-
for asset in release["assets"]:
669-
name = asset["name"]
670-
count = asset["download_count"]
668+
for asset in release.assets:
669+
name = asset.name
670+
count = asset.download_count
671671

672672
by_tag[tag] += count
673673

requirements.dev.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
ruff
44
mypy
5+
PyGithub
56
types-jsonschema
67
types-PyYAML
78
types-jinja2

0 commit comments

Comments
 (0)