Skip to content

Commit

Permalink
change 'package_folder_prefix' to a pos arg; grab examples subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
sommersoft committed May 11, 2019
1 parent 18df89a commit 50ddabd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
16 changes: 9 additions & 7 deletions circuitpython_build_tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand All @@ -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))
Expand Down
17 changes: 7 additions & 10 deletions circuitpython_build_tools/scripts/build_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit 50ddabd

Please sign in to comment.