Skip to content

Commit 0a2ac58

Browse files
authored
Merge pull request #93 from Neradoc/dont-normalize-names
Fix listing dependencies in json
2 parents 687af8c + ad4908a commit 0a2ac58

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

circuitpython_build_tools/scripts/build_bundles.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,22 @@
4040
import pkg_resources
4141

4242
BLINKA_LIBRARIES = [
43-
"adafruit_blinka",
44-
"adafruit_blinka_bleio",
45-
"adafruit_blinka_displayio",
46-
"adafruit_blinka_pyportal",
47-
"adafruit_python_extended_bus",
43+
"adafruit-blinka",
44+
"adafruit-blinka-bleio",
45+
"adafruit-blinka-displayio",
46+
"adafruit-blinka-pyportal",
47+
"adafruit-python-extended-bus",
4848
"numpy",
4949
"pillow",
5050
"pyasn1",
5151
"pyserial",
5252
"scipy",
53+
"spidev",
5354
]
5455

5556
def normalize_dist_name(name: str) -> str:
56-
return name.lower().replace("-", "_")
57+
"""Return a normalized pip name"""
58+
return name.lower().replace("_", "-")
5759

5860
def add_file(bundle, src_file, zip_name):
5961
bundle.write(src_file, zip_name)
@@ -70,7 +72,7 @@ def get_module_name(library_path):
7072
repo = repo.stdout.decode("utf-8", errors="ignore").strip().lower()
7173
if repo[-4:] == ".git":
7274
repo = repo[:-4]
73-
module_name = repo.split("/")[-1].replace("_", "-")
75+
module_name = normalize_dist_name(repo.split("/")[-1])
7476

7577
# circuitpython org repos are deployed to pypi without "org" in the pypi name
7678
module_name = re.sub(r"^circuitpython-org-", "circuitpython-", module_name)
@@ -83,8 +85,8 @@ def get_bundle_requirements(directory, package_list):
8385
Return the list
8486
"""
8587

86-
pypi_reqs = [] # For multiple bundle dependency
87-
dependencies = [] # For intra-bundle dependency
88+
pypi_reqs = set() # For multiple bundle dependency
89+
dependencies = set() # For intra-bundle dependency
8890

8991
path = directory + "/requirements.txt"
9092
if os.path.exists(path):
@@ -97,15 +99,16 @@ def get_bundle_requirements(directory, package_list):
9799
# skip comments
98100
pass
99101
else:
100-
if any(operators in line for operators in [">", "<", "="]):
101-
# Remove everything after any pip style version specifiers
102-
line = re.split("[<|>|=|]", line)[0]
103-
line = normalize_dist_name(line)
104-
if line not in dependencies and line in package_list:
105-
dependencies.append(package_list[line]["module_name"])
106-
elif line not in pypi_reqs and line not in BLINKA_LIBRARIES:
107-
pypi_reqs.append(line)
108-
return dependencies, pypi_reqs
102+
# Remove any pip version and platform specifiers
103+
original_name = re.split("[<>=~[;]", line)[0].strip()
104+
# Normalize to match the indexes in package_list
105+
line = normalize_dist_name(original_name)
106+
if line in package_list:
107+
dependencies.add(package_list[line]["module_name"])
108+
elif line not in BLINKA_LIBRARIES:
109+
# add with the exact spelling from requirements.txt
110+
pypi_reqs.add(original_name)
111+
return sorted(dependencies), sorted(pypi_reqs)
109112

110113
def build_bundle_json(libs, bundle_version, output_filename, package_folder_prefix):
111114
"""
@@ -137,7 +140,7 @@ def build_bundle_json(libs, bundle_version, output_filename, package_folder_pref
137140
library["dependencies"], library["external_dependencies"] = get_bundle_requirements(packages[id]["library_path"], packages)
138141
library_submodules[packages[id]["module_name"]] = library
139142
out_file = open(output_filename, "w")
140-
json.dump(library_submodules, out_file)
143+
json.dump(library_submodules, out_file, sort_keys=True)
141144
out_file.close()
142145

143146
def build_bundle(libs, bundle_version, output_filename, package_folder_prefix,

0 commit comments

Comments
 (0)