From d1d1709f7f7388b2014c37bc4da902218c3a0214 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 8 Apr 2024 18:14:10 -0500 Subject: [PATCH] example subdirectories --- circuitpython_build_tools/build.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/circuitpython_build_tools/build.py b/circuitpython_build_tools/build.py index 1728247..dc35ade 100644 --- a/circuitpython_build_tools/build.py +++ b/circuitpython_build_tools/build.py @@ -276,12 +276,6 @@ def library(library_path, output_directory, package_folder_prefix, example_files = package_info["example_files"] module_name = package_info["module_name"] - for fn in example_files: - base_dir = os.path.join(output_directory.replace("/lib", "/"), - fn.relative_to(library_path).parent) - if not os.path.isdir(base_dir): - os.makedirs(base_dir) - for fn in py_package_files: base_dir = os.path.join(output_directory, fn.relative_to(library_path).parent) @@ -338,6 +332,12 @@ def library(library_path, output_directory, package_folder_prefix, for filename in example_files: full_path = os.path.join(library_path, filename) + + relative_filename_parts = list(filename.relative_to(library_path).parts) + relative_filename_parts.insert(1, library_path.split(os.path.sep)[-1]) + final_relative_filename = os.path.join(*relative_filename_parts) output_file = os.path.join(output_directory.replace("/lib", "/"), - filename.relative_to(library_path)) + final_relative_filename) + + os.makedirs(os.path.join(*output_file.split(os.path.sep)[:-1]), exist_ok=True) shutil.copyfile(full_path, output_file)