|
67 | 67 |
|
68 | 68 | BAZEL_UPSTREAM = "bazelbuild"
|
69 | 69 |
|
| 70 | +BAZEL_DOWNLOAD_RETRIES = 5 |
| 71 | +BAZEL_DOWNLOAD_RETRY_WAIT_SECS = 5 |
| 72 | + |
70 | 73 |
|
71 | 74 | def decide_which_bazel_version_to_use():
|
72 | 75 | # Check in this order:
|
@@ -180,8 +183,7 @@ def get_version_history(bazelisk_directory):
|
180 | 183 | ),
|
181 | 184 | # This only handles versions with numeric components, but that is fine
|
182 | 185 | # since prerelease versions have been excluded.
|
183 |
| - key=lambda version: tuple(int(component) |
184 |
| - for component in version.split('.')), |
| 186 | + key=lambda version: tuple(int(component) for component in version.split(".")), |
185 | 187 | reverse=True,
|
186 | 188 | )
|
187 | 189 |
|
@@ -352,8 +354,16 @@ def download(url, destination_path):
|
352 | 354 | if creds is not None:
|
353 | 355 | auth = base64.b64encode(("%s:%s" % (creds[0], creds[2])).encode("ascii"))
|
354 | 356 | request.add_header("Authorization", "Basic %s" % auth.decode("utf-8"))
|
355 |
| - with closing(urlopen(request)) as response, open(destination_path, "wb") as file: |
356 |
| - shutil.copyfileobj(response, file) |
| 357 | + |
| 358 | + tries = BAZEL_DOWNLOAD_RETRIES |
| 359 | + while tries > 0: |
| 360 | + try: |
| 361 | + with closing(urlopen(request)) as response, open(destination_path, "wb") as file: |
| 362 | + shutil.copyfileobj(response, file) |
| 363 | + break |
| 364 | + except Exception: |
| 365 | + tries -= 1 |
| 366 | + time.sleep(secs=BAZEL_DOWNLOAD_RETRY_WAIT_SECS) |
357 | 367 |
|
358 | 368 |
|
359 | 369 | def get_bazelisk_directory():
|
|
0 commit comments