Initial commit with files from the Adafruit bundle.

This commit is contained in:
Scott Shawcroft 2017-07-26 11:10:23 -07:00
commit a185a49ee2
10 changed files with 291 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "circuitpython"]
path = circuitpython
url = https://github.com/adafruit/circuitpython.git

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 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.

49
README.md Normal file
View file

@ -0,0 +1,49 @@
# CircuitPython Community Library Bundle
[![Doc Status](https://readthedocs.org/projects/circuitpython/badge/?version=latest)](https://circuitpython.readthedocs.io/en/latest/docs/drivers.html) [![Gitter](https://badges.gitter.im/adafruit/circuitpython.svg)](https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
This repo bundles a bunch of useful CircuitPython libraries into an easy to
download zip file. CircuitPython boards can ship with the contents of the zip to
make it easy to provide a lot of libraries by default.
# License
Each included library has its own license that must allow for redistribution. To
save space, license text is not included in the bundle. However, a link to each
individual repository is which should provide source code access and license
information.
# Use
To use the bundle download the zip (not source zip) from the
[latest release](https://github.com/adafruit/CircuitPython_Community_Bundle/releases/latest),
unzip it and copy over the subfolders, such as `lib`, into the root of your
CircuitPython device. Make sure to indicate that it should be merged with the
existing folder when it exists.
# 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 or CircuitPython specific
prefixes such as `CircuitPython_` to simplify the listing.
## Removing a library
Only do this if you are replacing the module with an equivalent:
git submodule deinit libraries/<target directory>
git rm libraries/<target directory>
## 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.

2
README.txt Normal file
View file

@ -0,0 +1,2 @@
See here for more info: https://github.com/adafruit/CircuitPython_Community_Bundle
See VERSIONS.txt for version info.

155
build-bundle.py Normal file
View file

@ -0,0 +1,155 @@
#!/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("circuitpython/mpy-cross")
make = subprocess.run(["make"])
os.chdir("../../")
if make.returncode != 0:
print("Unable to make mpy-cross.")
sys.exit(1)
mpy_cross = "circuitpython/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 = []
package_files = []
for filename in os.listdir(library_path):
full_path = os.path.join(library_path, filename)
if os.path.isdir(full_path) and os.path.isfile(os.path.join(full_path, "__init__.py")):
files = os.listdir(full_path)
files = filter(lambda x: x.endswith(".py"), files)
files = map(lambda x: os.path.join(filename, x), files)
package_files.extend(files)
if filename.endswith(".py") and filename != "setup.py" and filename != "conf.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)
total_size += 512
if len(package_files) > 1:
for fn in package_files:
base_dir = os.path.join(output_directory, os.path.dirname(fn))
if not os.path.isdir(base_dir):
os.makedirs(base_dir)
print(base_dir, 512)
total_size += 512
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
for filename in package_files:
full_path = os.path.join(library_path, filename)
if os.stat(full_path).st_size == 0 or filename.endswith("__init__.py"):
output_file = os.path.join(output_directory, filename)
shutil.copyfile(full_path, output_file)
else:
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
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") or not line:
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/circuitpython-community-bundle-' + version.decode("utf-8", "strict") + '.zip'
def add_file(bundle, src_file, zip_name):
global total_size
bundle.write(src_file, zip_name)
file_size = os.stat(src_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(zip_name, file_size, file_sector_size)
with zipfile.ZipFile(zip_filename, 'w') as bundle:
add_file(bundle, "README.txt", "lib/README.txt")
for filename in os.listdir("update_scripts"):
src_file = os.path.join("update_scripts", filename)
add_file(bundle, src_file, os.path.join("lib", filename))
for root, dirs, files in os.walk("build/lib"):
ziproot = root[len("build/"):].replace("-", "_")
for filename in files:
add_file(bundle, os.path.join(root, filename),
os.path.join(ziproot, filename.replace("-", "_")))
print()
print(total_size, "B", total_size / 1024, "kiB", total_size / 1024 / 1024, "MiB")
print("Bundled in", zip_filename)
if not success:
sys.exit(2)

1
circuitpython Submodule

@ -0,0 +1 @@
Subproject commit f1e2afbea0244b04fb096862e132b181dba8c67f

28
update-submodules.sh Executable file
View 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"

View file

@ -0,0 +1,15 @@
#! /bin/bash
latest_release=$(curl -s "https://api.github.com/repos/adafruit/Adafruit_CircuitPython_Bundle/releases/latest")
download_link=$(echo $latest_release | grep -o "\"browser_download_url\": \"[^\"]*" | cut -d \" -f 4)
tag=$(echo $latest_release | grep -o "\"tag_name\": \"[^\"]*" | cut -d \" -f 4)
current=$(head -n 1 VERSIONS.txt | tr -d '[:space:]')
if [ $? -ne 0 ]
then echo "No VERSIONS.txt please run from lib/"
fi
if [ $current == $tag ]
then echo "Already updated to the latest."; exit 0
fi
save_to=~/Downloads/$(basename $download_link)
echo "Downloading to " $save_to
curl -sL $download_link > $save_to
unzip -o $save_to -d ..

View file

@ -0,0 +1,16 @@
#! /bin/bash
cd $(dirname $0)
latest_release=$(curl -s "https://api.github.com/repos/adafruit/Adafruit_CircuitPython_Bundle/releases/latest")
download_link=$(echo $latest_release | grep -o "\"browser_download_url\": \"[^\"]*" | cut -d \" -f 4)
tag=$(echo $latest_release | grep -o "\"tag_name\": \"[^\"]*" | cut -d \" -f 4)
current=$(head -n 1 VERSIONS.txt | tr -d '[:space:]')
if [ $? -ne 0 ]
then echo "No VERSIONS.txt please run from lib/"
fi
if [ $current == $tag ]
then echo "Already updated to the latest."; exit 0
fi
save_to=~/Downloads/$(basename $download_link)
echo "Downloading to " $save_to
curl -sL $download_link > $save_to
unzip -o $save_to -d ..