Skip to content
Merged
Show file tree
Hide file tree
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
56 changes: 30 additions & 26 deletions adabot/circuitpython_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,26 @@ 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"
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(
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
try:
with open(
os.path.join(bundle_path, "circuitpython_library_list.md"), "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 = []
Expand Down Expand Up @@ -197,9 +202,7 @@ def check_lib_links_md(bundle_path):
"## Drivers:\n",
]

with open(
os.path.join(bundle_path, "circuitpython_library_list.md"), "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")
Expand Down Expand Up @@ -264,6 +267,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")
Expand Down Expand Up @@ -307,12 +320,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(
Expand All @@ -321,18 +337,6 @@ def update_bundle(bundle_path):
)
)
release_required = True
if update_download_stats(bundle_path):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also removed this code that updates the pypi stats. We're no longer using the stats in the file used for meeting notes so this does not need to update any longer.

Copy link
Member

@tekktrik tekktrik Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't use this, we can probably remove the Google BigQuery task that occurs in retrieve_pypi_stats() that feeds into update_download_stats(). I don't think we're billed over it, but probably worth doing if we're not using the download stats :) It's attached to my account I believe so I can do that. Then we can clean up some of the Actions secrets and decouple adabot from BigQuery entirely.

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

Expand Down
22 changes: 17 additions & 5 deletions adabot/lib/common_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
Loading