Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions PCbuild/get_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,47 @@
import argparse
import os
import pathlib
import random
import sys
import time
import zipfile
from urllib.request import urlretrieve


def retrieve_with_retries(download_location,
output_path,
reporthook,
max_retries = 7,
base_delay = 2.25,
max_jitter = 1.0):
"""Download a file with exponential backoff retry and save to disk."""
for attempt in range(max_retries):
try:
resp = urlretrieve(
download_location,
output_path,
reporthook=reporthook,
)
except ConnectionError as ex:
if attempt == max_retries:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because attempt comes from range(max_retries), this condition can never be hit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♀️ thanks for catching that, opened #134867

msg = f"Download from {download_location} failed."
raise OSError(msg) from ex
time.sleep(base_delay**attempt + random.uniform(0, max_jitter))
else:
return resp


def fetch_zip(commit_hash, zip_dir, *, org='python', binary=False, verbose):
repo = f'cpython-{"bin" if binary else "source"}-deps'
url = f'https://github.com/{org}/{repo}/archive/{commit_hash}.zip'
reporthook = None
if verbose:
reporthook = print
zip_dir.mkdir(parents=True, exist_ok=True)
filename, headers = urlretrieve(
filename, _headers = retrieve_with_retries(
url,
zip_dir / f'{commit_hash}.zip',
reporthook=reporthook,
reporthook
)
return filename

Expand Down
Loading