Big initial commit that builds a bundle.
Adds all existing Adafruit MicroPython libraries to the bundle.
This commit is contained in:
parent
cdbb1cb6bd
commit
af13be7a29
15 changed files with 220 additions and 2 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
build
|
||||
30
.gitmodules
vendored
Normal file
30
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
[submodule "micropython"]
|
||||
path = micropython
|
||||
url = https://github.com/adafruit/micropython
|
||||
[submodule "libraries/drivers/pca9685"]
|
||||
path = libraries/drivers/pca9685
|
||||
url = git@github.com:adafruit/micropython-adafruit-pca9685.git
|
||||
[submodule "libraries/drivers/ssd1306"]
|
||||
path = libraries/drivers/ssd1306
|
||||
url = git@github.com:adafruit/micropython-adafruit-ssd1306.git
|
||||
[submodule "libraries/drivers/max7219"]
|
||||
path = libraries/drivers/max7219
|
||||
url = git@github.com:adafruit/micropython-adafruit-max7219.git
|
||||
[submodule "libraries/drivers/is31fl3731"]
|
||||
path = libraries/drivers/is31fl3731
|
||||
url = git@github.com:adafruit/micropython-adafruit-is31fl3731.git
|
||||
[submodule "libraries/drivers/ht16k33"]
|
||||
path = libraries/drivers/ht16k33
|
||||
url = git@github.com:adafruit/micropython-adafruit-ht16k33.git
|
||||
[submodule "libraries/drivers/ads1015"]
|
||||
path = libraries/drivers/ads1015
|
||||
url = git@github.com:adafruit/micropython-adafruit-ads1015.git
|
||||
[submodule "libraries/drivers/rgb-display"]
|
||||
path = libraries/drivers/rgb-display
|
||||
url = git@github.com:adafruit/micropython-adafruit-rgb-display.git
|
||||
[submodule "libraries/drivers/tsl2561"]
|
||||
path = libraries/drivers/tsl2561
|
||||
url = git@github.com:adafruit/micropython-adafruit-tsl2561.git
|
||||
[submodule "libraries/drivers/tcs34725"]
|
||||
path = libraries/drivers/tcs34725
|
||||
url = git@github.com:adafruit/micropython-adafruit-tcs34725.git
|
||||
33
README.md
33
README.md
|
|
@ -1,2 +1,31 @@
|
|||
# micropython-adafruit-bundle
|
||||
A bundle of useful MicroPython libraries ready to use from the filesystem.
|
||||
# Adafruit's MicroPython Bundle
|
||||
This repo bundles a bunch of useful MicroPython libraries into an easy to
|
||||
download zip file. MicroPython boards can ship with the contents of the zip to
|
||||
make it easy to provide a lot of libraries by default.
|
||||
|
||||
# Use
|
||||
To use the bundle download the zip (not source zip) from the latest release,
|
||||
unzip it and copy over the subfolders into the root of your MicroPython device.
|
||||
|
||||
# Development
|
||||
|
||||
After you clone this repository you must run `git submodule --init` on update
|
||||
also do `git submodule update`.
|
||||
|
||||
## Updating libraries
|
||||
To update the libraries run `update-submodules.sh`. The script will fetch the
|
||||
latest code and update to the newest tag (not master).
|
||||
|
||||
## Adding a library
|
||||
Determine the best location within `libraries` for the new library and then run:
|
||||
|
||||
git submodule add <git url> libraries/<target directory>
|
||||
|
||||
The target directory should omit any micropython specific prefixes such as
|
||||
`micropython-adafruit` to simplify the listing.
|
||||
|
||||
## Building the bundle
|
||||
To build the bundle run `build-bundle.py` it requires Python 3.5+ and will
|
||||
produce a zip file in `build`. The file structure of the zip will not be
|
||||
identical to the source `libraries` directory in order to save space. Libraries
|
||||
with a single source will not be placed in their own directory.
|
||||
|
|
|
|||
120
build-bundle.py
Executable file
120
build-bundle.py
Executable file
|
|
@ -0,0 +1,120 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import sys
|
||||
import subprocess
|
||||
import zipfile
|
||||
|
||||
os.chdir("micropython/mpy-cross")
|
||||
make = subprocess.run(["make"])
|
||||
os.chdir("../../")
|
||||
|
||||
if make.returncode != 0:
|
||||
print("Unable to make mpy-cross.")
|
||||
sys.exit(1)
|
||||
|
||||
mpy_cross = "micropython/mpy-cross/mpy-cross"
|
||||
|
||||
if "build" in os.listdir("."):
|
||||
print("Deleting existing build.")
|
||||
shutil.rmtree("build")
|
||||
os.mkdir("build")
|
||||
os.mkdir("build/lib")
|
||||
|
||||
success = True
|
||||
total_size = 512
|
||||
for subdirectory in os.listdir("libraries"):
|
||||
for library in os.listdir(os.path.join("libraries", subdirectory)):
|
||||
library_path = os.path.join("libraries", subdirectory, library)
|
||||
|
||||
py_files = []
|
||||
for filename in os.listdir(library_path):
|
||||
if filename.endswith(".py") and filename != "setup.py":
|
||||
py_files.append(filename)
|
||||
|
||||
output_directory = os.path.join("build", "lib")
|
||||
if len(py_files) > 1:
|
||||
output_directory = os.path.join(output_directory, library)
|
||||
os.makedirs(output_directory)
|
||||
package_init = os.path.join(output_directory, "__init__.py")
|
||||
with open(package_init, 'a'):
|
||||
pass
|
||||
print(output_directory, 512)
|
||||
print(package_init, 512)
|
||||
total_size = 1024
|
||||
|
||||
for filename in py_files:
|
||||
full_path = os.path.join(library_path, filename)
|
||||
output_file = os.path.join(output_directory, filename.replace(".py", ".mpy"))
|
||||
mpy_success = subprocess.call([mpy_cross, "-o", output_file, full_path])
|
||||
if mpy_success != 0:
|
||||
print("mpy-cross failed on", full_path)
|
||||
success = False
|
||||
continue
|
||||
file_size = os.stat(output_file).st_size
|
||||
file_sector_size = file_size
|
||||
if file_size % 512 != 0:
|
||||
file_sector_size = (file_size // 512 + 1) * 512
|
||||
total_size += file_sector_size
|
||||
print(output_file, file_size, file_sector_size)
|
||||
|
||||
print(total_size, "B", total_size / 1024, "kiB", total_size / 1024 / 1024, "MiB")
|
||||
|
||||
version = None
|
||||
tag = subprocess.run(shlex.split("git describe --tags --exact-match"), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if tag.returncode == 0:
|
||||
version = tag.stdout.strip()
|
||||
else:
|
||||
commitish = subprocess.run(shlex.split("git log --pretty=format:'%h' -n 1"), stdout=subprocess.PIPE)
|
||||
version = commitish.stdout.strip()
|
||||
|
||||
with open("build/lib/VERSIONS.txt", "w") as f:
|
||||
f.write(version.decode("utf-8", "strict") + "\r\n")
|
||||
versions = subprocess.run(shlex.split("git submodule foreach \"git remote get-url origin && git describe --tags\""), stdout=subprocess.PIPE)
|
||||
repo = None
|
||||
for line in versions.stdout.split(b"\n"):
|
||||
if line.startswith(b"Entering"):
|
||||
continue
|
||||
if line.startswith(b"git@"):
|
||||
repo = b"https://github.com/" + line.split(b":")[1][:-len(".git")]
|
||||
elif line.startswith(b"https:"):
|
||||
repo = line.strip()
|
||||
else:
|
||||
f.write(repo.decode("utf-8", "strict") + "/releases/tag/" + line.strip().decode("utf-8", "strict") + "\r\n")
|
||||
|
||||
zip_filename = 'build/adafruit-micropython-bundle-' + version.decode("utf-8", "strict") + '.zip'
|
||||
|
||||
with zipfile.ZipFile(zip_filename, 'w') as bundle:
|
||||
for root, dirs, files in os.walk("build/lib"):
|
||||
ziproot = root[len("build/"):].replace("-", "_")
|
||||
for filename in files:
|
||||
bundle.write(os.path.join(root, filename),
|
||||
os.path.join(ziproot, filename.replace("-", "_")))
|
||||
|
||||
print("Bundled in", zip_filename)
|
||||
if not success:
|
||||
sys.exit(2)
|
||||
1
libraries/drivers/ads1015
Submodule
1
libraries/drivers/ads1015
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 8edb1e97ef93959ac9f6975f0948e33d2424355e
|
||||
1
libraries/drivers/ht16k33
Submodule
1
libraries/drivers/ht16k33
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 04dfd1b62ff4369c3d81e656603556859f631734
|
||||
1
libraries/drivers/is31fl3731
Submodule
1
libraries/drivers/is31fl3731
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 31f5606d66dccb00326ec2dff22ce85e98f6353e
|
||||
1
libraries/drivers/max7219
Submodule
1
libraries/drivers/max7219
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 1606b2ad3e47b349e21acbe4752e51aec6d874dd
|
||||
1
libraries/drivers/pca9685
Submodule
1
libraries/drivers/pca9685
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit d887b1ac509011d8fb861118e6bcaa4219143470
|
||||
1
libraries/drivers/rgb-display
Submodule
1
libraries/drivers/rgb-display
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit baa05471985c129b4d9b756e0cbabbbe639eac4c
|
||||
1
libraries/drivers/ssd1306
Submodule
1
libraries/drivers/ssd1306
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 359e4c0886c1c639e5ca49e24bcc75d5788f84a9
|
||||
1
libraries/drivers/tcs34725
Submodule
1
libraries/drivers/tcs34725
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 363cee4a5d998bcd5088ff5290779eafb8a67894
|
||||
1
libraries/drivers/tsl2561
Submodule
1
libraries/drivers/tsl2561
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit fc4ea40d97320633546c2bc442446f6226fca2f4
|
||||
1
micropython
Submodule
1
micropython
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 6fe8c7b32c04e8c0b1ad8618920e241430634ad2
|
||||
28
update-submodules.sh
Executable file
28
update-submodules.sh
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#! /bin/bash
|
||||
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
# This script updates all submodules to the latest tag (hopefully release).
|
||||
git submodule update
|
||||
git submodule foreach git fetch
|
||||
git submodule foreach "tag=\$(git rev-list --tags --max-count=1); git checkout -q \$tag"
|
||||
Loading…
Reference in a new issue