Skip to content

Commit 7b0b16d

Browse files
authored
Merge pull request #66 from makermelissa/master
Bundle JSON improvements
2 parents 248bc56 + 336d6b9 commit 7b0b16d

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

circuitpython_build_tools/scripts/build_bundles.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939

4040
import pkg_resources
4141

42-
NOT_BUNDLE_LIBRARIES = [
42+
BLINKA_LIBRARIES = [
4343
"adafruit-blinka",
4444
"adafruit-blinka-bleio",
4545
"adafruit-blinka-displayio",
46+
"adafruit-blinka-pyportal",
47+
"adafruit-python-extended-bus",
4648
"pyserial",
4749
]
4850

@@ -56,20 +58,22 @@ def add_file(bundle, src_file, zip_name):
5658
return file_sector_size
5759

5860
def get_module_name(library_path):
59-
"""Figure out the module or package name anbd return it"""
60-
url = subprocess.run('git remote get-url origin', shell=True, stdout=subprocess.PIPE, cwd=library_path)
61-
url = url.stdout.decode("utf-8", errors="ignore").strip().lower()
62-
module_name = url[:-4].split("/")[-1].replace("_", "-")
63-
return module_name
61+
"""Figure out the module or package name and return it"""
62+
repo = subprocess.run('git remote get-url origin', shell=True, stdout=subprocess.PIPE, cwd=library_path)
63+
repo = repo.stdout.decode("utf-8", errors="ignore").strip().lower()
64+
module_name = repo[:-4].split("/")[-1].replace("_", "-")
65+
return module_name, repo
6466

65-
def get_bundle_requirements(directory):
67+
def get_bundle_requirements(directory, package_list):
6668
"""
6769
Open the requirements.txt if it exists
6870
Remove anything that shouldn't be a requirement like Adafruit_Blinka
6971
Return the list
7072
"""
7173

72-
libraries = []
74+
pypi_reqs = [] # For multiple bundle dependency
75+
dependencies = [] # For intra-bundle dependency
76+
7377
path = directory + "/requirements.txt"
7478
if os.path.exists(path):
7579
with open(path, "r") as file:
@@ -84,25 +88,41 @@ def get_bundle_requirements(directory):
8488
if any(operators in line for operators in [">", "<", "="]):
8589
# Remove everything after any pip style version specifiers
8690
line = re.split("[<|>|=|]", line)[0]
87-
if line not in libraries and line not in NOT_BUNDLE_LIBRARIES:
88-
libraries.append(line)
89-
return libraries
91+
if line not in dependencies and line in package_list:
92+
dependencies.append(package_list[line]["module_name"])
93+
elif line not in pypi_reqs and line not in BLINKA_LIBRARIES:
94+
pypi_reqs.append(line)
95+
return dependencies, pypi_reqs
9096

9197
def build_bundle_json(libs, bundle_version, output_filename, package_folder_prefix):
9298
"""
9399
Generate a JSON file of all the libraries in libs
94100
"""
95-
library_submodules = {}
101+
packages = {}
96102
for library_path in libs:
97-
library = {}
103+
package = {}
98104
package_info = build.get_package_info(library_path, package_folder_prefix)
99-
module_name = get_module_name(library_path)
105+
module_name, repo = get_module_name(library_path)
100106
if package_info["module_name"] is not None:
101-
library["package"] = package_info["is_package"]
102-
library["version"] = package_info["version"]
103-
library["path"] = "lib/" + package_info["module_name"]
104-
library["dependencies"] = get_bundle_requirements(library_path)
105-
library_submodules[module_name] = library
107+
package["module_name"] = package_info["module_name"]
108+
package["pypi_name"] = module_name
109+
package["repo"] = repo
110+
package["is_folder"] = package_info["is_package"]
111+
package["version"] = package_info["version"]
112+
package["path"] = "lib/" + package_info["module_name"]
113+
package["library_path"] = library_path
114+
packages[module_name] = package
115+
116+
library_submodules = {}
117+
for id in packages:
118+
library = {}
119+
library["package"] = packages[id]["is_folder"]
120+
library["pypi_name"] = packages[id]["pypi_name"]
121+
library["version"] = packages[id]["version"]
122+
library["repo"] = packages[id]["repo"]
123+
library["path"] = packages[id]["path"]
124+
library["dependencies"], library["external_dependencies"] = get_bundle_requirements(packages[id]["library_path"], packages)
125+
library_submodules[packages[id]["module_name"]] = library
106126
out_file = open(output_filename, "w")
107127
json.dump(library_submodules, out_file)
108128
out_file.close()

0 commit comments

Comments
 (0)