Skip to content

Allow bundles to be skipped #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 36 additions & 29 deletions circuitpython_build_tools/scripts/build_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ 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")
def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix, remote_name):
@click.option('--ignore', default="", help="Bundles to ignore building")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not tickled about the separator being ", " since this requires shell quoting --ignore "py, mpy" and is easy to get wrong, --ignore py,mpy is an undiagnosed error.

If you use @click.option('--ignore', '-i', multiple=True, type=click.Choice(["py", "mpy", "json"])) then you don't have to do the parsing, you just give zero or more --ignore arguments, and errors are detected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I also felt not great about that, but your suggestion is MUCH more elegant. I'll fix this up this evening!

def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix, remote_name, ignore):
skip_bundles = ignore.lower().split(", ")

os.makedirs(output_directory, exist_ok=True)

package_folder_prefix = package_folder_prefix.split(", ")
Expand All @@ -255,38 +258,42 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
f.write(build_tools_version)

# Build raw source .py bundle
zip_filename = os.path.join(output_directory,
filename_prefix + '-py-{VERSION}.zip'.format(
VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
build_tools_version=build_tools_version, remote_name=remote_name)

# Build .mpy bundle(s)
os.makedirs("build_deps", exist_ok=True)
for version in target_versions.VERSIONS:
# Use prebuilt mpy-cross on Travis, otherwise build our own.
if "TRAVIS" in os.environ:
mpy_cross = pkg_resources.resource_filename(
target_versions.__name__, "data/mpy-cross-" + version["name"])
else:
mpy_cross = "build_deps/mpy-cross-" + version["name"] + (".exe" * (os.name == "nt"))
build.mpy_cross(mpy_cross, version["tag"])
if "py" not in skip_bundles:
zip_filename = os.path.join(output_directory,
filename_prefix + '-{TAG}-mpy-{VERSION}.zip'.format(
TAG=version["name"],
filename_prefix + '-py-{VERSION}.zip'.format(
VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
mpy_cross=mpy_cross, build_tools_version=build_tools_version, remote_name=remote_name)
build_tools_version=build_tools_version, remote_name=remote_name)

# Build .mpy bundle(s)
if "mpy" not in skip_bundles:
os.makedirs("build_deps", exist_ok=True)
for version in target_versions.VERSIONS:
# Use prebuilt mpy-cross on Travis, otherwise build our own.
if "TRAVIS" in os.environ:
mpy_cross = pkg_resources.resource_filename(
target_versions.__name__, "data/mpy-cross-" + version["name"])
else:
mpy_cross = "build_deps/mpy-cross-" + version["name"] + (".exe" * (os.name == "nt"))
build.mpy_cross(mpy_cross, version["tag"])
zip_filename = os.path.join(output_directory,
filename_prefix + '-{TAG}-mpy-{VERSION}.zip'.format(
TAG=version["name"],
VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
mpy_cross=mpy_cross, build_tools_version=build_tools_version, remote_name=remote_name)

# Build example bundle
zip_filename = os.path.join(output_directory,
filename_prefix + '-examples-{VERSION}.zip'.format(
VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
build_tools_version=build_tools_version, example_bundle=True, remote_name=remote_name)
if "example" not in skip_bundles:
zip_filename = os.path.join(output_directory,
filename_prefix + '-examples-{VERSION}.zip'.format(
VERSION=bundle_version))
build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
build_tools_version=build_tools_version, example_bundle=True, remote_name=remote_name)

# Build Bundle JSON
json_filename = os.path.join(output_directory,
filename_prefix + '-{VERSION}.json'.format(
VERSION=bundle_version))
build_bundle_json(libs, bundle_version, json_filename, package_folder_prefix, remote_name=remote_name)
if "json" not in skip_bundles:
json_filename = os.path.join(output_directory,
filename_prefix + '-{VERSION}.json'.format(
VERSION=bundle_version))
build_bundle_json(libs, bundle_version, json_filename, package_folder_prefix, remote_name=remote_name)