Skip to content

Commit 38b5b6c

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 684cb94 commit 38b5b6c

File tree

3 files changed

+240
-11
lines changed

3 files changed

+240
-11
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.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
docker
22
jinja2
33
jsonschema
4+
PyGithub
45
PyYAML
56
# Undeclared dependency in docker 5.0 package.
67
six

0 commit comments

Comments
 (0)