|
4 | 4 | # |
5 | 5 | # Copyright (c) 2016 Scott Shawcroft for Adafruit Industries |
6 | 6 | # 2018, 2019 Michael Schroeder |
| 7 | +# 2021 James Carr |
7 | 8 | # |
8 | 9 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | 10 | # of this software and associated documentation files (the "Software"), to deal |
|
26 | 27 | import os |
27 | 28 | import os.path |
28 | 29 | import pathlib |
| 30 | +import requests |
29 | 31 | import semver |
30 | 32 | import shutil |
| 33 | +import stat |
31 | 34 | import sys |
32 | 35 | import subprocess |
33 | 36 | import tempfile |
34 | 37 |
|
35 | 38 | IGNORE_PY = ["setup.py", "conf.py", "__init__.py"] |
36 | 39 | GLOB_PATTERNS = ["*.py", "font5x8.bin"] |
| 40 | +S3_MPY_PREFIX = "https://adafruit-circuit-python.s3.amazonaws.com/bin/mpy-cross/" |
37 | 41 |
|
38 | 42 | def version_string(path=None, *, valid_semver=False): |
39 | 43 | version = None |
@@ -64,6 +68,38 @@ def version_string(path=None, *, valid_semver=False): |
64 | 68 | def mpy_cross(mpy_cross_filename, circuitpython_tag, quiet=False): |
65 | 69 | if os.path.isfile(mpy_cross_filename): |
66 | 70 | return |
| 71 | + |
| 72 | + # Try to pull from S3 |
| 73 | + uname = os.uname() |
| 74 | + s3_url = None |
| 75 | + if uname[0] == 'Linux' and uname[4] in ('amd64', 'x86_64'): |
| 76 | + s3_url = f"{S3_MPY_PREFIX}mpy-cross.static-amd64-linux-{circuitpython_tag}" |
| 77 | + elif uname[0] == 'Linux' and uname[4] == 'armv7l': |
| 78 | + s3_url = f"{S3_MPY_PREFIX}mpy-cross.static-raspbian-{circuitpython_tag}" |
| 79 | + elif uname[0] == 'Darwin' and uname[4] == 'x86_64': |
| 80 | + s3_url = f"{S3_MPY_PREFIX}mpy-cross-macos-catalina-{circuitpython_tag}" |
| 81 | + elif not quiet: |
| 82 | + print(f"Pre-built mpy-cross not available for sysname='{uname[0]}' release='{uname[2]}' machine='{uname[4]}'.") |
| 83 | + |
| 84 | + if s3_url is not None: |
| 85 | + if not quiet: |
| 86 | + print(f"Checking S3 for {s3_url}") |
| 87 | + try: |
| 88 | + r = requests.get(s3_url) |
| 89 | + if r.status_code == 200: |
| 90 | + with open(mpy_cross_filename, "wb") as f: |
| 91 | + f.write(r.content) |
| 92 | + # Set the User Execute bit |
| 93 | + os.chmod(mpy_cross_filename, os.stat(mpy_cross_filename)[0] | stat.S_IXUSR) |
| 94 | + if not quiet: |
| 95 | + print(" FOUND") |
| 96 | + return |
| 97 | + except Exception as e: |
| 98 | + if not quiet: |
| 99 | + print(f" exception fetching from S3: {e}") |
| 100 | + if not quiet: |
| 101 | + print(" NOT FOUND") |
| 102 | + |
67 | 103 | if not quiet: |
68 | 104 | title = "Building mpy-cross for circuitpython " + circuitpython_tag |
69 | 105 | print() |
|
0 commit comments