From ea28feb31d02cd82991a8ef3e10a863cbda5c2c4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 11 Jan 2024 08:58:56 -0600 Subject: [PATCH 1/2] Fix generation of dependencies[] array --- circuitpython_build_tools/scripts/build_bundles.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/circuitpython_build_tools/scripts/build_bundles.py b/circuitpython_build_tools/scripts/build_bundles.py index 0962c5b..ae3401c 100755 --- a/circuitpython_build_tools/scripts/build_bundles.py +++ b/circuitpython_build_tools/scripts/build_bundles.py @@ -117,7 +117,11 @@ def build_bundle_json(libs, bundle_version, output_filename, package_folder_pref """ Generate a JSON file of all the libraries in libs """ - packages = [] + packages = {} + # TODO simplify this 2-step process + # It mostly exists so that get_bundle_requirements has a way to look up + # "pypi name to bundle name" via `package_list[pypi_name]["module_name"]` + # otherwise it's just shuffling info around for library_path in libs: package = {} package_info = build.get_package_info(library_path, package_folder_prefix) @@ -130,10 +134,10 @@ def build_bundle_json(libs, bundle_version, output_filename, package_folder_pref package["version"] = package_info["version"] package["path"] = "lib/" + package_info["module_name"] package["library_path"] = library_path - packages.append(package) + packages[module_name] = package library_submodules = {} - for package in packages: + for package in packages.values(): library = {} library["package"] = package["is_folder"] library["pypi_name"] = package["pypi_name"] From 90a2341e0454bc8dcf3272e20c4e880fa5343cd4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 2 Jan 2024 10:25:45 -0600 Subject: [PATCH 2/2] Add an "--only" flag to quickly build just one kind of artifact Most often I find that I want to check just one kind of artifact (e.g., mpy files) and this is a quicker syntax than excluding the other 3 types with 3 --ignores. --- circuitpython_build_tools/scripts/build_bundles.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/circuitpython_build_tools/scripts/build_bundles.py b/circuitpython_build_tools/scripts/build_bundles.py index ae3401c..3c31185 100755 --- a/circuitpython_build_tools/scripts/build_bundles.py +++ b/circuitpython_build_tools/scripts/build_bundles.py @@ -235,6 +235,7 @@ def _find_libraries(current_path, depth): subdirectories.extend(_find_libraries(path, depth - 1)) return subdirectories +all_modules = ["py", "mpy", "example", "json"] @click.command() @click.option('--filename_prefix', required=True, help="Filename prefix for the output zip files.") @click.option('--output_directory', default="bundles", help="Output location for the zip files.") @@ -242,8 +243,9 @@ def _find_libraries(current_path, depth): @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('--package_folder_prefix', default="adafruit_", help="Prefix string used to determine package folders to bundle.") @click.option('--remote_name', default="origin", help="Git remote name to use during building") -@click.option('--ignore', "-i", multiple=True, type=click.Choice(["py", "mpy", "example", "json"]), help="Bundles to ignore building") -def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix, remote_name, ignore): +@click.option('--ignore', "-i", multiple=True, type=click.Choice(all_modules), help="Bundles to ignore building") +@click.option('--only', "-o", multiple=True, type=click.Choice(all_modules), help="Bundles to build building") +def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix, remote_name, ignore, only): os.makedirs(output_directory, exist_ok=True) package_folder_prefix = package_folder_prefix.split(", ") @@ -263,6 +265,11 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d with open(build_tools_fn, "w") as f: f.write(build_tools_version) + if ignore and only: + raise SystemExit("Only specify one of --ignore / --only") + if only: + ignore = set(all_modules) - set(only) + # Build raw source .py bundle if "py" not in ignore: zip_filename = os.path.join(output_directory,