Skip to content

Commit e516742

Browse files
authored
Merge pull request #386 from FoamyGuy/report_updates
Remove pypi DL counts. Add library count for adafruit and community
2 parents d9386e4 + 6528983 commit e516742

File tree

1 file changed

+15
-77
lines changed

1 file changed

+15
-77
lines changed

adabot/circuitpython_libraries.py

+15-77
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import os
1313
import re
1414
import sys
15-
import time
1615
import traceback
1716

1817
import github as pygithub
18+
import requests
1919

2020
from adabot import github_requests as gh_reqs
2121
from adabot import pypi_requests as pypi
@@ -219,52 +219,20 @@ def run_library_checks(validators, kw_args, error_depth):
219219
# - Release asset delivery is being moved to AWS CloudFront/S3
220220
# print_circuitpython_dl_stats()
221221

222-
# Get PyPI stats
223-
have_secrets = False
224-
while True:
225-
try:
226-
ada_bundle = GH_INTERFACE.get_repo("adafruit/Adafruit_CircuitPython_Bundle")
227-
file_contents = ada_bundle.get_contents(
228-
"circuitpython_library_pypi_stats.md"
229-
)
230-
stats_contents = file_contents.decoded_content.decode("utf-8").split("\n")
231-
lib_stats = {}
232-
total_library_pypi_stats = 0
233-
blinka_pypi_downloads = 0
234-
in_lib_stats = False
235-
for line in stats_contents:
236-
line = line.strip()
237-
if not line:
238-
continue
239-
if line.startswith("| Adafruit Blinka (adafruit-blinka) |"):
240-
blinka_pypi_downloads = int(line[38:-2])
241-
continue
242-
if line.startswith(
243-
"**Total PyPI library downloads in the last 7 days:"
244-
):
245-
total_library_pypi_stats = int(line[51:-2])
246-
continue
247-
if line.startswith("|"):
248-
parts = [part.strip() for part in line.split("|") if part.strip()]
249-
if parts[0] in ("Library (PyPI Package)", "---"):
250-
in_lib_stats = True
251-
continue
252-
if in_lib_stats:
253-
lib_stats[parts[0]] = int(parts[1][:-10])
254-
else:
255-
in_lib_stats = False
256-
have_secrets = True
257-
break
258-
except pygithub.RateLimitExceededException:
259-
core_rate_limit_reset = GH_INTERFACE.get_rate_limit().core.reset
260-
sleep_time = core_rate_limit_reset - datetime.datetime.utcnow()
261-
logging.warning("Rate Limit will reset at: %s", core_rate_limit_reset)
262-
time.sleep(sleep_time.seconds)
263-
continue
264-
except pygithub.GithubException:
265-
break
266-
267222
logger.info("### Libraries")
223+
# Bundle library counts
224+
resp = requests.get(
225+
"https://raw.githubusercontent.com/adafruit/"
226+
"CircuitPython_Community_Bundle/main/.gitmodules",
227+
timeout=30,
228+
)
229+
community_bundle_submodules = resp.text
230+
community_library_count = community_bundle_submodules.count("submodule")
231+
logger.info(
232+
"* Adafruit Libraries: %s Community Libraries: %s",
233+
len(bundle_submodules),
234+
community_library_count,
235+
)
268236
print_pr_overview(lib_insights)
269237
logger.info(" * Merged pull requests:")
270238
sorted_prs = sorted(
@@ -296,29 +264,6 @@ def run_library_checks(validators, kw_args, error_depth):
296264
logger.info("* https://circuitpython.org/contributing")
297265

298266
logger.info("")
299-
logger.info("#### Library PyPI Weekly Download Stats")
300-
# if pypi_stats:
301-
if have_secrets:
302-
logger.info("* **Total Library Stats**")
303-
logger.info(
304-
" * %d PyPI downloads over %d libraries",
305-
total_library_pypi_stats,
306-
len(lib_stats),
307-
)
308-
logger.info("* **Top 10 Libraries by PyPI Downloads**")
309-
for index, (lib_stat_name, lib_stat_dl) in enumerate(lib_stats.items()):
310-
if index == 10:
311-
break
312-
logger.info(
313-
" * %s: %d",
314-
lib_stat_name,
315-
lib_stat_dl,
316-
)
317-
else:
318-
logger.info(
319-
"Secrets unavailable, cannot report PyPI download stats for libraries"
320-
)
321-
logger.info("*This is normal for CI runs from PRs*")
322267

323268
new_libs, updated_libs = bundle_announcer.get_adafruit_bundle_updates()
324269
(
@@ -381,14 +326,7 @@ def run_library_checks(validators, kw_args, error_depth):
381326
.get("adafruit-blinka", {})
382327
.get("month", "N/A")
383328
)
384-
if have_secrets:
385-
logger.info(
386-
"* PyPI downloads in the last week: %d",
387-
blinka_pypi_downloads,
388-
)
389-
else:
390-
logger.info("Secrets unavailable, cannot report PyPI download stats for Blinka")
391-
logger.info("*This is normal for CI runs from PRs*")
329+
392330
logger.info("* Piwheels Downloads in the last month: %s", blinka_dl)
393331
logger.info("Number of supported boards: %s", blinka_funcs.board_count())
394332

0 commit comments

Comments
 (0)