|
10 | 10 | import glob
|
11 | 11 | import importlib.util
|
12 | 12 | import sys
|
| 13 | +import subprocess |
13 | 14 | from typing import Set
|
| 15 | +from urllib.request import urlopen |
| 16 | + |
14 | 17 | from tools import cache
|
15 | 18 | from tools import config
|
16 | 19 | from tools import shared
|
17 | 20 | from tools import system_libs
|
18 | 21 | from tools import utils
|
19 | 22 | from tools.settings import settings
|
20 |
| - |
21 | 23 | from tools.toolchain_profiler import ToolchainProfiler
|
22 | 24 |
|
23 | 25 | ports = []
|
@@ -297,27 +299,14 @@ def retrieve():
|
297 | 299 | # retrieve from remote server
|
298 | 300 | logger.info(f'retrieving port: {name} from {url}')
|
299 | 301 |
|
300 |
| - # Attempt to use the `requests` module rather `urllib`. |
301 |
| - # The main difference here is that `requests` will use the `certifi` |
302 |
| - # certificate chain whereas `urllib` will use the system openssl |
303 |
| - # certificate chain, which can be out-of-date on some macOS systems. |
304 |
| - # TODO(sbc): Perhaps we can remove this at some point when we no |
305 |
| - # longer support such out-of-date systems. |
306 |
| - try: |
307 |
| - import requests |
308 |
| - try: |
309 |
| - response = requests.get(url) |
310 |
| - data = response.content |
311 |
| - except requests.exceptions.InvalidSchema: |
312 |
| - # requests does not support 'file://' protocol and raises InvalidSchema |
313 |
| - pass |
314 |
| - except ImportError: |
315 |
| - pass |
316 |
| - |
317 |
| - # If we don't have `requests` or if we got InvalidSchema then fall |
318 |
| - # back to `urllib`. |
319 |
| - if not data: |
320 |
| - from urllib.request import urlopen |
| 302 | + if utils.MACOS: |
| 303 | + # Use `curl` over `urllib` on macOS to avoid issues with |
| 304 | + # certificate verification. |
| 305 | + # https://stackoverflow.com/questions/40684543/how-to-make-python-use-ca-certificates-from-mac-os-truststore |
| 306 | + # Unlike on Windows or Linux, curl is guaranteed to always be |
| 307 | + # available on macOS. |
| 308 | + data = subprocess.check_output(['curl', '-sSL', url]) |
| 309 | + else: |
321 | 310 | f = urlopen(url)
|
322 | 311 | data = f.read()
|
323 | 312 |
|
|
0 commit comments