Skip to content

Commit a185a49

Browse files
committed
Initial commit with files from the Adafruit bundle.
0 parents  commit a185a49

10 files changed

+291
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "circuitpython"]
2+
path = circuitpython
3+
url = https://github.com/adafruit/circuitpython.git

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Adafruit Industries
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CircuitPython Community Library Bundle
2+
3+
[![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)
4+
5+
This repo bundles a bunch of useful CircuitPython libraries into an easy to
6+
download zip file. CircuitPython boards can ship with the contents of the zip to
7+
make it easy to provide a lot of libraries by default.
8+
9+
# License
10+
Each included library has its own license that must allow for redistribution. To
11+
save space, license text is not included in the bundle. However, a link to each
12+
individual repository is which should provide source code access and license
13+
information.
14+
15+
# Use
16+
To use the bundle download the zip (not source zip) from the
17+
[latest release](https://github.com/adafruit/CircuitPython_Community_Bundle/releases/latest),
18+
unzip it and copy over the subfolders, such as `lib`, into the root of your
19+
CircuitPython device. Make sure to indicate that it should be merged with the
20+
existing folder when it exists.
21+
22+
# Development
23+
24+
After you clone this repository you must run `git submodule --init` on update
25+
also do `git submodule update`.
26+
27+
## Updating libraries
28+
To update the libraries run `update-submodules.sh`. The script will fetch the
29+
latest code and update to the newest tag (not master).
30+
31+
## Adding a library
32+
Determine the best location within `libraries` for the new library and then run:
33+
34+
git submodule add <git url> libraries/<target directory>
35+
36+
The target directory should omit any MicroPython or CircuitPython specific
37+
prefixes such as `CircuitPython_` to simplify the listing.
38+
39+
## Removing a library
40+
Only do this if you are replacing the module with an equivalent:
41+
42+
git submodule deinit libraries/<target directory>
43+
git rm libraries/<target directory>
44+
45+
## Building the bundle
46+
To build the bundle run `build-bundle.py` it requires Python 3.5+ and will
47+
produce a zip file in `build`. The file structure of the zip will not be
48+
identical to the source `libraries` directory in order to save space. Libraries
49+
with a single source will not be placed in their own directory.

README.txt

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

build-bundle.py

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env python3
2+
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
import os
26+
import shlex
27+
import shutil
28+
import sys
29+
import subprocess
30+
import zipfile
31+
32+
os.chdir("circuitpython/mpy-cross")
33+
make = subprocess.run(["make"])
34+
os.chdir("../../")
35+
36+
if make.returncode != 0:
37+
print("Unable to make mpy-cross.")
38+
sys.exit(1)
39+
40+
mpy_cross = "circuitpython/mpy-cross/mpy-cross"
41+
42+
if "build" in os.listdir("."):
43+
print("Deleting existing build.")
44+
shutil.rmtree("build")
45+
os.mkdir("build")
46+
os.mkdir("build/lib")
47+
48+
success = True
49+
total_size = 512
50+
for subdirectory in os.listdir("libraries"):
51+
for library in os.listdir(os.path.join("libraries", subdirectory)):
52+
library_path = os.path.join("libraries", subdirectory, library)
53+
54+
py_files = []
55+
package_files = []
56+
for filename in os.listdir(library_path):
57+
full_path = os.path.join(library_path, filename)
58+
if os.path.isdir(full_path) and os.path.isfile(os.path.join(full_path, "__init__.py")):
59+
files = os.listdir(full_path)
60+
files = filter(lambda x: x.endswith(".py"), files)
61+
files = map(lambda x: os.path.join(filename, x), files)
62+
package_files.extend(files)
63+
if filename.endswith(".py") and filename != "setup.py" and filename != "conf.py":
64+
py_files.append(filename)
65+
66+
output_directory = os.path.join("build", "lib")
67+
if len(py_files) > 1:
68+
output_directory = os.path.join(output_directory, library)
69+
os.makedirs(output_directory)
70+
package_init = os.path.join(output_directory, "__init__.py")
71+
with open(package_init, 'a'):
72+
pass
73+
print(output_directory, 512)
74+
total_size += 512
75+
76+
if len(package_files) > 1:
77+
for fn in package_files:
78+
base_dir = os.path.join(output_directory, os.path.dirname(fn))
79+
if not os.path.isdir(base_dir):
80+
os.makedirs(base_dir)
81+
print(base_dir, 512)
82+
total_size += 512
83+
84+
for filename in py_files:
85+
full_path = os.path.join(library_path, filename)
86+
output_file = os.path.join(output_directory, filename.replace(".py", ".mpy"))
87+
mpy_success = subprocess.call([mpy_cross, "-o", output_file, full_path])
88+
if mpy_success != 0:
89+
print("mpy-cross failed on", full_path)
90+
success = False
91+
continue
92+
93+
for filename in package_files:
94+
full_path = os.path.join(library_path, filename)
95+
if os.stat(full_path).st_size == 0 or filename.endswith("__init__.py"):
96+
output_file = os.path.join(output_directory, filename)
97+
shutil.copyfile(full_path, output_file)
98+
else:
99+
output_file = os.path.join(output_directory, filename.replace(".py", ".mpy"))
100+
mpy_success = subprocess.call([mpy_cross, "-o", output_file, full_path])
101+
if mpy_success != 0:
102+
print("mpy-cross failed on", full_path)
103+
success = False
104+
continue
105+
106+
version = None
107+
tag = subprocess.run(shlex.split("git describe --tags --exact-match"), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
108+
if tag.returncode == 0:
109+
version = tag.stdout.strip()
110+
else:
111+
commitish = subprocess.run(shlex.split("git log --pretty=format:'%h' -n 1"), stdout=subprocess.PIPE)
112+
version = commitish.stdout.strip()
113+
114+
with open("build/lib/VERSIONS.txt", "w") as f:
115+
f.write(version.decode("utf-8", "strict") + "\r\n")
116+
versions = subprocess.run(shlex.split("git submodule foreach \"git remote get-url origin && git describe --tags\""), stdout=subprocess.PIPE)
117+
repo = None
118+
for line in versions.stdout.split(b"\n"):
119+
if line.startswith(b"Entering") or not line:
120+
continue
121+
if line.startswith(b"git@"):
122+
repo = b"https://github.com/" + line.split(b":")[1][:-len(".git")]
123+
elif line.startswith(b"https:"):
124+
repo = line.strip()
125+
else:
126+
f.write(repo.decode("utf-8", "strict") + "/releases/tag/" + line.strip().decode("utf-8", "strict") + "\r\n")
127+
128+
zip_filename = 'build/circuitpython-community-bundle-' + version.decode("utf-8", "strict") + '.zip'
129+
130+
def add_file(bundle, src_file, zip_name):
131+
global total_size
132+
bundle.write(src_file, zip_name)
133+
file_size = os.stat(src_file).st_size
134+
file_sector_size = file_size
135+
if file_size % 512 != 0:
136+
file_sector_size = (file_size // 512 + 1) * 512
137+
total_size += file_sector_size
138+
print(zip_name, file_size, file_sector_size)
139+
140+
with zipfile.ZipFile(zip_filename, 'w') as bundle:
141+
add_file(bundle, "README.txt", "lib/README.txt")
142+
for filename in os.listdir("update_scripts"):
143+
src_file = os.path.join("update_scripts", filename)
144+
add_file(bundle, src_file, os.path.join("lib", filename))
145+
for root, dirs, files in os.walk("build/lib"):
146+
ziproot = root[len("build/"):].replace("-", "_")
147+
for filename in files:
148+
add_file(bundle, os.path.join(root, filename),
149+
os.path.join(ziproot, filename.replace("-", "_")))
150+
151+
print()
152+
print(total_size, "B", total_size / 1024, "kiB", total_size / 1024 / 1024, "MiB")
153+
print("Bundled in", zip_filename)
154+
if not success:
155+
sys.exit(2)

circuitpython

Submodule circuitpython added at f1e2afb

update-submodules.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#! /bin/bash
2+
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
# This script updates all submodules to the latest tag (hopefully release).
26+
git submodule update
27+
git submodule foreach git fetch
28+
git submodule foreach "tag=\$(git rev-list --tags --max-count=1); git checkout -q \$tag"

update_scripts/update_linux.sh

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

update_scripts/update_macosx.command

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

0 commit comments

Comments
 (0)