Skip to content

Commit 006e95e

Browse files
authored
Merge pull request #392 from FoamyGuy/automate_community_bundle_list
Automate community bundle list
2 parents 53e7906 + cfe50bb commit 006e95e

File tree

2 files changed

+47
-31
lines changed

2 files changed

+47
-31
lines changed

adabot/circuitpython_bundle.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,26 @@ def update_download_stats(bundle_path):
140140
# pylint: disable=too-many-locals
141141
def check_lib_links_md(bundle_path):
142142
"""Checks and updates the `circuitpython_library_list` Markdown document
143-
located in the Adafruit CircuitPython Bundle.
143+
located in the Adafruit CircuitPython Bundle and Community Bundle.
144144
"""
145-
if not "Adafruit_CircuitPython_Bundle" in bundle_path:
145+
bundle = None
146+
if "Adafruit_CircuitPython_Bundle" in bundle_path:
147+
bundle = "adafruit"
148+
listfile_name = "circuitpython_library_list.md"
149+
elif "CircuitPython_Community_Bundle" in bundle_path:
150+
bundle = "community"
151+
listfile_name = "circuitpython_community_auto_library_list.md"
152+
else:
146153
return []
147154
submodules_list = sorted(
148-
common_funcs.get_bundle_submodules(), key=lambda module: module[1]["path"]
155+
common_funcs.get_bundle_submodules(bundle=bundle),
156+
key=lambda module: module[1]["path"],
149157
)
150-
submodules_list = common_funcs.get_bundle_submodules()
151158

152159
lib_count = len(submodules_list)
153160
# used to generate commit message by comparing new libs to current list
154161
try:
155-
with open(
156-
os.path.join(bundle_path, "circuitpython_library_list.md"), "r"
157-
) as lib_list:
162+
with open(os.path.join(bundle_path, listfile_name), "r") as lib_list:
158163
read_lines = lib_list.read().splitlines()
159164
except OSError:
160165
read_lines = []
@@ -197,9 +202,7 @@ def check_lib_links_md(bundle_path):
197202
"## Drivers:\n",
198203
]
199204

200-
with open(
201-
os.path.join(bundle_path, "circuitpython_library_list.md"), "w"
202-
) as md_file:
205+
with open(os.path.join(bundle_path, listfile_name), "w") as md_file:
203206
md_file.write("\n".join(lib_list_header))
204207
for line in sorted(write_drivers):
205208
md_file.write(line + "\n")
@@ -264,6 +267,16 @@ def repo_remote_url(repo_path):
264267

265268
def update_bundle(bundle_path):
266269
"""Process all libraries in the bundle, and update their version if necessary."""
270+
271+
if (
272+
"Adafruit_CircuitPython_Bundle" not in bundle_path
273+
and "CircuitPython_Community_Bundle" not in bundle_path
274+
):
275+
raise ValueError(
276+
"bundle_path must be for "
277+
"Adafruit_CircuitPython_Bundle or CircuitPython_Community_Bundle"
278+
)
279+
267280
working_directory = os.path.abspath(os.getcwd())
268281
os.chdir(bundle_path)
269282
git.submodule("foreach", "git", "fetch")
@@ -307,12 +320,15 @@ def update_bundle(bundle_path):
307320
os.chdir(working_directory)
308321
lib_list_updates = check_lib_links_md(bundle_path)
309322
if lib_list_updates:
323+
if "Adafruit_CircuitPython_Bundle" in bundle_path:
324+
listfile_name = "circuitpython_library_list.md"
325+
bundle_url = "https://github.com/adafruit/Adafruit_CircuitPython_Bundle/"
326+
elif "CircuitPython_Community_Bundle" in bundle_path:
327+
listfile_name = "circuitpython_community_auto_library_list.md"
328+
bundle_url = "https://github.com/adafruit/CircuitPython_Community_Bundle/"
310329
updates.append(
311330
(
312-
(
313-
"https://github.com/adafruit/Adafruit_CircuitPython_Bundle/"
314-
"circuitpython_library_list.md"
315-
),
331+
f"{bundle_url}{listfile_name}", # pylint: disable=possibly-used-before-assignment
316332
"NA",
317333
"NA",
318334
" > Added the following libraries: {}".format(
@@ -321,18 +337,6 @@ def update_bundle(bundle_path):
321337
)
322338
)
323339
release_required = True
324-
if update_download_stats(bundle_path):
325-
updates.append(
326-
(
327-
(
328-
"https://github.com/adafruit/Adafruit_CircuitPython_Bundle/"
329-
"circuitpython_library_list.md"
330-
),
331-
"NA",
332-
"NA",
333-
" > Updated download stats for the libraries",
334-
)
335-
)
336340

337341
return updates, release_required
338342

adabot/lib/common_funcs.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,32 @@ def parse_gitmodules(input_text):
8484
return results
8585

8686

87-
def get_bundle_submodules():
87+
def get_bundle_submodules(bundle="adafruit"):
8888
"""Query Adafruit_CircuitPython_Bundle repository for all the submodules
8989
(i.e. modules included inside) and return a list of the found submodules.
9090
Each list item is a 2-tuple of submodule name and a dict of submodule
9191
variables including 'path' (location of submodule in bundle) and
9292
'url' (URL to git repository with submodule contents).
93+
94+
:param string bundle: Which bundle to get submodules for, 'adafruit' or 'community'.
9395
"""
9496
# Assume the bundle repository is public and get the .gitmodules file
9597
# without any authentication or Github API usage. Also assumes the
9698
# master branch of the bundle is the canonical source of the bundle release.
97-
result = requests.get(
98-
"https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/.gitmodules",
99-
timeout=REQUESTS_TIMEOUT,
100-
)
99+
if bundle == "adafruit":
100+
result = requests.get(
101+
"https://raw.githubusercontent.com/adafruit/"
102+
"Adafruit_CircuitPython_Bundle/main/.gitmodules",
103+
timeout=REQUESTS_TIMEOUT,
104+
)
105+
elif bundle == "community":
106+
result = requests.get(
107+
"https://raw.githubusercontent.com/adafruit/"
108+
"CircuitPython_Community_Bundle/main/.gitmodules",
109+
timeout=REQUESTS_TIMEOUT,
110+
)
111+
else:
112+
raise ValueError("Bundle must be either 'adafruit' or 'community'")
101113
if result.status_code != 200:
102114
# output_handler("Failed to access bundle .gitmodules file from GitHub!", quiet=True)
103115
raise RuntimeError("Failed to access bundle .gitmodules file from GitHub!")

0 commit comments

Comments
 (0)