|
26 | 26 | import os |
27 | 27 | import os.path |
28 | 28 | import pathlib |
| 29 | +import requests |
29 | 30 | import semver |
30 | 31 | import shutil |
| 32 | +import stat |
31 | 33 | import sys |
32 | 34 | import subprocess |
33 | 35 | import tempfile |
34 | 36 |
|
35 | 37 | IGNORE_PY = ["setup.py", "conf.py", "__init__.py"] |
36 | 38 | GLOB_PATTERNS = ["*.py", "font5x8.bin"] |
| 39 | +S3_MPY_PREFIX = "https://adafruit-circuit-python.s3.amazonaws.com/bin/mpy-cross/" |
37 | 40 |
|
38 | 41 | def version_string(path=None, *, valid_semver=False): |
39 | 42 | version = None |
@@ -64,6 +67,32 @@ def version_string(path=None, *, valid_semver=False): |
64 | 67 | def mpy_cross(mpy_cross_filename, circuitpython_tag, quiet=False): |
65 | 68 | if os.path.isfile(mpy_cross_filename): |
66 | 69 | return |
| 70 | + |
| 71 | + # Try to pull from S3 |
| 72 | + uname = os.uname() |
| 73 | + s3_url = None |
| 74 | + if uname[0] == 'Linux' and uname[4] == 'amd64': |
| 75 | + s3_url = f"{S3_MPY_PREFIX}mpy-cross.static-amd64-linux-{circuitpython_tag}" |
| 76 | + print(s3_url) |
| 77 | + elif uname[0] == 'Linux' and uname[4] == 'armv7l': |
| 78 | + s3_url = f"{S3_MPY_PREFIX}mpy-cross.static-raspbian-{circuitpython_tag}" |
| 79 | + print(s3_url) |
| 80 | + else: |
| 81 | + print(f"\nUnable to check S3 for sysname='{uname[0]}' release='{uname[2]}' machine='{uname[4]}'.") |
| 82 | + print(" Please file an issue at https://github.com/adafruit/circuitpython-build-tools/ with the above message") |
| 83 | + |
| 84 | + if s3_url is not None: |
| 85 | + print(f"Checking S3 for {s3_url}") |
| 86 | + r = requests.get(s3_url) |
| 87 | + if r.status_code == 200: |
| 88 | + with open(mpy_cross_filename, "wb") as f: |
| 89 | + f.write(r.content) |
| 90 | + # Set the User Execute bit |
| 91 | + os.chmod(mpy_cross_filename, os.stat(mpy_cross_filename)[0] | stat.S_IXUSR) |
| 92 | + print(" FOUND") |
| 93 | + return |
| 94 | + print(" NOT FOUND") |
| 95 | + |
67 | 96 | if not quiet: |
68 | 97 | title = "Building mpy-cross for circuitpython " + circuitpython_tag |
69 | 98 | print() |
|
0 commit comments