Skip to content

Commit 430d8ab

Browse files
authored
Merge pull request #81 from sommersoft/cp_org_lib
Add CP.org Libraries Update Script
2 parents f6d810a + aa9e98a commit 430d8ab

5 files changed

+327
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ _build
66
env.sh
77
*.swp
88
.libraries/*
9+
.cp_org/*

adabot/github_requests.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
2828
* Author(s): Scott Shawcroft
2929
"""
30-
import os
3130

31+
import datetime
32+
import os
3233
import requests
34+
import time
3335

3436

3537
def _fix_url(url):
@@ -58,6 +60,19 @@ def get(url, **kwargs):
5860
response = requests.get(_fix_url(url), timeout=30, **_fix_kwargs(kwargs))
5961
if "X-RateLimit-Remaining" in response.headers:
6062
remaining = int(response.headers["X-RateLimit-Remaining"])
63+
if remaining <= 1:
64+
rate_limit_reset = datetime.datetime.fromtimestamp(int(response.headers["X-RateLimit-Reset"]))
65+
print("GitHub API Rate Limit reached. Pausing until Rate Limit reset.")
66+
while datetime.datetime.now() < rate_limit_reset:
67+
print("Rate Limit will reset at: {}".format(rate_limit_reset))
68+
if "TRAVIS" in os.environ:
69+
# only pause for 5 minutes so that Travis doesn't timeout
70+
# due to idle console output.
71+
time.sleep(300)
72+
else:
73+
reset_diff = rate_limit_reset - datetime.datetime.now()
74+
print("Sleeping {} seconds".format(reset_diff.seconds))
75+
time.sleep(reset_diff.seconds)
6176
if remaining % 100 == 0:
6277
print(remaining, "requests remaining this hour")
6378
return response

adabot/lib/circuitpython_library_validators.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from adabot import github_requests as github
2828
from adabot import travis_requests as travis
2929
from adabot import pypi_requests as pypi
30-
from adabot.lib.common_funcs import *
30+
from adabot.lib import common_funcs
3131

3232

3333
# Define constants for error strings to make checking against them more robust:
@@ -169,7 +169,7 @@ def validate_repo_state(self, repo):
169169
errors.append(ERROR_MISSING_LICENSE)
170170
if not repo["permissions"]["push"]:
171171
errors.append(ERROR_MISSING_LIBRARIANS)
172-
if not is_repo_in_bundle(full_repo["clone_url"], self.bundle_submodules) and \
172+
if not common_funcs.is_repo_in_bundle(full_repo["clone_url"], self.bundle_submodules) and \
173173
not repo["name"] in BUNDLE_IGNORE_LIST: # Don't assume the bundle will
174174
# bundle itself and possibly
175175
# other repos.
@@ -337,10 +337,12 @@ def _validate_travis_yml(self, repo, travis_yml_file_info):
337337

338338
if not pylint_version:
339339
errors.append(ERROR_PYLINT_VERSION_NOT_FIXED)
340-
elif pylint_version.startswith("1."):
341-
errors.append(ERROR_PYLINT_VERSION_VERY_OUTDATED)
342-
elif pylint_version != self.latest_pylint:
343-
errors.append(ERROR_PYLINT_VERSION_NOT_LATEST)
340+
# disabling below for now, since we know all pylint versions are old
341+
# will re-enable once efforts are underway to update pylint
342+
#elif pylint_version.startswith("1."):
343+
# errors.append(ERROR_PYLINT_VERSION_VERY_OUTDATED)
344+
#elif pylint_version != self.latest_pylint:
345+
# errors.append(ERROR_PYLINT_VERSION_NOT_LATEST)
344346

345347
return errors
346348

@@ -586,9 +588,9 @@ def validate_readthedocs(self, repo):
586588
return [ERROR_RTD_SUBPROJECT_FAILED]
587589
rtd_subprojects = {}
588590
for subproject in rtd_response.json()["subprojects"]:
589-
rtd_subprojects[sanitize_url(subproject["repo"])] = subproject
591+
rtd_subprojects[common_funcs.sanitize_url(subproject["repo"])] = subproject
590592

591-
repo_url = sanitize_url(repo["clone_url"])
593+
repo_url = common_funcs.sanitize_url(repo["clone_url"])
592594
if repo_url not in rtd_subprojects:
593595
return [ERROR_RTD_SUBPROJECT_MISSING]
594596

@@ -608,9 +610,10 @@ def validate_readthedocs(self, repo):
608610
latest_release = github.get("/repos/{}/releases/latest".format(repo["full_name"]))
609611
if not latest_release.ok:
610612
errors.append(ERROR_GITHUB_RELEASE_FAILED)
611-
else:
612-
if latest_release.json()["tag_name"] not in [tag["verbose_name"] for tag in valid_versions["versions"]]:
613-
errors.append(ERROR_RTD_MISSING_LATEST_RELEASE)
613+
# disabling this for now, since it is ignored and always fails
614+
#else:
615+
# if latest_release.json()["tag_name"] not in [tag["verbose_name"] for tag in valid_versions["versions"]]:
616+
# errors.append(ERROR_RTD_MISSING_LATEST_RELEASE)
614617

615618
# There is no API which gives access to a list of builds for a project so we parse the html
616619
# webpage.
@@ -786,6 +789,6 @@ def validate_in_pypi(self, repo):
786789
if not (repo["owner"]["login"] == "adafruit" and
787790
repo["name"].startswith("Adafruit_CircuitPython")):
788791
return []
789-
if not repo_is_on_pypi(repo):
792+
if not common_funcs.repo_is_on_pypi(repo):
790793
return [ERROR_NOT_ON_PYPI]
791794
return []

0 commit comments

Comments
 (0)