Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c5a8b0

Browse files
gh-134262: Add retries to generate_sbom.py (#134263)
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
1 parentb8998fe commit0c5a8b0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

‎Tools/build/generate_sbom.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
importre
88
importsubprocess
99
importsys
10+
importtime
1011
importtyping
12+
importurllib.error
1113
importurllib.request
1214
frompathlibimportPath,PurePosixPath,PureWindowsPath
1315

@@ -161,6 +163,21 @@ def get_externals() -> list[str]:
161163
returnexternals
162164

163165

166+
defdownload_with_retries(download_location:str,
167+
max_retries:int=5,
168+
base_delay:float=2.0)->typing.Any:
169+
"""Download a file with exponential backoff retry."""
170+
forattemptinrange(max_retries):
171+
try:
172+
resp=urllib.request.urlopen(download_location)
173+
excepturllib.error.URLErrorasex:
174+
ifattempt==max_retries:
175+
raiseex
176+
time.sleep(base_delay**attempt)
177+
else:
178+
returnresp
179+
180+
164181
defcheck_sbom_packages(sbom_data:dict[str,typing.Any])->None:
165182
"""Make a bunch of assertions about the SBOM package data to ensure it's consistent."""
166183

@@ -175,7 +192,7 @@ def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
175192
# and that the download URL is valid.
176193
if"checksums"notinpackageor"CI"inos.environ:
177194
download_location=package["downloadLocation"]
178-
resp=urllib.request.urlopen(download_location)
195+
resp=download_with_retries(download_location)
179196
error_if(resp.status!=200,f"Couldn't access URL:{download_location}'")
180197

181198
package["checksums"]= [{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp