Skip to content

Commit d34e522

Browse files
committed
library: Include requirements.txt metadata
It is hoped that this data will be useful to circup, enabling it to find dependency information without phoning out to github.
1 parent 4672763 commit d34e522

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

circuitpython_build_tools/build.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ def library(library_path, output_directory, package_folder_prefix,
139139
raise ValueError("Multiple top level py files not allowed. Please put "
140140
"them in a package or combine them into a single file.")
141141

142+
if package_files:
143+
module_name = package_files[0].relative_to(library_path).parent.name
144+
elif py_files:
145+
module_name = py_files[0].relative_to(library_path).name[:-3]
146+
else:
147+
module_name = None
148+
142149
for fn in example_files:
143150
base_dir = os.path.join(output_directory.replace("/lib", "/"),
144151
fn.relative_to(library_path).parent)
@@ -208,6 +215,22 @@ def library(library_path, output_directory, package_folder_prefix,
208215
if mpy_success != 0:
209216
raise RuntimeError("mpy-cross failed on", full_path)
210217

218+
requirements_files = lib_path.glob("requirements.txt*")
219+
requirements_files = [f for f in requirements_files if f.stat().st_size > 0]
220+
if module_name and requirements_files and not example_bundle:
221+
requirements_dir = pathlib.Path(output_directory).parent / "requirements"
222+
if not os.path.isdir(requirements_dir):
223+
os.makedirs(requirements_dir, exist_ok=True)
224+
total_size += 512
225+
requirements_subdir = f"{requirements_dir}/{module_name}"
226+
if not os.path.isdir(requirements_subdir):
227+
os.makedirs(requirements_subdir, exist_ok=True)
228+
total_size += 512
229+
for filename in requirements_files:
230+
full_path = os.path.join(library_path, filename)
231+
output_file = os.path.join(requirements_subdir, "requirements.txt")
232+
shutil.copyfile(full_path, output_file)
233+
211234
for filename in example_files:
212235
full_path = os.path.join(library_path, filename)
213236
output_file = os.path.join(output_directory.replace("/lib", "/"),

0 commit comments

Comments
 (0)