Skip to content

Commit 59ed295

Browse files
committed
Merge branch 'refs/heads/main' into fix_dupe_lib_dir
# Conflicts: # create_requirement_images.py
2 parents a2b36ed + 3003e14 commit 59ed295

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

Diff for: create_requirement_images.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
with open("latest_bundle_data.json", "r", encoding="utf-8") as f:
4242
bundle_data = json.load(f)
4343

44+
with open("latest_community_bundle_data.json", "r", encoding="utf-8") as f:
45+
community_bundle_data = json.load(f)
46+
4447

4548
def asset_path(asset_name):
4649
"""Return the location of a file shipped with the screenshot maker"""
@@ -163,7 +166,7 @@ def make_line(
163166
)
164167

165168
def make_header(position, project_files, files_and_libs):
166-
# pylint: disable=too-many-locals
169+
# pylint: disable=too-many-locals, too-many-branches
167170
# Static files
168171
make_line(
169172
"CIRCUITPY",
@@ -198,8 +201,7 @@ def make_header(position, project_files, files_and_libs):
198201
icon=file_icon,
199202
)
200203

201-
# TODO: Add settings.toml if it's needed
202-
204+
# Add settings.toml if it's needed
203205
if settings_required(files_and_libs):
204206
make_line(
205207
"settings.toml",
@@ -247,6 +249,10 @@ def make_header(position, project_files, files_and_libs):
247249

248250
extra_rows = 0
249251
for i, file in enumerate(sorted(project_folders_to_draw.keys())):
252+
if len(project_folders_to_draw[file]) > 0:
253+
triangle_to_use = down_triangle
254+
else:
255+
triangle_to_use = right_triangle
250256
make_line(
251257
file,
252258
(
@@ -257,7 +263,7 @@ def make_header(position, project_files, files_and_libs):
257263
* (begin_y_offset + i + len(project_files_to_draw) + extra_rows)
258264
),
259265
),
260-
triangle_icon=down_triangle,
266+
triangle_icon=triangle_to_use,
261267
)
262268
rows_added += 1
263269
for sub_file in sorted(project_folders_to_draw[file]):
@@ -318,9 +324,12 @@ def get_dependencies(libraries):
318324

319325
if lib_name in bundle_data:
320326
lib_obj = bundle_data[lib_name]
327+
bundle_used = bundle_data
328+
elif lib_name in community_bundle_data:
329+
lib_obj = community_bundle_data[lib_name]
330+
bundle_used = community_bundle_data
321331
else:
322-
# Library isn't in bundle, so we don't know about its
323-
# dependencies.
332+
# handle lib that is not in any known bundle
324333
if "." in lib_name:
325334
file_list.add(lib_name)
326335
else:
@@ -329,7 +338,7 @@ def get_dependencies(libraries):
329338

330339
for dep_name in lib_obj["dependencies"]:
331340
libraries_to_check.append(dep_name)
332-
dep_obj = bundle_data[dep_name]
341+
dep_obj = bundle_used[dep_name]
333342
if dep_obj["package"]:
334343
package_list.add(dep_name)
335344
else:

Diff for: get_imports.py

+46-31
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
import requests
1414

1515

16-
BUNDLE_DATA = "latest_bundle_data.json"
17-
BUNDLE_TAG = "latest_bundle_tag.json"
16+
ADAFRUIT_BUNDLE_DATA = "latest_bundle_data.json"
17+
ADAFRUIT_BUNDLE_TAG = "latest_bundle_tag.json"
18+
19+
COMMUNITY_BUNDLE_DATA = "latest_community_bundle_data.json"
20+
COMMUNITY_BUNDLE_TAG = "latest_community_bundle_tag.json"
21+
22+
ADAFRUIT_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long
23+
COMMUNITY_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/community/circuitpython-community-bundle-{tag}.json" # pylint: disable=line-too-long
24+
25+
SUBDIRECTORY_FILECOUNT_LIMIT = 10
1826

1927
LEARN_GUIDE_REPO = os.environ.get(
2028
"LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/"
@@ -36,18 +44,14 @@
3644
SHOWN_FILETYPES_EXAMPLE = [s for s in SHOWN_FILETYPES if s != "py"]
3745

3846

39-
def get_bundle(tag):
40-
"""Download the given bundle's data to BUNDLE_DATA"""
41-
url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long
42-
print(f"get bundle metadata from {url}")
43-
r = requests.get(url)
44-
with open(BUNDLE_DATA, "wb") as bundle_file:
47+
def get_bundle(bundle_url, bundle_data_file):
48+
"""Download the Adafruit and Community bundles data"""
49+
print(f"get bundle metadata from {bundle_url}")
50+
r = requests.get(bundle_url)
51+
with open(bundle_data_file, "wb") as bundle_file:
4552
bundle_file.write(r.content)
4653

4754

48-
LATEST_BUNDLE_VERSION = ""
49-
50-
5155
def get_latest_release_from_url(url):
5256
"""
5357
Find the tag name of the latest release by using HTTP HEAD and decoding the redirect.
@@ -65,44 +69,40 @@ def get_latest_release_from_url(url):
6569
return tag
6670

6771

68-
def get_latest_tag():
72+
def get_latest_tag(repo_url):
6973
"""
7074
Find the value of the latest tag for the Adafruit CircuitPython library
7175
bundle.
7276
:return: The most recent tag value for the project.
7377
"""
74-
global LATEST_BUNDLE_VERSION # pylint: disable=global-statement
75-
if LATEST_BUNDLE_VERSION == "":
76-
LATEST_BUNDLE_VERSION = get_latest_release_from_url(
77-
"https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest"
78-
)
79-
return LATEST_BUNDLE_VERSION
78+
79+
return get_latest_release_from_url(repo_url)
8080

8181

82-
def ensure_latest_bundle():
82+
def ensure_latest_bundle(bundle_url, bundle_s3_url, bundle_tag_file, bundle_data_file):
8383
"""
8484
Ensure that there's a copy of the latest library bundle available so circup
8585
can check the metadata contained therein.
8686
"""
8787
print("Checking for library updates.")
88-
tag = get_latest_tag()
88+
tag = get_latest_tag(bundle_url)
8989
old_tag = "0"
90-
if os.path.isfile(BUNDLE_TAG):
91-
with open(BUNDLE_TAG, encoding="utf-8") as data:
90+
if os.path.isfile(bundle_tag_file):
91+
with open(bundle_tag_file, encoding="utf-8") as data:
9292
try:
9393
old_tag = json.load(data)["tag"]
9494
except json.decoder.JSONDecodeError as _:
9595
# Sometimes (why?) the JSON file becomes corrupt. In which case
9696
# log it and carry on as if setting up for first time.
97-
print(f"Could not parse {BUNDLE_TAG:r}")
97+
print(f"Could not parse {bundle_tag_file:r}")
9898
if tag > old_tag:
9999
print(f"New version available {tag}.")
100100
try:
101-
get_bundle(tag)
102-
with open(BUNDLE_TAG, "w", encoding="utf-8") as data:
101+
get_bundle(bundle_s3_url.replace("{tag}", tag), bundle_data_file)
102+
with open(bundle_tag_file, "w", encoding="utf-8") as data:
103103
json.dump({"tag": tag}, data)
104104
except requests.exceptions.HTTPError as _:
105-
# See #20 for reason this this
105+
# See #20 for reason this
106106
print(
107107
(
108108
"There was a problem downloading the bundle. "
@@ -114,11 +114,25 @@ def ensure_latest_bundle():
114114
print(f"Current library bundle up to date {tag}")
115115

116116

117-
ensure_latest_bundle()
117+
ensure_latest_bundle(
118+
"https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest",
119+
ADAFRUIT_BUNDLE_S3_URL,
120+
ADAFRUIT_BUNDLE_TAG,
121+
ADAFRUIT_BUNDLE_DATA,
122+
)
123+
ensure_latest_bundle(
124+
"https://github.com/adafruit/CircuitPython_Community_Bundle/releases/latest",
125+
COMMUNITY_BUNDLE_S3_URL,
126+
COMMUNITY_BUNDLE_TAG,
127+
COMMUNITY_BUNDLE_DATA,
128+
)
118129

119-
with open("latest_bundle_data.json", "r", encoding="utf-8") as f:
130+
with open(ADAFRUIT_BUNDLE_DATA, "r", encoding="utf-8") as f:
120131
bundle_data = json.load(f)
121132

133+
with open(COMMUNITY_BUNDLE_DATA, "r", encoding="utf-8") as f:
134+
community_bundle_data = json.load(f)
135+
122136

123137
def get_files_for_project(project_name):
124138
"""Get the set of files for a learn project"""
@@ -141,8 +155,9 @@ def get_files_for_project(project_name):
141155
if cur_tuple[0].split("/")[-1] == _dir:
142156
for _sub_dir in cur_tuple[1]:
143157
dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_dir,))
144-
for _sub_file in cur_tuple[2]:
145-
dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,))
158+
if len(cur_tuple[2]) < SUBDIRECTORY_FILECOUNT_LIMIT:
159+
for _sub_file in cur_tuple[2]:
160+
dir_tuple = (dir_tuple[0], dir_tuple[1] + (_sub_file,))
146161

147162
# e.g. ("dir_name", ("file_1.txt", "file_2.txt"))
148163
found_files.add(dir_tuple)
@@ -161,7 +176,7 @@ def get_libs_for_project(project_name):
161176

162177
for cur_import in found_imports:
163178
cur_lib = cur_import.name.split(".")[0]
164-
if cur_lib in bundle_data:
179+
if cur_lib in bundle_data or cur_lib in community_bundle_data:
165180
found_libs.add(cur_lib)
166181

167182
return found_libs

0 commit comments

Comments
 (0)