Compare commits

...

68 commits

Author SHA1 Message Date
Dan Halbert
4672763fab
Merge pull request #58 from adafruit/tannewt-patch-7
Stop releasing for 5.x
2021-01-28 14:23:10 -05:00
Scott Shawcroft
a292909c21
Stop releasing for 5.x
5.x bundles would break with the pwmio.PWMOut changes otherwise.
2021-01-28 11:09:41 -08:00
Dan Halbert
06c4237c08
Merge pull request #57 from adafruit/tannewt-patch-7
Update versions for mpy-cross
2021-01-20 13:51:42 -05:00
Scott Shawcroft
bab005fb54
Update versions for mpy-cross
This brings in f-string support.
2021-01-20 10:47:06 -08:00
Limor "Ladyada" Fried
2c982ad536
Merge pull request #56 from mcauser/patch-1
Fix expired Discord link
2020-12-07 10:06:11 -05:00
Mike Causer
181368b0e4
Fix expired Discord link 2020-12-08 01:21:05 +11:00
Kattni
381253f2ae
Merge pull request #54 from adafruit/tannewt-patch-6
Turn off 4.x bundles and enable 6.x
2020-07-06 19:17:04 -04:00
Scott Shawcroft
8ccfa837a3
Turn off 4.x bundles and enable 6.x 2020-07-06 15:33:56 -07:00
Jeff Epler
b014d651cd
Merge pull request #53 from joedevivo/master
Added `ssh://git@` url pattern
2019-12-27 14:30:15 -06:00
Joe DeVivo
0fe0ed6353 My git urls look like ssh://git@github.com/**/.git 2019-12-27 08:26:09 -07:00
Kattni
e5da2baed3
Merge pull request #52 from sommersoft/fix_mpy_cross
Properly Truncate mpy Filenames
2019-10-15 19:46:26 -04:00
sommersoft
283d8286bd properly truncate mpy filenames 2019-10-15 17:28:38 -05:00
Scott Shawcroft
318fa70652
Merge pull request #50 from sommersoft/new_path_walk
Allow Multiple Package Folder Prefixes; Improve File Gathering
2019-09-25 11:13:09 -07:00
sommersoft
b803b26f4a allow for multiple entries for the 'package_folder_prefix" argument 2019-09-24 21:54:02 -05:00
sommersoft
83ecd9525a use 'pathlib' vs 'os.walk' to gather files 2019-09-24 18:40:09 -05:00
Kattni
ffcbdc598c
Merge pull request #47 from adafruit/tannewt-patch-5
Add 5.x and remove 2.x and 3.x
2019-09-03 17:35:39 -04:00
Scott Shawcroft
098a636b09
Add 5.x and remove 2.x and 3.x
The libraries may not support the older versions so remove them.
2019-08-22 20:59:36 -07:00
Kattni
26ca8730a1
Merge pull request #46 from sommersoft/test_examps_bundle
Fix Example Bundling When 'examples' In Subfolder Name
2019-08-18 11:38:45 -04:00
sommersoft
519c62f3aa allow subfolders with 'examples' in the name, without truncating the path 2019-08-18 08:09:23 -05:00
Scott Shawcroft
800ee1a567
Merge pull request #44 from sommersoft/fix_subfolder
Retain Full Subfolder Structure In Packages
2019-05-31 17:12:49 -07:00
sommersoft
8175c6c9a0 retain full subfolder structure in packages 2019-05-31 18:49:59 -05:00
sommersoft
930c053791
Merge pull request #42 from sommersoft/more_fix_deploy
Re-add `on: tags: true` to Travis deploy
2019-05-23 19:13:17 -05:00
sommersoft
1d60da1bb1 re-add to deployment 2019-05-23 18:43:07 -05:00
Kattni
a5b09751d5
Merge pull request #41 from sommersoft/fix_deploy
Fix PyPI Deployment
2019-05-23 19:16:43 -04:00
sommersoft
d19f810cbe restructure .travis.yml so that releases actually trigger a PyPI deployment 2019-05-23 18:07:35 -05:00
Kattni
fbb43bd2d8
Merge pull request #40 from sommersoft/fix_arg_round_2
Attempt 2: Include mpy-cross '__init__.py' In Packages; Restructure Package Bundling
2019-05-15 13:46:41 -04:00
sommersoft
7f8af9417d de-confuse 'package_folder_prefix' parameter naming 2019-05-14 20:29:52 -05:00
sommersoft
0e839df058 README: remove build mpy-cross cmd in local testing; only used on Travis 2019-05-11 09:33:41 -05:00
sommersoft
50ddabd2cc change 'package_folder_prefix' to a pos arg; grab examples subfolders 2019-05-11 09:32:21 -05:00
sommersoft
18df89a3ef Merge branch 'master' of https://github.com/adafruit/circuitpython-build-tools into fix_arg_round_2 2019-05-10 18:44:45 -05:00
Scott Shawcroft
63c6be10cb
Merge pull request #39 from sommersoft/add_pr_tests
Add Test Matrix For Pull Requests
2019-05-09 13:36:40 -07:00
sommersoft
67abd08f71 missed local testing step: build mpy-cross's 2019-05-08 17:28:17 -05:00
sommersoft
1079f0b041 README: add local test example, and CoC link. 2019-05-08 17:07:50 -05:00
sommersoft
3c51a8bfff include a test matrix for PRs; one for the whole bundle, and one for a single library. 2019-05-08 16:57:57 -05:00
sommersoft
6fa843f03c add '.env/' to .gitignore 2019-05-08 16:55:55 -05:00
sommersoft
03373f49a9 set @click 'package_folder_prefix' default to 'adafruit_' to maintain backwards compatibility 2019-05-07 20:39:07 -05:00
sommersoft
f9ac09d94e Revert "Revert "Fix arg; again...""
This reverts commit 495627bf29.
2019-05-07 18:13:39 -05:00
sommersoft
346ab583d0 Revert "Revert "Fix Mismatched arg Between Click And build_bundles()""
This reverts commit e010f5a10d.
2019-05-07 18:13:12 -05:00
sommersoft
55c69b7b66 Revert "Revert "Include mpy-cross '__init__.py' In Packages; Restructure Package Bundling""
This reverts commit cd1a858a01.
2019-05-07 18:12:43 -05:00
Kattni
7804a09df1
Merge pull request #38 from adafruit/revert-31-include_init
Revert "Include mpy-cross '__init__.py' In Packages; Restructure Package Bundling"
2019-05-07 15:04:30 -04:00
Kattni
cd1a858a01
Revert "Include mpy-cross '__init__.py' In Packages; Restructure Package Bundling" 2019-05-07 15:04:16 -04:00
Kattni
b7c8f712f8
Merge pull request #37 from adafruit/revert-33-fix_arg
Revert "Fix Mismatched arg Between Click And build_bundles()"
2019-05-07 15:03:48 -04:00
Kattni
e010f5a10d
Revert "Fix Mismatched arg Between Click And build_bundles()" 2019-05-07 15:03:34 -04:00
Kattni
514ff6cc46
Merge pull request #36 from adafruit/revert-35-fix_arg
Revert "Fix arg; again..."
2019-05-07 15:03:19 -04:00
Kattni
495627bf29
Revert "Fix arg; again..." 2019-05-07 15:01:54 -04:00
Melissa LeBlanc-Williams
4296d661cd
Merge pull request #35 from sommersoft/fix_arg
Fix arg; again...
2019-05-07 11:54:15 -04:00
sommersoft
84aff92793 Merge branch 'master' of https://github.com/adafruit/circuitpython-build-tools into fix_arg 2019-05-07 10:51:04 -05:00
sommersoft
17bfe9642c return of the lost commit (or i forgot it) 2019-05-07 10:49:44 -05:00
Melissa LeBlanc-Williams
c4fa036265
Merge pull request #33 from sommersoft/fix_arg
Fix Mismatched arg Between Click And build_bundles()
2019-05-07 11:20:44 -04:00
sommersoft
a96f2bec8b fix mismatched arg between Click and build_bundles() 2019-05-06 21:55:52 -05:00
Kattni
44c07484ef
Merge pull request #31 from sommersoft/include_init
Include mpy-cross '__init__.py' In Packages; Restructure Package Bundling
2019-05-06 21:14:40 -04:00
sommersoft
f803ba57a3 build.py->library: refactor file selection, so it includes subfolders 2019-05-06 10:44:22 -05:00
sommersoft
732c144b36 remove local debuggy stuff that snuck in 2019-05-02 21:40:31 -05:00
sommersoft
92138a56fd include package file based on package name prefix 2019-05-02 21:35:26 -05:00
sommersoft
c38f93dcc4 restructure package file bundling; uses folder name prefix string 2019-05-02 13:15:32 -05:00
sommersoft
d8c18da0b6 remove mpy-cross exclusion for '__init__.py' in packaged modules 2019-05-02 12:09:15 -05:00
sommersoft
2d7b35831b
Merge pull request #27 from dhalbert/build-bundle-no-entering
Simplify parsing git output in build_bundle.
2019-02-14 10:14:06 -06:00
Dan Halbert
97f95cc5f7 add wheel to requirements.txt 2019-02-14 11:03:16 -05:00
Dan Halbert
96c66762ce add pip install wheel to README.md 2019-02-14 09:23:26 -05:00
Dan Halbert
8d38cf8ee6 ugh; remove redundant --quiet 2019-02-14 09:21:05 -05:00
Dan Halbert
3b2e59091b Simplify prasing git output in build_bundle. 2019-02-14 09:17:27 -05:00
Kattni
6d26530586
Merge pull request #24 from sommersoft/framebuf_font
Include Font Binary for adafruit_framebuf
2019-02-05 13:43:30 -05:00
sommersoft
5256b1b1a9 include 'font5x8.bin' in examples for adafruit_framebuf 2019-02-04 22:29:46 -06:00
Scott Shawcroft
1475ae79b6
Merge pull request #23 from sommersoft/folder_rename
Fix Zip Top-Level Folder Name
2018-11-15 10:35:11 -08:00
sommersoft
b3808371c1 remove 'build' from top-level folder name in zipfile 2018-11-14 22:50:36 -06:00
Kattni
ce7dc588a8
Merge pull request #22 from sommersoft/folder_rename
Rename Folder In Zip
2018-11-10 15:59:31 -05:00
sommersoft
929ebf7d70 match top folder name to zip name [drop 'replace("-", "_")'] 2018-11-10 10:23:36 -06:00
Dan Halbert
5983c59cef
Merge pull request #21 from adafruit/add-temp-2x-bundle
Reenable 2.x bundle
2018-10-29 16:44:52 -04:00
7 changed files with 163 additions and 73 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ dist
circuitpython_build_tools/data/ circuitpython_build_tools/data/
.eggs .eggs
version.py version.py
.env/*

View file

@ -1,17 +1,50 @@
sudo: false dist: xenial
dist: trusty
language: python language: python
python: python:
- '3.6' - '3.6'
script:
- python3 -m circuitpython_build_tools.scripts.build_mpy_cross circuitpython_build_tools/data/
stages:
- name: Tests
if: type = pull_request
- name: deploy
if: tag IS present
jobs:
include:
- stage: Tests
name: "Test CircuitPython Bundle"
python: "3.6"
script:
- echo "Building mpy-cross" && echo "travis_fold:start:mpy-cross"
- python3 -u -m circuitpython_build_tools.scripts.build_mpy_cross circuitpython_build_tools/data/
- echo "travis_fold:end:mpy-cross"
- pip install -e .
- echo "Cloning Adafruit_CircuitPython_Bundle" && echo "travis_fold:start:clone"
- git clone --recurse-submodules https://github.com/adafruit/Adafruit_CircuitPython_Bundle.git
- echo "travis_fold:end:clone"
- cd Adafruit_CircuitPython_Bundle
- circuitpython-build-bundles --filename_prefix test-bundle --library_location libraries --library_depth 2
- stage: Tests
name: "Test Single Library Bundle"
script:
- echo "Building mpy-cross" && echo "travis_fold:start:mpy-cross"
- python3 -u -m circuitpython_build_tools.scripts.build_mpy_cross circuitpython_build_tools/data/
- echo "travis_fold:end:mpy-cross"
- pip install -e .
- git clone https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git
- cd Adafruit_CircuitPython_FeatherWing
- circuitpython-build-bundles --filename_prefix test-single --library_location .
- stage: deploy
script:
- python3 -u -m circuitpython_build_tools.scripts.build_mpy_cross circuitpython_build_tools/data/
deploy:
provider: pypi
user: "adafruit-travis"
password:
secure: tCjXwD8YeitG0HZLxW1D1QlVv4Xbj8mfRoqW0CM9ikPp3KY1PCz6Axj0PiOcyVwKdnxcUQ0EGRl16wEqwkObrmo9MboYrPuPqN00ULmyCQCRvJa2abIN6jDoLtBuf6bcze88t0XY2LdMOcj2Udv5Iijgf95zUgE+Z6BqT9Rgche78JEOeANJ7BlAJ6nRCA4whDdG7J9s7SmFtIjKWtMxig2J3X+Qy0bZ+Armtfp9/CRvjLJ8juDrcCBSysWLnAYLS4u8e/rbSTh8YwFeoeJ1pp9qSmME5NuwScY18QmfESNSqz8wVVXtAFKdoMOCoN+/CodTxp9aB0QsXX6yOYg74ahDIaci239wgnuUqxSaeLxeSwWkkVCXWdQVuP4vgq3GZwm2yNOQ1ZjfFbXF156yv0uSVw5nuaxv0YblQTinJtL4x9hwOdPDJio3b6UT3H1ue9l1qK0LT2OSkzDgn12WmTnTfRUH3BkU6onsYsdP33PK1YhepeQnfbT1P3ikrRHIwGYb7XqcjOtJh413kid6YezCXRqccl8kAxegnqX+cQG7K9ilpZtWaVYLu4RRBJ37H4vpuOb3SV686Y62sWPUXEbI3MR1OxU+RrRr/9DCH1EFXnlYT9LF986wXFJtWuSc+pbXuxY7qduai0hn5Pft6XH31exyiOwAHBIFeYebnVM=
skip_cleanup: true
on:
tags: true
deploy:
provider: pypi
user: "adafruit-travis"
password:
secure: tCjXwD8YeitG0HZLxW1D1QlVv4Xbj8mfRoqW0CM9ikPp3KY1PCz6Axj0PiOcyVwKdnxcUQ0EGRl16wEqwkObrmo9MboYrPuPqN00ULmyCQCRvJa2abIN6jDoLtBuf6bcze88t0XY2LdMOcj2Udv5Iijgf95zUgE+Z6BqT9Rgche78JEOeANJ7BlAJ6nRCA4whDdG7J9s7SmFtIjKWtMxig2J3X+Qy0bZ+Armtfp9/CRvjLJ8juDrcCBSysWLnAYLS4u8e/rbSTh8YwFeoeJ1pp9qSmME5NuwScY18QmfESNSqz8wVVXtAFKdoMOCoN+/CodTxp9aB0QsXX6yOYg74ahDIaci239wgnuUqxSaeLxeSwWkkVCXWdQVuP4vgq3GZwm2yNOQ1ZjfFbXF156yv0uSVw5nuaxv0YblQTinJtL4x9hwOdPDJio3b6UT3H1ue9l1qK0LT2OSkzDgn12WmTnTfRUH3BkU6onsYsdP33PK1YhepeQnfbT1P3ikrRHIwGYb7XqcjOtJh413kid6YezCXRqccl8kAxegnqX+cQG7K9ilpZtWaVYLu4RRBJ37H4vpuOb3SV686Y62sWPUXEbI3MR1OxU+RrRr/9DCH1EFXnlYT9LF986wXFJtWuSc+pbXuxY7qduai0hn5Pft6XH31exyiOwAHBIFeYebnVM=
skip_cleanup: true
on:
tags: true

View file

@ -1,6 +1,6 @@
# Adafruit CircuitPython Build Tools # Adafruit CircuitPython Build Tools
[![Discord](https://img.shields.io/discord/327254708534116352.svg)](https://discord.gg/nBQh6qu) [![Discord](https://img.shields.io/discord/327254708534116352.svg)](https://adafru.it/discord)
This repo contains build scripts used to build the This repo contains build scripts used to build the
[Adafruit CircuitPython bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle), [CircuitPython Community bundle](https://github.com/adafruit/CircuitPython_Community_Bundle) [Adafruit CircuitPython bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle), [CircuitPython Community bundle](https://github.com/adafruit/CircuitPython_Community_Bundle)
@ -56,3 +56,20 @@ source .env/bin/activate
pip install circuitpython-build-tools pip install circuitpython-build-tools
circuitpython-build-bundles --filename_prefix <output file prefix> --library_location . circuitpython-build-bundles --filename_prefix <output file prefix> --library_location .
``` ```
When making changes to `circuitpython-build-tools` itself, you can test your changes
locally like so:
```shell
cd circuitpython-build-tools # this will be specific to your storage location
python3 -m venv .env
source .env/bin/activate
pip install -e . # '-e' is pip's "development" install feature
circuitpython-build-bundles --filename_prefix <output file prefix> --library_location <library location>
```
## Contributing
Contributions are welcome! Please read our [Code of Conduct]
(https://github.com/adafruit/Adafruit_CircuitPython_adabot/blob/master/CODE_OF_CONDUCT.md)
before contributing to help this project stay welcoming.

View file

@ -3,6 +3,7 @@
# The MIT License (MIT) # The MIT License (MIT)
# #
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries # Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
# 2018, 2019 Michael Schroeder
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -24,6 +25,7 @@
import os import os
import os.path import os.path
import pathlib
import semver import semver
import shutil import shutil
import sys import sys
@ -31,6 +33,7 @@ import subprocess
import tempfile import tempfile
IGNORE_PY = ["setup.py", "conf.py", "__init__.py"] IGNORE_PY = ["setup.py", "conf.py", "__init__.py"]
GLOB_PATTERNS = ["*.py", "font5x8.bin"]
def version_string(path=None, *, valid_semver=False): def version_string(path=None, *, valid_semver=False):
version = None version = None
@ -90,39 +93,62 @@ def mpy_cross(mpy_cross_filename, circuitpython_tag, quiet=False):
def _munge_to_temp(original_path, temp_file, library_version): def _munge_to_temp(original_path, temp_file, library_version):
with open(original_path, "rb") as original_file: with open(original_path, "rb") as original_file:
for line in original_file: for line in original_file:
line = line.decode("utf-8").strip("\n") if original_path.endswith(".bin"):
if line.startswith("__version__"): # this is solely for adafruit_framebuf/examples/font5x8.bin
line = line.replace("0.0.0-auto.0", library_version) temp_file.write(line)
temp_file.write(line.encode("utf-8") + b"\r\n") else:
line = line.decode("utf-8").strip("\n")
if line.startswith("__version__"):
line = line.replace("0.0.0-auto.0", library_version)
temp_file.write(line.encode("utf-8") + b"\r\n")
temp_file.flush() temp_file.flush()
def library(library_path, output_directory, mpy_cross=None, example_bundle=False): def library(library_path, output_directory, package_folder_prefix,
mpy_cross=None, example_bundle=False):
py_files = [] py_files = []
package_files = [] package_files = []
example_files = [] example_files = []
total_size = 512 total_size = 512
for filename in os.listdir(library_path):
full_path = os.path.join(library_path, filename) lib_path = pathlib.Path(library_path)
if os.path.isdir(full_path) and filename not in ["docs"]: parent_idx = len(lib_path.parts)
files = os.listdir(full_path) glob_search = []
files = filter(lambda x: x.endswith(".py"), files) for pattern in GLOB_PATTERNS:
files = map(lambda x: os.path.join(filename, x), files) glob_search.extend(list(lib_path.rglob(pattern)))
if filename.startswith("examples"):
example_files.extend(files) for file in glob_search:
else: if file.parts[parent_idx] == "examples":
if not example_bundle: example_files.append(file)
package_files.extend(files) else:
if (filename.endswith(".py") and if not example_bundle:
filename not in IGNORE_PY and is_package = False
not example_bundle): for prefix in package_folder_prefix:
py_files.append(filename) if file.parts[parent_idx].startswith(prefix):
is_package = True
if is_package:
package_files.append(file)
else:
if file.name in IGNORE_PY:
#print("Ignoring:", file.resolve())
continue
if file.parent == lib_path:
py_files.append(file)
if len(py_files) > 1: if len(py_files) > 1:
raise ValueError("Multiple top level py files not allowed. Please put them in a package " raise ValueError("Multiple top level py files not allowed. Please put "
"or combine them into a single file.") "them in a package or combine them into a single file.")
for fn in example_files:
base_dir = os.path.join(output_directory.replace("/lib", "/"),
fn.relative_to(library_path).parent)
if not os.path.isdir(base_dir):
os.makedirs(base_dir)
total_size += 512
for fn in package_files: for fn in package_files:
base_dir = os.path.join(output_directory, os.path.dirname(fn)) base_dir = os.path.join(output_directory,
fn.relative_to(library_path).parent)
if not os.path.isdir(base_dir): if not os.path.isdir(base_dir):
os.makedirs(base_dir) os.makedirs(base_dir)
total_size += 512 total_size += 512
@ -140,16 +166,20 @@ def library(library_path, output_directory, mpy_cross=None, example_bundle=False
for filename in py_files: for filename in py_files:
full_path = os.path.join(library_path, filename) full_path = os.path.join(library_path, filename)
output_file = os.path.join(output_directory, output_file = os.path.join(
filename.replace(".py", new_extension)) output_directory,
filename.relative_to(library_path).with_suffix(new_extension)
)
with tempfile.NamedTemporaryFile() as temp_file: with tempfile.NamedTemporaryFile() as temp_file:
_munge_to_temp(full_path, temp_file, library_version) _munge_to_temp(full_path, temp_file, library_version)
if mpy_cross: if mpy_cross:
mpy_success = subprocess.call([mpy_cross, mpy_success = subprocess.call([
"-o", output_file, mpy_cross,
"-s", filename, "-o", output_file,
temp_file.name]) "-s", str(filename.relative_to(library_path)),
temp_file.name
])
if mpy_success != 0: if mpy_success != 0:
raise RuntimeError("mpy-cross failed on", full_path) raise RuntimeError("mpy-cross failed on", full_path)
else: else:
@ -159,24 +189,29 @@ def library(library_path, output_directory, mpy_cross=None, example_bundle=False
full_path = os.path.join(library_path, filename) full_path = os.path.join(library_path, filename)
with tempfile.NamedTemporaryFile() as temp_file: with tempfile.NamedTemporaryFile() as temp_file:
_munge_to_temp(full_path, temp_file, library_version) _munge_to_temp(full_path, temp_file, library_version)
if (not mpy_cross or if not mpy_cross or os.stat(full_path).st_size == 0:
os.stat(full_path).st_size == 0 or output_file = os.path.join(output_directory,
filename.endswith("__init__.py")): filename.relative_to(library_path))
output_file = os.path.join(output_directory, filename)
shutil.copyfile(temp_file.name, output_file) shutil.copyfile(temp_file.name, output_file)
else: else:
output_file = os.path.join(output_directory, output_file = os.path.join(
filename.replace(".py", new_extension)) output_directory,
mpy_success = subprocess.call([mpy_cross, filename.relative_to(library_path).with_suffix(new_extension)
"-o", output_file, )
"-s", filename,
temp_file.name]) mpy_success = subprocess.call([
mpy_cross,
"-o", output_file,
"-s", str(filename.relative_to(library_path)),
temp_file.name
])
if mpy_success != 0: if mpy_success != 0:
raise RuntimeError("mpy-cross failed on", full_path) raise RuntimeError("mpy-cross failed on", full_path)
for filename in example_files: for filename in example_files:
full_path = os.path.join(library_path, filename) full_path = os.path.join(library_path, filename)
output_file = os.path.join(output_directory.replace("/lib", "/"), filename) output_file = os.path.join(output_directory.replace("/lib", "/"),
filename.relative_to(library_path))
with tempfile.NamedTemporaryFile() as temp_file: with tempfile.NamedTemporaryFile() as temp_file:
_munge_to_temp(full_path, temp_file, library_version) _munge_to_temp(full_path, temp_file, library_version)
shutil.copyfile(temp_file.name, output_file) shutil.copyfile(temp_file.name, output_file)

View file

@ -48,11 +48,12 @@ def add_file(bundle, src_file, zip_name):
return file_sector_size return file_sector_size
def build_bundle(libs, bundle_version, output_filename, def build_bundle(libs, bundle_version, output_filename, package_folder_prefix,
build_tools_version="devel", mpy_cross=None, example_bundle=False): build_tools_version="devel", mpy_cross=None, example_bundle=False):
build_dir = "build-" + os.path.basename(output_filename) build_dir = "build-" + os.path.basename(output_filename)
build_lib_dir = os.path.join(build_dir, build_dir.replace(".zip", ""), "lib") top_folder = os.path.basename(output_filename).replace(".zip", "")
build_example_dir = os.path.join(build_dir, build_dir.replace(".zip", ""), "examples") build_lib_dir = os.path.join(build_dir, top_folder, "lib")
build_example_dir = os.path.join(build_dir, top_folder, "examples")
if os.path.isdir(build_dir): if os.path.isdir(build_dir):
print("Deleting existing build.") print("Deleting existing build.")
shutil.rmtree(build_dir) shutil.rmtree(build_dir)
@ -68,8 +69,8 @@ def build_bundle(libs, bundle_version, output_filename,
success = True success = True
for library_path in libs: for library_path in libs:
try: try:
build.library(library_path, build_lib_dir, mpy_cross=mpy_cross, build.library(library_path, build_lib_dir, package_folder_prefix,
example_bundle=example_bundle) mpy_cross=mpy_cross, example_bundle=example_bundle)
except ValueError as e: except ValueError as e:
print("build.library failure:", library_path) print("build.library failure:", library_path)
print(e) print(e)
@ -78,9 +79,9 @@ def build_bundle(libs, bundle_version, output_filename,
print() print()
print("Generating VERSIONS") print("Generating VERSIONS")
if multiple_libs: if multiple_libs:
with open(os.path.join(build_dir, build_dir.replace(".zip", ""), "VERSIONS.txt"), "w") as f: with open(os.path.join(build_dir, top_folder, "VERSIONS.txt"), "w") as f:
f.write(bundle_version + "\r\n") f.write(bundle_version + "\r\n")
versions = subprocess.run('git submodule foreach \"git remote get-url origin && git describe --tags\"', shell=True, stdout=subprocess.PIPE, cwd=os.path.commonpath(libs)) versions = subprocess.run('git submodule --quiet foreach \"git remote get-url origin && git describe --tags\"', shell=True, stdout=subprocess.PIPE, cwd=os.path.commonpath(libs))
if versions.returncode != 0: if versions.returncode != 0:
print("Failed to generate versions file. Its likely a library hasn't been " print("Failed to generate versions file. Its likely a library hasn't been "
"released yet.") "released yet.")
@ -88,9 +89,11 @@ def build_bundle(libs, bundle_version, output_filename,
repo = None repo = None
for line in versions.stdout.split(b"\n"): for line in versions.stdout.split(b"\n"):
if line.startswith(b"Entering") or not line: if not line:
continue continue
if line.startswith(b"git@"): if line.startswith(b"ssh://git@"):
repo = b"https://" + line.split(b"@")[1][:-len(".git")]
elif line.startswith(b"git@"):
repo = b"https://github.com/" + line.split(b":")[1][:-len(".git")] repo = b"https://github.com/" + line.split(b":")[1][:-len(".git")]
elif line.startswith(b"https:"): elif line.startswith(b"https:"):
repo = line.strip()[:-len(".git")] repo = line.strip()[:-len(".git")]
@ -108,10 +111,9 @@ def build_bundle(libs, bundle_version, output_filename,
build_metadata = {"build-tools-version": build_tools_version} build_metadata = {"build-tools-version": build_tools_version}
bundle.comment = json.dumps(build_metadata).encode("utf-8") bundle.comment = json.dumps(build_metadata).encode("utf-8")
if multiple_libs: if multiple_libs:
readme_zip_dir = build_dir.replace(".zip", "") total_size += add_file(bundle, "README.txt", os.path.join(top_folder, "README.txt"))
total_size += add_file(bundle, "README.txt", os.path.join(readme_zip_dir.replace("-", "_"), "README.txt"))
for root, dirs, files in os.walk(build_dir): for root, dirs, files in os.walk(build_dir):
ziproot = root[len(build_dir + "/"):].replace("-", "_") ziproot = root[len(build_dir + "/"):]
for filename in files: for filename in files:
total_size += add_file(bundle, os.path.join(root, filename), total_size += add_file(bundle, os.path.join(root, filename),
os.path.join(ziproot, filename.replace("-", "_"))) os.path.join(ziproot, filename.replace("-", "_")))
@ -135,9 +137,12 @@ def _find_libraries(current_path, depth):
@click.option('--output_directory', default="bundles", help="Output location for the zip files.") @click.option('--output_directory', default="bundles", help="Output location for the zip files.")
@click.option('--library_location', required=True, help="Location of libraries to bundle.") @click.option('--library_location', required=True, help="Location of libraries to bundle.")
@click.option('--library_depth', default=0, help="Depth of library folders. This is useful when multiple libraries are bundled together but are initially in separate subfolders.") @click.option('--library_depth', default=0, help="Depth of library folders. This is useful when multiple libraries are bundled together but are initially in separate subfolders.")
def build_bundles(filename_prefix, output_directory, library_location, library_depth): @click.option('--package_folder_prefix', default="adafruit_", help="Prefix string used to determine package folders to bundle.")
def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix):
os.makedirs(output_directory, exist_ok=True) os.makedirs(output_directory, exist_ok=True)
package_folder_prefix = package_folder_prefix.split(", ")
bundle_version = build.version_string() bundle_version = build.version_string()
libs = _find_libraries(os.path.abspath(library_location), library_depth) libs = _find_libraries(os.path.abspath(library_location), library_depth)
@ -157,7 +162,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
zip_filename = os.path.join(output_directory, zip_filename = os.path.join(output_directory,
filename_prefix + '-py-{VERSION}.zip'.format( filename_prefix + '-py-{VERSION}.zip'.format(
VERSION=bundle_version)) VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
build_tools_version=build_tools_version) build_tools_version=build_tools_version)
# Build .mpy bundle(s) # Build .mpy bundle(s)
@ -174,12 +179,12 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
filename_prefix + '-{TAG}-mpy-{VERSION}.zip'.format( filename_prefix + '-{TAG}-mpy-{VERSION}.zip'.format(
TAG=version["name"], TAG=version["name"],
VERSION=bundle_version)) VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, mpy_cross=mpy_cross, build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
build_tools_version=build_tools_version) mpy_cross=mpy_cross, build_tools_version=build_tools_version)
# Build example bundle # Build example bundle
zip_filename = os.path.join(output_directory, zip_filename = os.path.join(output_directory,
filename_prefix + '-examples-{VERSION}.zip'.format( filename_prefix + '-examples-{VERSION}.zip'.format(
VERSION=bundle_version)) VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
build_tools_version=build_tools_version, example_bundle=True) build_tools_version=build_tools_version, example_bundle=True)

View file

@ -25,7 +25,5 @@
# The tag specifies which version of CircuitPython to use for mpy-cross. # The tag specifies which version of CircuitPython to use for mpy-cross.
# The name is used when constructing the zip file names. # The name is used when constructing the zip file names.
VERSIONS = [ VERSIONS = [
{"tag": "2.3.1", "name": "2.x"}, {"tag": "6.1.0", "name": "6.x"},
{"tag": "3.0.0", "name": "3.x"},
{"tag": "4.0.0-alpha.2", "name": "4.x"},
] ]

View file

@ -1,2 +1,3 @@
Click Click
semver semver
wheel