Skip to content

Commit 03fd236

Browse files
Pull mpy-cross from AWS S3 instead of building.
Fall back to building if fetching fails.
1 parent 716a38c commit 03fd236

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

circuitpython_build_tools/build.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@
2626
import os
2727
import os.path
2828
import pathlib
29+
import requests
2930
import semver
3031
import shutil
32+
import stat
3133
import sys
3234
import subprocess
3335
import tempfile
3436

3537
IGNORE_PY = ["setup.py", "conf.py", "__init__.py"]
3638
GLOB_PATTERNS = ["*.py", "font5x8.bin"]
39+
S3_MPY_PREFIX = "https://adafruit-circuit-python.s3.amazonaws.com/bin/mpy-cross/"
3740

3841
def version_string(path=None, *, valid_semver=False):
3942
version = None
@@ -64,6 +67,32 @@ def version_string(path=None, *, valid_semver=False):
6467
def mpy_cross(mpy_cross_filename, circuitpython_tag, quiet=False):
6568
if os.path.isfile(mpy_cross_filename):
6669
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+
6796
if not quiet:
6897
title = "Building mpy-cross for circuitpython " + circuitpython_tag
6998
print()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Click
2+
requests
23
semver
34
wheel

0 commit comments

Comments
 (0)