Skip to content

Commit c38f93d

Browse files
committed
restructure package file bundling; uses folder name prefix string
1 parent d8c18da commit c38f93d

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

circuitpython_build_tools/build.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,30 @@ def _munge_to_temp(original_path, temp_file, library_version):
100100
temp_file.write(line.encode("utf-8") + b"\r\n")
101101
temp_file.flush()
102102

103-
def library(library_path, output_directory, mpy_cross=None, example_bundle=False):
103+
def library(library_path, output_directory, mpy_cross=None, example_bundle=False, pkg_folder_prefix=None):
104104
py_files = []
105105
package_files = []
106106
example_files = []
107107
total_size = 512
108108
for filename in os.listdir(library_path):
109109
full_path = os.path.join(library_path, filename)
110-
if os.path.isdir(full_path) and filename not in ["docs"]:
110+
if os.path.isdir(full_path):
111111
files = os.listdir(full_path)
112112
files = filter(lambda x: x.endswith(".py") or x.startswith("font5x8.bin"), files)
113113
files = map(lambda x: os.path.join(filename, x), files)
114114
if filename.startswith("examples"):
115115
example_files.extend(files)
116+
#print(" - example files: {}".format(example_files))
116117
else:
118+
if pkg_folder_prefix:
119+
if (not example_bundle and
120+
not filename.startswith(pkg_folder_prefix)):
121+
print("skipped path: {}".format(full_path))
122+
continue
117123
if not example_bundle:
118124
package_files.extend(files)
125+
#print(" - package files: {}".format(package_files))
126+
119127
if (filename.endswith(".py") and
120128
filename not in IGNORE_PY and
121129
not example_bundle):

circuitpython_build_tools/scripts/build_bundles.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def add_file(bundle, src_file, zip_name):
4949

5050

5151
def build_bundle(libs, bundle_version, output_filename,
52-
build_tools_version="devel", mpy_cross=None, example_bundle=False):
52+
build_tools_version="devel", mpy_cross=None, example_bundle=False,
53+
pkg_folder_prefix=None):
5354
build_dir = "build-" + os.path.basename(output_filename)
5455
top_folder = os.path.basename(output_filename).replace(".zip", "")
5556
build_lib_dir = os.path.join(build_dir, top_folder, "lib")
@@ -69,8 +70,8 @@ def build_bundle(libs, bundle_version, output_filename,
6970
success = True
7071
for library_path in libs:
7172
try:
72-
build.library(library_path, build_lib_dir, mpy_cross=mpy_cross,
73-
example_bundle=example_bundle)
73+
build.library(library_path, build_lib_dir, pkg_folder_prefix=pkg_folder_prefix,
74+
mpy_cross=mpy_cross, example_bundle=example_bundle)
7475
except ValueError as e:
7576
print("build.library failure:", library_path)
7677
print(e)
@@ -135,7 +136,8 @@ def _find_libraries(current_path, depth):
135136
@click.option('--output_directory', default="bundles", help="Output location for the zip files.")
136137
@click.option('--library_location', required=True, help="Location of libraries to bundle.")
137138
@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.")
138-
def build_bundles(filename_prefix, output_directory, library_location, library_depth):
139+
@click.option('--package_folder_prefix', default=None, required=False, help="Prefix string used to determine package folders to bundle.")
140+
def build_bundles(filename_prefix, output_directory, library_location, library_depth, pkg_folder_prefix):
139141
os.makedirs(output_directory, exist_ok=True)
140142

141143
bundle_version = build.version_string()
@@ -158,6 +160,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
158160
filename_prefix + '-py-{VERSION}.zip'.format(
159161
VERSION=bundle_version))
160162
build_bundle(libs, bundle_version, zip_filename,
163+
pkg_folder_prefix=pkg_folder_prefix,
161164
build_tools_version=build_tools_version)
162165

163166
# Build .mpy bundle(s)
@@ -175,7 +178,8 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
175178
TAG=version["name"],
176179
VERSION=bundle_version))
177180
build_bundle(libs, bundle_version, zip_filename, mpy_cross=mpy_cross,
178-
build_tools_version=build_tools_version)
181+
build_tools_version=build_tools_version,
182+
pkg_folder_prefix=pkg_folder_prefix)
179183

180184
# Build example bundle
181185
zip_filename = os.path.join(output_directory,

0 commit comments

Comments
 (0)