Skip to content

Commit 0684d8c

Browse files
authored
Merge pull request #6 from tannewt/error_on_multipy
Raise an error when multiple top-level py files exist.
2 parents f4c4e16 + 477a7f7 commit 0684d8c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

circuitpython_build_tools/build.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,8 @@ def library(library_path, output_directory, mpy_cross=None):
101101
py_files.append(filename)
102102

103103
if len(py_files) > 1:
104-
output_directory = os.path.join(output_directory, library)
105-
os.makedirs(output_directory)
106-
package_init = os.path.join(output_directory, "__init__.py")
107-
# Touch the __init__ file.
108-
with open(package_init, 'a'):
109-
pass
104+
raise ValueError("Multiple top level py files not allowed. Please put them in a package "
105+
"or combine them into a single file.")
110106

111107
if len(package_files) > 1:
112108
for fn in package_files:
@@ -120,7 +116,12 @@ def library(library_path, output_directory, mpy_cross=None):
120116
if mpy_cross:
121117
new_extension = ".mpy"
122118

123-
library_version = version_string(library_path, valid_semver=True)
119+
try:
120+
library_version = version_string(library_path, valid_semver=True)
121+
except ValueError as e:
122+
print(library_path + " has version that doesn't follow SemVer (semver.org)")
123+
print(e)
124+
library_version = version_string(library_path)
124125

125126
for filename in py_files:
126127
full_path = os.path.join(library_path, filename)

circuitpython_build_tools/scripts/build_bundles.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ def build_bundle(libs, bundle_version, output_filename,
6262
success = True
6363
total_size = 512
6464
for library_path in libs:
65-
build.library(library_path, build_lib_dir, mpy_cross=mpy_cross)
65+
try:
66+
build.library(library_path, build_lib_dir, mpy_cross=mpy_cross)
67+
except ValueError as e:
68+
print(library_path)
69+
print(e)
70+
success = False
6671

72+
print()
73+
print("Generating VERSIONS")
6774
if multiple_libs:
6875
with open(os.path.join(build_lib_dir, "VERSIONS.txt"), "w") as f:
6976
f.write(bundle_version + "\r\n")
@@ -79,6 +86,9 @@ def build_bundle(libs, bundle_version, output_filename,
7986
else:
8087
f.write(repo.decode("utf-8", "strict") + "/releases/tag/" + line.strip().decode("utf-8", "strict") + "\r\n")
8188

89+
print()
90+
print("Zipping")
91+
8292
with zipfile.ZipFile(output_filename, 'w') as bundle:
8393
build_metadata = {"build-tools-version": build_tools_version}
8494
bundle.comment = json.dumps(build_metadata).encode("utf-8")

0 commit comments

Comments
 (0)