Skip to content

Commit

Permalink
pythonbuild: support more download statistics slicing
Browse files Browse the repository at this point in the history
I have a suspicion that some build configurations can be deleted
without externalizing much hardship. Let's support more display
formats of download statistics so we can dig into the data.
  • Loading branch information
indygreg committed Feb 28, 2024
1 parent 82a038f commit 84e8090
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
22 changes: 21 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,25 @@ release token commit tag:
just release-upload-distributions {{token}} ${datetime} {{tag}}
just release-set-latest-release {{tag}}

_download-stats mode:
build/venv.*/bin/python3 -c 'import pythonbuild.utils as u; u.release_download_statistics(mode="{{mode}}")'

# Show download counts of every release asset.
download-stats:
build/venv.*/bin/python3 -c 'import pythonbuild.utils as u; u.release_download_statistics()'
just _download-stats by_asset

# Show download counts of release assets by build configuration.
download-stats-by-build:
just _download-stats by_build

# Show download counts of "install only" release assets by build configuration.
download-stats-by-build-install-only:
just _download-stats by_build_install_only

# Show download counts of release assets by release tag.
download-stats-by-tag:
just _download-stats by_tag

# Show a total count of all release asset downloads.
download-stats-total:
just _download-stats total
40 changes: 38 additions & 2 deletions pythonbuild/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import collections
import gzip
import hashlib
import http.client
Expand Down Expand Up @@ -579,14 +580,49 @@ def validate_python_json(info, extension_modules):
)


def release_download_statistics():
def release_download_statistics(mode="by_asset"):
with urllib.request.urlopen(
"https://api.github.com/repos/indygreg/python-build-standalone/releases"
) as fh:
data = json.load(fh)

by_tag = collections.Counter()
by_build = collections.Counter()
by_build_install_only = collections.Counter()

for release in data:
tag = release["tag_name"]

for asset in release["assets"]:
print("%d\t%s\t%s" % (asset["download_count"], tag, asset["name"]))
name = asset["name"]
count = asset["download_count"]

by_tag[tag] += count

if name.endswith(".tar.zst"):
# cpython-3.10.2-aarch64-apple-darwin-debug-20220220T1113.tar.zst
build_parts = name.split("-")
build = "-".join(build_parts[2:-1])
by_build[build] += count
elif name.endswith("install_only.tar.gz"):
# cpython-3.10.13+20240224-x86_64-apple-darwin-install_only.tar.gz
build_parts = name.split("-")
build = "-".join(build_parts[2:-1])
by_build_install_only[build] += count

if mode == "by_asset":
print("%d\t%s\t%s" % (count, tag, name))

if mode == "by_build":
for build, count in sorted(by_build.items()):
print("%d\t%s" % (count, build))
elif mode == "by_build_install_only":
for build, count in sorted(by_build_install_only.items()):
print("%d\t%s" % (count, build))
elif mode == "by_tag":
for tag, count in sorted(by_tag.items()):
print("%d\t%s"% (count, tag))
elif mode == "total":
print("%d" % by_tag.total())
else:
raise Exception("unhandled display mode: %s" % mode)

0 comments on commit 84e8090

Please sign in to comment.