diff --git a/circuitpython_build_tools/scripts/build_bundles.py b/circuitpython_build_tools/scripts/build_bundles.py index 3c9b82c..18be778 100755 --- a/circuitpython_build_tools/scripts/build_bundles.py +++ b/circuitpython_build_tools/scripts/build_bundles.py @@ -66,9 +66,9 @@ def add_file(bundle, src_file, zip_name): print(zip_name, file_size, file_sector_size) return file_sector_size -def get_module_name(library_path): +def get_module_name(library_path, remote_name): """Figure out the module or package name and return it""" - repo = subprocess.run('git remote get-url origin', shell=True, stdout=subprocess.PIPE, cwd=library_path) + repo = subprocess.run(f'git remote get-url {remote_name}', shell=True, stdout=subprocess.PIPE, cwd=library_path) repo = repo.stdout.decode("utf-8", errors="ignore").strip().lower() if repo[-4:] == ".git": repo = repo[:-4] @@ -110,7 +110,7 @@ def get_bundle_requirements(directory, package_list): pypi_reqs.add(original_name) return sorted(dependencies), sorted(pypi_reqs) -def build_bundle_json(libs, bundle_version, output_filename, package_folder_prefix): +def build_bundle_json(libs, bundle_version, output_filename, package_folder_prefix, remote_name="origin"): """ Generate a JSON file of all the libraries in libs """ @@ -118,7 +118,7 @@ def build_bundle_json(libs, bundle_version, output_filename, package_folder_pref for library_path in libs: package = {} package_info = build.get_package_info(library_path, package_folder_prefix) - module_name, repo = get_module_name(library_path) + module_name, repo = get_module_name(library_path, remote_name) if package_info["module_name"] is not None: package["module_name"] = package_info["module_name"] package["pypi_name"] = module_name @@ -144,7 +144,7 @@ def build_bundle_json(libs, bundle_version, output_filename, package_folder_pref out_file.close() def build_bundle(libs, bundle_version, output_filename, package_folder_prefix, - build_tools_version="devel", mpy_cross=None, example_bundle=False): + build_tools_version="devel", mpy_cross=None, example_bundle=False, remote_name="origin"): 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") @@ -176,7 +176,7 @@ def build_bundle(libs, bundle_version, output_filename, package_folder_prefix, if multiple_libs: with open(os.path.join(build_dir, top_folder, "VERSIONS.txt"), "w") as f: f.write(bundle_version + "\r\n") - versions = subprocess.run('git submodule --quiet foreach \"git remote get-url origin && git describe --tags\"', shell=True, stdout=subprocess.PIPE, cwd=os.path.commonpath(libs)) + versions = subprocess.run(f'git submodule --quiet foreach \"git remote get-url {remote_name} && git describe --tags\"', shell=True, stdout=subprocess.PIPE, cwd=os.path.commonpath(libs)) if versions.returncode != 0: print("Failed to generate versions file. Its likely a library hasn't been " "released yet.") @@ -233,7 +233,8 @@ def _find_libraries(current_path, depth): @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.") -def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix): +@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): os.makedirs(output_directory, exist_ok=True) package_folder_prefix = package_folder_prefix.split(", ") @@ -258,7 +259,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d 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) + build_tools_version=build_tools_version, remote_name=remote_name) # Build .mpy bundle(s) os.makedirs("build_deps", exist_ok=True) @@ -275,17 +276,17 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d 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) + 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) + 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) + build_bundle_json(libs, bundle_version, json_filename, package_folder_prefix, remote_name=remote_name)