Skip to content

Commit 84e8090

Browse files
committed
pythonbuild: support more download statistics slicing
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.
1 parent 82a038f commit 84e8090

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

Justfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,25 @@ release token commit tag:
6666
just release-upload-distributions {{token}} ${datetime} {{tag}}
6767
just release-set-latest-release {{tag}}
6868

69+
_download-stats mode:
70+
build/venv.*/bin/python3 -c 'import pythonbuild.utils as u; u.release_download_statistics(mode="{{mode}}")'
71+
72+
# Show download counts of every release asset.
6973
download-stats:
70-
build/venv.*/bin/python3 -c 'import pythonbuild.utils as u; u.release_download_statistics()'
74+
just _download-stats by_asset
75+
76+
# Show download counts of release assets by build configuration.
77+
download-stats-by-build:
78+
just _download-stats by_build
79+
80+
# Show download counts of "install only" release assets by build configuration.
81+
download-stats-by-build-install-only:
82+
just _download-stats by_build_install_only
83+
84+
# Show download counts of release assets by release tag.
85+
download-stats-by-tag:
86+
just _download-stats by_tag
87+
88+
# Show a total count of all release asset downloads.
89+
download-stats-total:
90+
just _download-stats total

pythonbuild/utils.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
import collections
56
import gzip
67
import hashlib
78
import http.client
@@ -579,14 +580,49 @@ def validate_python_json(info, extension_modules):
579580
)
580581

581582

582-
def release_download_statistics():
583+
def release_download_statistics(mode="by_asset"):
583584
with urllib.request.urlopen(
584585
"https://api.github.com/repos/indygreg/python-build-standalone/releases"
585586
) as fh:
586587
data = json.load(fh)
587588

589+
by_tag = collections.Counter()
590+
by_build = collections.Counter()
591+
by_build_install_only = collections.Counter()
592+
588593
for release in data:
589594
tag = release["tag_name"]
590595

591596
for asset in release["assets"]:
592-
print("%d\t%s\t%s" % (asset["download_count"], tag, asset["name"]))
597+
name = asset["name"]
598+
count = asset["download_count"]
599+
600+
by_tag[tag] += count
601+
602+
if name.endswith(".tar.zst"):
603+
# cpython-3.10.2-aarch64-apple-darwin-debug-20220220T1113.tar.zst
604+
build_parts = name.split("-")
605+
build = "-".join(build_parts[2:-1])
606+
by_build[build] += count
607+
elif name.endswith("install_only.tar.gz"):
608+
# cpython-3.10.13+20240224-x86_64-apple-darwin-install_only.tar.gz
609+
build_parts = name.split("-")
610+
build = "-".join(build_parts[2:-1])
611+
by_build_install_only[build] += count
612+
613+
if mode == "by_asset":
614+
print("%d\t%s\t%s" % (count, tag, name))
615+
616+
if mode == "by_build":
617+
for build, count in sorted(by_build.items()):
618+
print("%d\t%s" % (count, build))
619+
elif mode == "by_build_install_only":
620+
for build, count in sorted(by_build_install_only.items()):
621+
print("%d\t%s" % (count, build))
622+
elif mode == "by_tag":
623+
for tag, count in sorted(by_tag.items()):
624+
print("%d\t%s"% (count, tag))
625+
elif mode == "total":
626+
print("%d" % by_tag.total())
627+
else:
628+
raise Exception("unhandled display mode: %s" % mode)

0 commit comments

Comments
 (0)