Skip to content

Commit 4d055bb

Browse files
authored
Merge pull request #72 from lesamouraipourpre/aws-mpy-cross
Use mpy-cross from S3 if possible
2 parents 716a38c + eadbc29 commit 4d055bb

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dist: xenial
22
language: python
33
python:
4-
- '3.6'
4+
- '3.7'
55

66
stages:
77
- name: Tests
@@ -13,7 +13,7 @@ jobs:
1313
include:
1414
- stage: Tests
1515
name: "Test CircuitPython Bundle"
16-
python: "3.6"
16+
python: "3.7"
1717
script:
1818
- echo "Building mpy-cross" && echo "travis_fold:start:mpy-cross"
1919
- python3 -u -m circuitpython_build_tools.scripts.build_mpy_cross circuitpython_build_tools/data/

circuitpython_build_tools/build.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
66
# 2018, 2019 Michael Schroeder
7+
# 2021 James Carr
78
#
89
# Permission is hereby granted, free of charge, to any person obtaining a copy
910
# of this software and associated documentation files (the "Software"), to deal
@@ -26,14 +27,17 @@
2627
import os
2728
import os.path
2829
import pathlib
30+
import requests
2931
import semver
3032
import shutil
33+
import stat
3134
import sys
3235
import subprocess
3336
import tempfile
3437

3538
IGNORE_PY = ["setup.py", "conf.py", "__init__.py"]
3639
GLOB_PATTERNS = ["*.py", "font5x8.bin"]
40+
S3_MPY_PREFIX = "https://adafruit-circuit-python.s3.amazonaws.com/bin/mpy-cross/"
3741

3842
def version_string(path=None, *, valid_semver=False):
3943
version = None
@@ -64,6 +68,38 @@ def version_string(path=None, *, valid_semver=False):
6468
def mpy_cross(mpy_cross_filename, circuitpython_tag, quiet=False):
6569
if os.path.isfile(mpy_cross_filename):
6670
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+
67103
if not quiet:
68104
title = "Building mpy-cross for circuitpython " + circuitpython_tag
69105
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

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
'circuitpython_build_tools.scripts'],
1414
package_data={'circuitpython_build_tools': ['data/mpy-cross-*']},
1515
zip_safe=False,
16-
python_requires='>=3.4',
17-
install_requires=['Click', 'semver'],
16+
python_requires='>=3.7',
17+
install_requires=['Click', 'requests', 'semver'],
1818
entry_points='''
1919
[console_scripts]
2020
circuitpython-build-bundles=circuitpython_build_tools.scripts.build_bundles:build_bundles

0 commit comments

Comments
 (0)