|
1 | | -# Download and extract the redistributable package to support building |
2 | | -# the wheels on Windows and Linux. |
| 1 | +# Download and extract the MQ packages that support building |
| 2 | +# wheels on MacOS, Windows and Linux. |
3 | 3 | # |
4 | 4 | # Pass the source URL as the first argument and the destination directory |
5 | 5 | # as the second argument. |
6 | 6 | # |
7 | | -# The source URL should end with .tar.gz or .zip |
| 7 | +# The source URL should end with .tar.gz (Linux) or .zip (Windows) or .pkg (MacOS) |
8 | 8 | # |
9 | 9 | import os |
10 | 10 | import sys |
| 11 | +import time |
11 | 12 | import tarfile |
12 | 13 | import zipfile |
13 | 14 |
|
|
18 | 19 | sys.exit(1) |
19 | 20 |
|
20 | 21 | SOURCE_URL = sys.argv[1] |
| 22 | +# This is a directory |
21 | 23 | DESTINATION_PATH = sys.argv[2] |
22 | 24 |
|
| 25 | +# And we actually download to a file whose name starts with the destination directory |
23 | 26 | if SOURCE_URL.endswith('.tar.gz'): |
24 | 27 | temp_path = DESTINATION_PATH + '-temp.tar.gz' |
25 | 28 | elif SOURCE_URL.endswith('.zip'): |
26 | 29 | temp_path = DESTINATION_PATH + '-temp.zip' |
| 30 | +elif SOURCE_URL.endswith('.pkg'): |
| 31 | + temp_path = DESTINATION_PATH + '-temp.pkg' |
27 | 32 | else: |
28 | 33 | print("Unsupported archive format") |
29 | 34 | sys.exit(1) |
@@ -55,8 +60,27 @@ def extract_archive(archive_path, extract_to): |
55 | 60 | raise ValueError("Unsupported archive format") |
56 | 61 |
|
57 | 62 |
|
58 | | -print(f'Downloading "{SOURCE_URL}" to "{DESTINATION_PATH}"') |
59 | | -download_file(SOURCE_URL, temp_path) |
60 | | -extract_archive(temp_path, DESTINATION_PATH) |
61 | | -os.unlink(temp_path) |
| 63 | +# If it's a .pkg file, that's for MacOS which we do not unpack here. |
| 64 | +# Instead, it'll be installed properly by the calling environment. |
| 65 | +print(f'Downloading "{SOURCE_URL}" to {temp_path}' ) |
| 66 | + |
| 67 | +cnt = 0 |
| 68 | +while True: |
| 69 | + try: |
| 70 | + # A very simple retry mechanism as we've seen occasional DNS failures |
| 71 | + # on some github runners |
| 72 | + download_file(SOURCE_URL, temp_path) |
| 73 | + break |
| 74 | + except requests.exceptions.ConnectionError as e: |
| 75 | + if cnt == 3: |
| 76 | + print("Maximum retries reached") |
| 77 | + raise(e) |
| 78 | + print(f"Connection error {e}: sleeping") |
| 79 | + cnt = cnt + 1 |
| 80 | + time.sleep(5) |
| 81 | + |
| 82 | +if not SOURCE_URL.endswith('.pkg'): |
| 83 | + print(f'Extracting files from {temp_path} to {DESTINATION_PATH}') |
| 84 | + extract_archive(temp_path, DESTINATION_PATH) |
| 85 | + os.unlink(temp_path) |
62 | 86 | print(f'Done via "{temp_path}"') |
0 commit comments