From 50ddabd2cc3fddd8c8e9a661fbc758392594e4d8 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 11 May 2019 09:32:21 -0500 Subject: [PATCH] change 'package_folder_prefix' to a pos arg; grab examples subfolders --- circuitpython_build_tools/build.py | 16 +++++++++------- .../scripts/build_bundles.py | 17 +++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/circuitpython_build_tools/build.py b/circuitpython_build_tools/build.py index 6bedd9e..862a5bb 100644 --- a/circuitpython_build_tools/build.py +++ b/circuitpython_build_tools/build.py @@ -100,7 +100,7 @@ def _munge_to_temp(original_path, temp_file, library_version): temp_file.write(line.encode("utf-8") + b"\r\n") temp_file.flush() -def library(library_path, output_directory, mpy_cross=None, example_bundle=False, pkg_folder_prefix=None): +def library(library_path, output_directory, pkg_folder_prefix, mpy_cross=None, example_bundle=False): py_files = [] package_files = [] example_files = [] @@ -115,7 +115,10 @@ def library(library_path, output_directory, mpy_cross=None, example_bundle=False # 'walked_files' while retaining subdirectory structure walked_files = [] for path in path_walk: - path_tail_idx = path[0].rfind("/") + 1 + if filename.startswith("examples"): + path_tail_idx = path[0].rfind("examples/") + 9 + else: + path_tail_idx = path[0].rfind("/") + 1 path_tail = path[0][path_tail_idx:] rel_path = "" # if this entry is the package top dir, keep it @@ -134,11 +137,10 @@ def library(library_path, output_directory, mpy_cross=None, example_bundle=False example_files.extend(files) #print("- example files: {}".format(example_files)) else: - if pkg_folder_prefix: - if (not example_bundle and - not filename.startswith(pkg_folder_prefix)): - #print("skipped path: {}".format(full_path)) - continue + if (not example_bundle and + not filename.startswith(pkg_folder_prefix)): + #print("skipped path: {}".format(full_path)) + continue if not example_bundle: package_files.extend(files) #print("- package files: {} | {}".format(filename, package_files)) diff --git a/circuitpython_build_tools/scripts/build_bundles.py b/circuitpython_build_tools/scripts/build_bundles.py index 0ae233d..65bfd7a 100755 --- a/circuitpython_build_tools/scripts/build_bundles.py +++ b/circuitpython_build_tools/scripts/build_bundles.py @@ -48,9 +48,8 @@ def add_file(bundle, src_file, zip_name): return file_sector_size -def build_bundle(libs, bundle_version, output_filename, - build_tools_version="devel", mpy_cross=None, example_bundle=False, - pkg_folder_prefix=None): +def build_bundle(libs, bundle_version, output_filename, pkg_folder_prefix, + build_tools_version="devel", mpy_cross=None, example_bundle=False): build_dir = "build-" + os.path.basename(output_filename) top_folder = os.path.basename(output_filename).replace(".zip", "") build_lib_dir = os.path.join(build_dir, top_folder, "lib") @@ -70,7 +69,7 @@ def build_bundle(libs, bundle_version, output_filename, success = True for library_path in libs: try: - build.library(library_path, build_lib_dir, pkg_folder_prefix=pkg_folder_prefix, + build.library(library_path, build_lib_dir, pkg_folder_prefix, mpy_cross=mpy_cross, example_bundle=example_bundle) except ValueError as e: print("build.library failure:", library_path) @@ -159,8 +158,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d zip_filename = os.path.join(output_directory, filename_prefix + '-py-{VERSION}.zip'.format( VERSION=bundle_version)) - build_bundle(libs, bundle_version, zip_filename, - pkg_folder_prefix=package_folder_prefix, + build_bundle(libs, bundle_version, zip_filename, package_folder_prefix, build_tools_version=build_tools_version) # Build .mpy bundle(s) @@ -177,13 +175,12 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d filename_prefix + '-{TAG}-mpy-{VERSION}.zip'.format( TAG=version["name"], VERSION=bundle_version)) - build_bundle(libs, bundle_version, zip_filename, mpy_cross=mpy_cross, - build_tools_version=build_tools_version, - pkg_folder_prefix=package_folder_prefix) + build_bundle(libs, bundle_version, zip_filename, package_folder_prefix, + mpy_cross=mpy_cross, build_tools_version=build_tools_version) # 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, + build_bundle(libs, bundle_version, zip_filename, package_folder_prefix, build_tools_version=build_tools_version, example_bundle=True)