Skip to content

--remote_name argument #96

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 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
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
23 changes: 12 additions & 11 deletions circuitpython_build_tools/scripts/build_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -110,15 +110,15 @@ 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
"""
packages = {}
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
Expand All @@ -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")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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(", ")
Expand All @@ -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)
Expand All @@ -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)