From 82cc5d3ee1cdfcca2f74613cabccdfb9f9bb8903 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 2 Jan 2025 11:05:14 -0600 Subject: [PATCH 1/4] add support for generate community bundle list md file --- adabot/circuitpython_bundle.py | 13 +++++++++---- adabot/lib/common_funcs.py | 22 +++++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/adabot/circuitpython_bundle.py b/adabot/circuitpython_bundle.py index e94d88a..b5a28b9 100644 --- a/adabot/circuitpython_bundle.py +++ b/adabot/circuitpython_bundle.py @@ -140,14 +140,19 @@ def update_download_stats(bundle_path): # pylint: disable=too-many-locals def check_lib_links_md(bundle_path): """Checks and updates the `circuitpython_library_list` Markdown document - located in the Adafruit CircuitPython Bundle. + located in the Adafruit CircuitPython Bundle and Community Bundle. """ - if not "Adafruit_CircuitPython_Bundle" in bundle_path: + bundle = None + if "Adafruit_CircuitPython_Bundle" in bundle_path: + bundle = "adafruit" + elif "CircuitPython_Community_Bundle" in bundle_path: + bundle = "community" + else: return [] submodules_list = sorted( - common_funcs.get_bundle_submodules(), key=lambda module: module[1]["path"] + common_funcs.get_bundle_submodules(bundle=bundle), + key=lambda module: module[1]["path"], ) - submodules_list = common_funcs.get_bundle_submodules() lib_count = len(submodules_list) # used to generate commit message by comparing new libs to current list diff --git a/adabot/lib/common_funcs.py b/adabot/lib/common_funcs.py index 65b9b09..864ccf7 100644 --- a/adabot/lib/common_funcs.py +++ b/adabot/lib/common_funcs.py @@ -84,20 +84,32 @@ def parse_gitmodules(input_text): return results -def get_bundle_submodules(): +def get_bundle_submodules(bundle="adafruit"): """Query Adafruit_CircuitPython_Bundle repository for all the submodules (i.e. modules included inside) and return a list of the found submodules. Each list item is a 2-tuple of submodule name and a dict of submodule variables including 'path' (location of submodule in bundle) and 'url' (URL to git repository with submodule contents). + + :param string bundle: Which bundle to get submodules for, 'adafruit' or 'community'. """ # Assume the bundle repository is public and get the .gitmodules file # without any authentication or Github API usage. Also assumes the # master branch of the bundle is the canonical source of the bundle release. - result = requests.get( - "https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/.gitmodules", - timeout=REQUESTS_TIMEOUT, - ) + if bundle == "adafruit": + result = requests.get( + "https://raw.githubusercontent.com/adafruit/" + "Adafruit_CircuitPython_Bundle/main/.gitmodules", + timeout=REQUESTS_TIMEOUT, + ) + elif bundle == "community": + result = requests.get( + "https://raw.githubusercontent.com/adafruit/" + "CircuitPython_Community_Bundle/main/.gitmodules", + timeout=REQUESTS_TIMEOUT, + ) + else: + raise ValueError("Bundle must be either 'adafruit' or 'community'") if result.status_code != 200: # output_handler("Failed to access bundle .gitmodules file from GitHub!", quiet=True) raise RuntimeError("Failed to access bundle .gitmodules file from GitHub!") From 337353dd5d679876e04bf81a42373912938ff7c0 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 2 Jan 2025 11:31:12 -0600 Subject: [PATCH 2/4] enforce bundle to adafruit & community. include which bundle in updates. remove unused pypi stats fetch. --- adabot/circuitpython_bundle.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/adabot/circuitpython_bundle.py b/adabot/circuitpython_bundle.py index b5a28b9..17f32c5 100644 --- a/adabot/circuitpython_bundle.py +++ b/adabot/circuitpython_bundle.py @@ -269,6 +269,16 @@ def repo_remote_url(repo_path): def update_bundle(bundle_path): """Process all libraries in the bundle, and update their version if necessary.""" + + if ( + "Adafruit_CircuitPython_Bundle" not in bundle_path + and "CircuitPython_Community_Bundle" not in bundle_path + ): + raise ValueError( + "bundle_path must be for " + "Adafruit_CircuitPython_Bundle or CircuitPython_Community_Bundle" + ) + working_directory = os.path.abspath(os.getcwd()) os.chdir(bundle_path) git.submodule("foreach", "git", "fetch") @@ -312,12 +322,15 @@ def update_bundle(bundle_path): os.chdir(working_directory) lib_list_updates = check_lib_links_md(bundle_path) if lib_list_updates: + if "Adafruit_CircuitPython_Bundle" in bundle_path: + listfile_name = "circuitpython_library_list.md" + bundle_url = "https://github.com/adafruit/Adafruit_CircuitPython_Bundle/" + elif "CircuitPython_Community_Bundle" in bundle_path: + listfile_name = "circuitpython_community_auto_library_list.md" + bundle_url = "https://github.com/adafruit/CircuitPython_Community_Bundle/" updates.append( ( - ( - "https://github.com/adafruit/Adafruit_CircuitPython_Bundle/" - "circuitpython_library_list.md" - ), + f"{bundle_url}{listfile_name}", # pylint: disable=possibly-used-before-assignment "NA", "NA", " > Added the following libraries: {}".format( @@ -326,18 +339,6 @@ def update_bundle(bundle_path): ) ) release_required = True - if update_download_stats(bundle_path): - updates.append( - ( - ( - "https://github.com/adafruit/Adafruit_CircuitPython_Bundle/" - "circuitpython_library_list.md" - ), - "NA", - "NA", - " > Updated download stats for the libraries", - ) - ) return updates, release_required From 58e624b36155749ffd059d8531370530e97c157d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 2 Jan 2025 11:58:09 -0600 Subject: [PATCH 3/4] different file names for bundles --- adabot/circuitpython_bundle.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adabot/circuitpython_bundle.py b/adabot/circuitpython_bundle.py index 17f32c5..0d6f3bd 100644 --- a/adabot/circuitpython_bundle.py +++ b/adabot/circuitpython_bundle.py @@ -145,8 +145,10 @@ def check_lib_links_md(bundle_path): bundle = None if "Adafruit_CircuitPython_Bundle" in bundle_path: bundle = "adafruit" + listfile_name = "circuitpython_library_list.md" elif "CircuitPython_Community_Bundle" in bundle_path: bundle = "community" + listfile_name = "circuitpython_community_auto_library_list.md" else: return [] submodules_list = sorted( @@ -158,7 +160,7 @@ def check_lib_links_md(bundle_path): # used to generate commit message by comparing new libs to current list try: with open( - os.path.join(bundle_path, "circuitpython_library_list.md"), "r" + os.path.join(bundle_path, listfile_name), "r" ) as lib_list: read_lines = lib_list.read().splitlines() except OSError: @@ -203,7 +205,7 @@ def check_lib_links_md(bundle_path): ] with open( - os.path.join(bundle_path, "circuitpython_library_list.md"), "w" + os.path.join(bundle_path, listfile_name), "w" ) as md_file: md_file.write("\n".join(lib_list_header)) for line in sorted(write_drivers): From cfe50bb8111dcd02a439fd7a5a7542fabea07e01 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 2 Jan 2025 12:06:51 -0600 Subject: [PATCH 4/4] format --- adabot/circuitpython_bundle.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/adabot/circuitpython_bundle.py b/adabot/circuitpython_bundle.py index 0d6f3bd..876032e 100644 --- a/adabot/circuitpython_bundle.py +++ b/adabot/circuitpython_bundle.py @@ -159,9 +159,7 @@ def check_lib_links_md(bundle_path): lib_count = len(submodules_list) # used to generate commit message by comparing new libs to current list try: - with open( - os.path.join(bundle_path, listfile_name), "r" - ) as lib_list: + with open(os.path.join(bundle_path, listfile_name), "r") as lib_list: read_lines = lib_list.read().splitlines() except OSError: read_lines = [] @@ -204,9 +202,7 @@ def check_lib_links_md(bundle_path): "## Drivers:\n", ] - with open( - os.path.join(bundle_path, listfile_name), "w" - ) as md_file: + with open(os.path.join(bundle_path, listfile_name), "w") as md_file: md_file.write("\n".join(lib_list_header)) for line in sorted(write_drivers): md_file.write(line + "\n")