Skip to content

Commit 8d24771

Browse files
committed
[3.13] pythongh-134262: increase retries in Tools/build/generate_sbom.py (pythonGH-134558)
(cherry picked from commit 3f9eb55) Co-authored-by: Emma Smith <emma@emmatyping.dev>
1 parent be1ca79 commit 8d24771

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Tools/build/generate_sbom.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""Tool for generating Software Bill of Materials (SBOM) for Python's dependencies"""
22
import os
3+
import random
34
import re
45
import hashlib
56
import json
67
import glob
78
from pathlib import Path, PurePosixPath, PureWindowsPath
89
import subprocess
910
import sys
11+
import urllib.error
1012
import urllib.request
13+
import time
1114
import typing
1215

1316
CPYTHON_ROOT_DIR = Path(__file__).parent.parent.parent
@@ -163,6 +166,23 @@ def get_externals() -> list[str]:
163166
return externals
164167

165168

169+
def download_with_retries(download_location: str,
170+
max_retries: int = 7,
171+
base_delay: float = 2.25,
172+
max_jitter: float = 1.0) -> typing.Any:
173+
"""Download a file with exponential backoff retry."""
174+
for attempt in range(max_retries):
175+
try:
176+
resp = urllib.request.urlopen(download_location)
177+
except urllib.error.URLError as ex:
178+
if attempt == max_retries:
179+
msg = f"Download from {download_location} failed."
180+
raise OSError(msg) from ex
181+
time.sleep(base_delay**attempt + random.uniform(0, max_jitter))
182+
else:
183+
return resp
184+
185+
166186
def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
167187
"""Make a bunch of assertions about the SBOM package data to ensure it's consistent."""
168188

0 commit comments

Comments
 (0)