(url: str, file_path: str, max_retries: int = 3)
| 16 | |
| 17 | |
| 18 | def download_file(url: str, file_path: str, max_retries: int = 3) -> None: |
| 19 | if os.path.exists(file_path): |
| 20 | return |
| 21 | logging.info(f"Downloading {url} to {file_path}") |
| 22 | for retry in range(max_retries): |
| 23 | try: |
| 24 | urllib.request.urlretrieve(url, file_path) |
| 25 | return |
| 26 | except Exception as exc: |
| 27 | logging.error( |
| 28 | f"Failed to download {url} (trial={retry + 1}) " |
| 29 | f"to {file_path} due to {exc}" |
| 30 | ) |
| 31 | |
| 32 | |
| 33 | def check_small_errors_or_exit( |