Skip to content

Commit

Permalink
Add an "--only" flag to quickly build just one kind of artifact
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jepler committed Jan 2, 2024
1 parent 5de7f05 commit 1fa9182
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions circuitpython_build_tools/scripts/build_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,17 @@ 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.")
@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('--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(", ")
Expand All @@ -259,6 +261,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,
Expand Down

0 comments on commit 1fa9182

Please sign in to comment.