Skip to content

Commit

Permalink
pass timeout arg to all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
FoamyGuy committed Dec 11, 2023
1 parent 7b24054 commit f8fbab4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
13 changes: 9 additions & 4 deletions adabot/arduino_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def is_arduino_library(repo):
+ repo["name"]
+ "/"
+ repo["default_branch"]
+ "/library.properties"
+ "/library.properties",
timeout=30,
)
return lib_prop_file.ok

Expand Down Expand Up @@ -116,7 +117,8 @@ def validate_library_properties(repo):
+ repo["name"]
+ "/"
+ repo["default_branch"]
+ "/library.properties"
+ "/library.properties",
timeout=30,
)
if not lib_prop_file.ok:
# print("{} skipped".format(repo["name"]))
Expand Down Expand Up @@ -193,7 +195,8 @@ def validate_actions(repo):
+ repo["name"]
+ "/"
+ repo["default_branch"]
+ "/.github/workflows/githubci.yml"
+ "/.github/workflows/githubci.yml",
timeout=30,
)
return repo_has_actions.ok

Expand Down Expand Up @@ -309,7 +312,9 @@ def main(verbosity=1, output_file=None): # pylint: disable=missing-function-doc
logger.setLevel("CRITICAL")

try:
reply = requests.get("http://downloads.arduino.cc/libraries/library_index.json")
reply = requests.get(
"http://downloads.arduino.cc/libraries/library_index.json", timeout=30
)
if not reply.ok:
logging.error(
"Could not fetch http://downloads.arduino.cc/libraries/library_index.json"
Expand Down
2 changes: 1 addition & 1 deletion adabot/circuitpython_library_download_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
def retrieve_piwheels_stats():
"""Get data dump of piwheels download stats"""
stats = {}
response = requests.get(PIWHEELS_PACKAGES_URL)
response = requests.get(PIWHEELS_PACKAGES_URL, timeout=30)
if response.ok:
packages = response.json()
stats = {
Expand Down
2 changes: 1 addition & 1 deletion adabot/lib/assign_hacktober_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_open_issues(repo):
)

if response.links.get("next"):
response = requests.get(response.links["next"]["url"])
response = requests.get(response.links["next"]["url"], timeout=30)
else:
break

Expand Down
10 changes: 5 additions & 5 deletions adabot/lib/circuitpython_library_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def rtd_yml_base(self):
"%20if%20cookiecutter.sphinx_docs%20in%20%5B'y'%2C%20'yes'%5D%20%25"
"%7D.readthedocs.yaml%7B%25%20endif%20%25%7D"
)
rtd_yml = requests.get(rtd_yml_dl_url)
rtd_yml = requests.get(rtd_yml_dl_url, timeout=30)
if rtd_yml.ok:
try:
self._rtd_yaml_base = yaml.safe_load(rtd_yml.text)
Expand All @@ -255,7 +255,7 @@ def pcc_versions(self):
"circuitpython/main/%7B%7B%20cookiecutter.__dirname%20%7D%7D/.pre-"
"commit-config.yaml"
)
pcc_yml = requests.get(pcc_yml_dl_url)
pcc_yml = requests.get(pcc_yml_dl_url, timeout=30)
if pcc_yml.ok:
try:
pcc_yaml_base = yaml.safe_load(pcc_yml.text)
Expand Down Expand Up @@ -718,7 +718,7 @@ def validate_contents(self, repo):
if ".readthedocs.yaml" in files:
filename = ".readthedocs.yaml"
file_info = content_list[files.index(filename)]
rtd_contents = requests.get(file_info["download_url"])
rtd_contents = requests.get(file_info["download_url"], timeout=30)
if rtd_contents.ok:
try:
rtd_yml = yaml.safe_load(rtd_contents.text)
Expand All @@ -736,7 +736,7 @@ def validate_contents(self, repo):
if len(self._pcc_versions) or self.pcc_versions != "":
filename = ".pre-commit-config.yaml"
file_info = content_list[files.index(filename)]
pcc_contents = requests.get(file_info["download_url"])
pcc_contents = requests.get(file_info["download_url"], timeout=30)
if pcc_contents.ok:
try:
pcc_yml = yaml.safe_load(pcc_contents.text)
Expand Down Expand Up @@ -938,7 +938,7 @@ def validate_readthedocs(self, repo):
url = f"https://readthedocs.org/api/v3/projects/{rtd_slug}/builds/"
rtd_token = os.environ["RTD_TOKEN"]
headers = {"Authorization": f"token {rtd_token}"}
response = requests.get(url, headers=headers)
response = requests.get(url, headers=headers, timeout=30)
json_response = response.json()

error_message = json_response.get("detail")
Expand Down
2 changes: 1 addition & 1 deletion tools/docs_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def check_docs_status(
# GET the latest documentation build runs
url = f"https://readthedocs.org/api/v3/projects/{rtd_slug}/builds/"
headers = {"Authorization": f"token {rtd_token}"}
response = requests.get(url, headers=headers)
response = requests.get(url, headers=headers, timeout=30)
json_response: dict[str, Any] = response.json()

# Return the results of the latest run
Expand Down
4 changes: 2 additions & 2 deletions tools/file_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def compare(git_file: str, token: Optional[str] = None) -> list:
headers = CaseInsensitiveDict()
headers["Authorization"] = f"token {token}"

resp = requests.get(url, headers=headers)
resp = requests.get(url, headers=headers, timeout=30)
else:
resp = requests.get(url)
resp = requests.get(url, timeout=30)

if resp.status_code != 200:
print(name)
Expand Down
2 changes: 1 addition & 1 deletion tools/find_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def prettyprint(info, results):

for repo in all_repos:
INFO = "getting {} for: {}".format(FILE, repo["name"])
response = requests.get(URL_TEMPLATE.format(repo["name"], FILE))
response = requests.get(URL_TEMPLATE.format(repo["name"], FILE), timeout=30)
result = []
if response.status_code == 404:
RESULTS["file_not_found"].append(repo["html_url"])
Expand Down

0 comments on commit f8fbab4

Please sign in to comment.