Skip to content

Commit 7804a09

Browse files
authored
Merge pull request #38 from adafruit/revert-31-include_init
Revert "Include mpy-cross '__init__.py' In Packages; Restructure Package Bundling"
2 parents b7c8f71 + cd1a858 commit 7804a09

File tree

2 files changed

+13
-48
lines changed

2 files changed

+13
-48
lines changed

circuitpython_build_tools/build.py

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -100,64 +100,31 @@ def _munge_to_temp(original_path, temp_file, library_version):
100100
temp_file.write(line.encode("utf-8") + b"\r\n")
101101
temp_file.flush()
102102

103-
def library(library_path, output_directory, mpy_cross=None, example_bundle=False, pkg_folder_prefix=None):
103+
def library(library_path, output_directory, mpy_cross=None, example_bundle=False):
104104
py_files = []
105105
package_files = []
106106
example_files = []
107107
total_size = 512
108108
for filename in os.listdir(library_path):
109109
full_path = os.path.join(library_path, filename)
110-
if os.path.isdir(full_path):
111-
path_walk = [names for names in os.walk(full_path)]
112-
#print("- '{}' walk: {}".format(filename, path_walk))
113-
114-
# iterate through path_walk, appending each file to
115-
# 'walked_files' while retaining subdirectory structure
116-
walked_files = []
117-
for path in path_walk:
118-
path_tail_idx = path[0].rfind("/") + 1
119-
path_tail = path[0][path_tail_idx:]
120-
rel_path = ""
121-
# if this entry is the package top dir, keep it
122-
# empty so we don't double append the dir name
123-
if filename not in path_tail:
124-
rel_path = "{}/".format(path_tail)
125-
126-
for path_files in path[2]:
127-
walked_files.append("{}{}".format(rel_path, path_files))
128-
#print(" - expanded file walk: {}".format(walked_files))
129-
130-
files = filter(lambda x: x.endswith(".py") or x.startswith("font5x8.bin"), walked_files)
110+
if os.path.isdir(full_path) and filename not in ["docs"]:
111+
files = os.listdir(full_path)
112+
files = filter(lambda x: x.endswith(".py") or x.startswith("font5x8.bin"), files)
131113
files = map(lambda x: os.path.join(filename, x), files)
132-
133114
if filename.startswith("examples"):
134115
example_files.extend(files)
135-
#print("- example files: {}".format(example_files))
136116
else:
137-
if pkg_folder_prefix:
138-
if (not example_bundle and
139-
not filename.startswith(pkg_folder_prefix)):
140-
#print("skipped path: {}".format(full_path))
141-
continue
142117
if not example_bundle:
143118
package_files.extend(files)
144-
#print("- package files: {} | {}".format(filename, package_files))
145-
146119
if (filename.endswith(".py") and
147120
filename not in IGNORE_PY and
148121
not example_bundle):
149-
py_files.append(filename)
122+
py_files.append(filename)
150123

151124
if len(py_files) > 1:
152125
raise ValueError("Multiple top level py files not allowed. Please put them in a package "
153126
"or combine them into a single file.")
154127

155-
for fn in example_files:
156-
base_dir = os.path.join(output_directory.replace("/lib", "/"), os.path.dirname(fn))
157-
if not os.path.isdir(base_dir):
158-
os.makedirs(base_dir)
159-
total_size += 512
160-
161128
for fn in package_files:
162129
base_dir = os.path.join(output_directory, os.path.dirname(fn))
163130
if not os.path.isdir(base_dir):
@@ -196,7 +163,9 @@ def library(library_path, output_directory, mpy_cross=None, example_bundle=False
196163
full_path = os.path.join(library_path, filename)
197164
with tempfile.NamedTemporaryFile() as temp_file:
198165
_munge_to_temp(full_path, temp_file, library_version)
199-
if not mpy_cross or os.stat(full_path).st_size == 0:
166+
if (not mpy_cross or
167+
os.stat(full_path).st_size == 0 or
168+
filename.endswith("__init__.py")):
200169
output_file = os.path.join(output_directory, filename)
201170
shutil.copyfile(temp_file.name, output_file)
202171
else:

circuitpython_build_tools/scripts/build_bundles.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def add_file(bundle, src_file, zip_name):
4949

5050

5151
def build_bundle(libs, bundle_version, output_filename,
52-
build_tools_version="devel", mpy_cross=None, example_bundle=False,
53-
pkg_folder_prefix=None):
52+
build_tools_version="devel", mpy_cross=None, example_bundle=False):
5453
build_dir = "build-" + os.path.basename(output_filename)
5554
top_folder = os.path.basename(output_filename).replace(".zip", "")
5655
build_lib_dir = os.path.join(build_dir, top_folder, "lib")
@@ -70,8 +69,8 @@ def build_bundle(libs, bundle_version, output_filename,
7069
success = True
7170
for library_path in libs:
7271
try:
73-
build.library(library_path, build_lib_dir, pkg_folder_prefix=pkg_folder_prefix,
74-
mpy_cross=mpy_cross, example_bundle=example_bundle)
72+
build.library(library_path, build_lib_dir, mpy_cross=mpy_cross,
73+
example_bundle=example_bundle)
7574
except ValueError as e:
7675
print("build.library failure:", library_path)
7776
print(e)
@@ -136,8 +135,7 @@ def _find_libraries(current_path, depth):
136135
@click.option('--output_directory', default="bundles", help="Output location for the zip files.")
137136
@click.option('--library_location', required=True, help="Location of libraries to bundle.")
138137
@click.option('--library_depth', default=0, help="Depth of library folders. This is useful when multiple libraries are bundled together but are initially in separate subfolders.")
139-
@click.option('--package_folder_prefix', default=None, required=False, help="Prefix string used to determine package folders to bundle.")
140-
def build_bundles(filename_prefix, output_directory, library_location, library_depth, pkg_folder_prefix):
138+
def build_bundles(filename_prefix, output_directory, library_location, library_depth):
141139
os.makedirs(output_directory, exist_ok=True)
142140

143141
bundle_version = build.version_string()
@@ -160,7 +158,6 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
160158
filename_prefix + '-py-{VERSION}.zip'.format(
161159
VERSION=bundle_version))
162160
build_bundle(libs, bundle_version, zip_filename,
163-
pkg_folder_prefix=pkg_folder_prefix,
164161
build_tools_version=build_tools_version)
165162

166163
# Build .mpy bundle(s)
@@ -178,8 +175,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
178175
TAG=version["name"],
179176
VERSION=bundle_version))
180177
build_bundle(libs, bundle_version, zip_filename, mpy_cross=mpy_cross,
181-
build_tools_version=build_tools_version,
182-
pkg_folder_prefix=pkg_folder_prefix)
178+
build_tools_version=build_tools_version)
183179

184180
# Build example bundle
185181
zip_filename = os.path.join(output_directory,

0 commit comments

Comments
 (0)