Skip to content

Commit 027b248

Browse files
committed
include community bundle libraries
1 parent 8f2e717 commit 027b248

File tree

2 files changed

+55
-31
lines changed

2 files changed

+55
-31
lines changed

create_requirement_images.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
bundle_data = json.load(f)
4343
f.close()
4444

45+
f = open("latest_community_bundle_data.json", "r")
46+
community_bundle_data = json.load(f)
47+
f.close()
48+
4549

4650
def asset_path(asset_name):
4751
"""Return the location of a file shipped with the screenshot maker"""
@@ -317,10 +321,23 @@ def get_dependencies(libraries):
317321
lib_name = libraries_to_check[0]
318322
del libraries_to_check[0]
319323

320-
lib_obj = bundle_data[lib_name]
324+
if lib_name in bundle_data:
325+
lib_obj = bundle_data[lib_name]
326+
bundle_used = bundle_data
327+
elif lib_name in community_bundle_data:
328+
lib_obj = community_bundle_data[lib_name]
329+
bundle_used = community_bundle_data
330+
else:
331+
# handle lib that is not in any known bundle
332+
if "." in lib_name:
333+
file_list.add(lib_name)
334+
else:
335+
package_list.add(lib_name)
336+
continue
337+
321338
for dep_name in lib_obj["dependencies"]:
322339
libraries_to_check.append(dep_name)
323-
dep_obj = bundle_data[dep_name]
340+
dep_obj = bundle_used[dep_name]
324341
if dep_obj["package"]:
325342
package_list.add(dep_name)
326343
else:

get_imports.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
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"
23+
COMMUNITY_BUNDLE_S3_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bundles/community/circuitpython-community-bundle-{tag}.json"
1824

1925
LEARN_GUIDE_REPO = os.environ.get(
2026
"LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/"
@@ -36,18 +42,15 @@
3642
SHOWN_FILETYPES_EXAMPLE = [s for s in SHOWN_FILETYPES if s != "py"]
3743

3844

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:
45+
def get_bundle(bundle_url, bundle_data_file):
46+
"""Download the Adafruit and Community bundles data"""
47+
#url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long
48+
print(f"get bundle metadata from {bundle_url}")
49+
r = requests.get(bundle_url)
50+
with open(bundle_data_file, "wb") as bundle_file:
4551
bundle_file.write(r.content)
4652

4753

48-
LATEST_BUNDLE_VERSION = ""
49-
50-
5154
def get_latest_release_from_url(url):
5255
"""
5356
Find the tag name of the latest release by using HTTP HEAD and decoding the redirect.
@@ -65,44 +68,40 @@ def get_latest_release_from_url(url):
6568
return tag
6669

6770

68-
def get_latest_tag():
71+
def get_latest_tag(repo_url):
6972
"""
7073
Find the value of the latest tag for the Adafruit CircuitPython library
7174
bundle.
7275
:return: The most recent tag value for the project.
7376
"""
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
77+
78+
return get_latest_release_from_url(repo_url)
8079

8180

82-
def ensure_latest_bundle():
81+
def ensure_latest_bundle(bundle_url, bundle_s3_url, bundle_tag_file, bundle_data_file):
8382
"""
8483
Ensure that there's a copy of the latest library bundle available so circup
8584
can check the metadata contained therein.
8685
"""
8786
print("Checking for library updates.")
88-
tag = get_latest_tag()
87+
tag = get_latest_tag(bundle_url)
8988
old_tag = "0"
90-
if os.path.isfile(BUNDLE_TAG):
91-
with open(BUNDLE_TAG, encoding="utf-8") as data:
89+
if os.path.isfile(bundle_tag_file):
90+
with open(bundle_tag_file, encoding="utf-8") as data:
9291
try:
9392
old_tag = json.load(data)["tag"]
9493
except json.decoder.JSONDecodeError as _:
9594
# Sometimes (why?) the JSON file becomes corrupt. In which case
9695
# log it and carry on as if setting up for first time.
97-
print(f"Could not parse {BUNDLE_TAG:r}")
96+
print(f"Could not parse {bundle_tag_file:r}")
9897
if tag > old_tag:
9998
print(f"New version available {tag}.")
10099
try:
101-
get_bundle(tag)
102-
with open(BUNDLE_TAG, "w", encoding="utf-8") as data:
100+
get_bundle(bundle_s3_url.replace("{tag}", tag), bundle_data_file)
101+
with open(bundle_tag_file, "w", encoding="utf-8") as data:
103102
json.dump({"tag": tag}, data)
104103
except requests.exceptions.HTTPError as _:
105-
# See #20 for reason this this
104+
# See #20 for reason this
106105
print(
107106
(
108107
"There was a problem downloading the bundle. "
@@ -114,11 +113,19 @@ def ensure_latest_bundle():
114113
print(f"Current library bundle up to date {tag}")
115114

116115

117-
ensure_latest_bundle()
116+
ensure_latest_bundle("https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest",
117+
ADAFRUIT_BUNDLE_S3_URL,
118+
ADAFRUIT_BUNDLE_TAG, ADAFRUIT_BUNDLE_DATA)
119+
ensure_latest_bundle("https://github.com/adafruit/CircuitPython_Community_Bundle/releases/latest",
120+
COMMUNITY_BUNDLE_S3_URL,
121+
COMMUNITY_BUNDLE_TAG, COMMUNITY_BUNDLE_DATA)
118122

119-
with open("latest_bundle_data.json", "r") as f:
123+
with open(ADAFRUIT_BUNDLE_DATA, "r") as f:
120124
bundle_data = json.load(f)
121125

126+
with open(COMMUNITY_BUNDLE_DATA, "r") as f:
127+
community_bundle_data = json.load(f)
128+
122129

123130
def get_files_for_project(project_name):
124131
"""Get the set of files for a learn project"""
@@ -161,7 +168,7 @@ def get_libs_for_project(project_name):
161168

162169
for cur_import in found_imports:
163170
cur_lib = cur_import.name.split(".")[0]
164-
if cur_lib in bundle_data:
171+
if cur_lib in bundle_data or cur_lib in community_bundle_data:
165172
found_libs.add(cur_lib)
166173

167174
return found_libs

0 commit comments

Comments
 (0)