Compare commits

..

No commits in common. "master" and "tannewt-patch-5" have entirely different histories.

4 changed files with 70 additions and 62 deletions

View file

@ -1,6 +1,6 @@
# Adafruit CircuitPython Build Tools
[![Discord](https://img.shields.io/discord/327254708534116352.svg)](https://adafru.it/discord)
[![Discord](https://img.shields.io/discord/327254708534116352.svg)](https://discord.gg/nBQh6qu)
This repo contains build scripts used to build the
[Adafruit CircuitPython bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle), [CircuitPython Community bundle](https://github.com/adafruit/CircuitPython_Community_Bundle)

View file

@ -3,7 +3,6 @@
# The MIT License (MIT)
#
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
# 2018, 2019 Michael Schroeder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@ -25,7 +24,6 @@
import os
import os.path
import pathlib
import semver
import shutil
import sys
@ -33,7 +31,6 @@ import subprocess
import tempfile
IGNORE_PY = ["setup.py", "conf.py", "__init__.py"]
GLOB_PATTERNS = ["*.py", "font5x8.bin"]
def version_string(path=None, *, valid_semver=False):
version = None
@ -109,46 +106,71 @@ def library(library_path, output_directory, package_folder_prefix,
package_files = []
example_files = []
total_size = 512
for filename in os.listdir(library_path):
full_path = os.path.join(library_path, filename)
if os.path.isdir(full_path):
path_walk = [names for names in os.walk(full_path)]
#print("- '{}' walk: {}".format(filename, path_walk))
lib_path = pathlib.Path(library_path)
parent_idx = len(lib_path.parts)
glob_search = []
for pattern in GLOB_PATTERNS:
glob_search.extend(list(lib_path.rglob(pattern)))
# iterate through path_walk, appending each file to
# 'walked_files' while retaining subdirectory structure
walked_files = []
for path in path_walk:
rel_path = ""
if filename.startswith("examples"):
path_tail_idx = path[0].rfind("examples/")
if path_tail_idx != -1:
rel_path = "{}/".format(path[0][path_tail_idx + 9:])
for file in glob_search:
if file.parts[parent_idx] == "examples":
example_files.append(file)
else:
if not example_bundle:
is_package = False
for prefix in package_folder_prefix:
if file.parts[parent_idx].startswith(prefix):
is_package = True
if is_package:
package_files.append(file)
else:
if file.name in IGNORE_PY:
#print("Ignoring:", file.resolve())
path_tail_idx = (path[0].rfind("{}/".format(filename))
+ (len(filename) +1))
path_tail = path[0][path_tail_idx:]
# if this entry is the package top dir, keep it
# empty so we don't double append the dir name
if filename not in path_tail:
rel_path = "{}/".format(path_tail)
for path_files in path[2]:
walked_files.append("{}{}".format(rel_path, path_files))
#print(" - expanded file walk: {}".format(walked_files))
files = filter(
lambda x: x.endswith(".py") or x.startswith("font5x8.bin"),
walked_files
)
files = map(lambda x: os.path.join(filename, x), files)
if filename.startswith("examples"):
example_files.extend(files)
#print("- example files: {}".format(example_files))
else:
if (not example_bundle and
not filename.startswith(package_folder_prefix)):
print("skipped path: {}".format(full_path))
continue
if file.parent == lib_path:
py_files.append(file)
if not example_bundle:
package_files.extend(files)
#print("- package files: {} | {}".format(filename, package_files))
if (filename.endswith(".py") and
filename not in IGNORE_PY and
not example_bundle):
py_files.append(filename)
if len(py_files) > 1:
raise ValueError("Multiple top level py files not allowed. Please put "
"them in a package or combine them into a single file.")
raise ValueError("Multiple top level py files not allowed. Please put them in a package "
"or combine them into a single file.")
for fn in example_files:
base_dir = os.path.join(output_directory.replace("/lib", "/"),
fn.relative_to(library_path).parent)
base_dir = os.path.join(output_directory.replace("/lib", "/"), os.path.dirname(fn))
if not os.path.isdir(base_dir):
os.makedirs(base_dir)
total_size += 512
for fn in package_files:
base_dir = os.path.join(output_directory,
fn.relative_to(library_path).parent)
base_dir = os.path.join(output_directory, os.path.dirname(fn))
if not os.path.isdir(base_dir):
os.makedirs(base_dir)
total_size += 512
@ -166,20 +188,16 @@ def library(library_path, output_directory, package_folder_prefix,
for filename in py_files:
full_path = os.path.join(library_path, filename)
output_file = os.path.join(
output_directory,
filename.relative_to(library_path).with_suffix(new_extension)
)
output_file = os.path.join(output_directory,
filename.replace(".py", new_extension))
with tempfile.NamedTemporaryFile() as temp_file:
_munge_to_temp(full_path, temp_file, library_version)
if mpy_cross:
mpy_success = subprocess.call([
mpy_cross,
"-o", output_file,
"-s", str(filename.relative_to(library_path)),
temp_file.name
])
mpy_success = subprocess.call([mpy_cross,
"-o", output_file,
"-s", filename,
temp_file.name])
if mpy_success != 0:
raise RuntimeError("mpy-cross failed on", full_path)
else:
@ -190,28 +208,21 @@ def library(library_path, output_directory, package_folder_prefix,
with tempfile.NamedTemporaryFile() as temp_file:
_munge_to_temp(full_path, temp_file, library_version)
if not mpy_cross or os.stat(full_path).st_size == 0:
output_file = os.path.join(output_directory,
filename.relative_to(library_path))
output_file = os.path.join(output_directory, filename)
shutil.copyfile(temp_file.name, output_file)
else:
output_file = os.path.join(
output_directory,
filename.relative_to(library_path).with_suffix(new_extension)
)
mpy_success = subprocess.call([
mpy_cross,
"-o", output_file,
"-s", str(filename.relative_to(library_path)),
temp_file.name
])
output_file = os.path.join(output_directory,
filename.replace(".py", new_extension))
mpy_success = subprocess.call([mpy_cross,
"-o", output_file,
"-s", filename,
temp_file.name])
if mpy_success != 0:
raise RuntimeError("mpy-cross failed on", full_path)
for filename in example_files:
full_path = os.path.join(library_path, filename)
output_file = os.path.join(output_directory.replace("/lib", "/"),
filename.relative_to(library_path))
output_file = os.path.join(output_directory.replace("/lib", "/"), filename)
with tempfile.NamedTemporaryFile() as temp_file:
_munge_to_temp(full_path, temp_file, library_version)
shutil.copyfile(temp_file.name, output_file)

View file

@ -91,9 +91,7 @@ def build_bundle(libs, bundle_version, output_filename, package_folder_prefix,
for line in versions.stdout.split(b"\n"):
if not line:
continue
if line.startswith(b"ssh://git@"):
repo = b"https://" + line.split(b"@")[1][:-len(".git")]
elif line.startswith(b"git@"):
if line.startswith(b"git@"):
repo = b"https://github.com/" + line.split(b":")[1][:-len(".git")]
elif line.startswith(b"https:"):
repo = line.strip()[:-len(".git")]
@ -141,8 +139,6 @@ def _find_libraries(current_path, depth):
def build_bundles(filename_prefix, output_directory, library_location, library_depth, package_folder_prefix):
os.makedirs(output_directory, exist_ok=True)
package_folder_prefix = package_folder_prefix.split(", ")
bundle_version = build.version_string()
libs = _find_libraries(os.path.abspath(library_location), library_depth)

View file

@ -25,5 +25,6 @@
# The tag specifies which version of CircuitPython to use for mpy-cross.
# The name is used when constructing the zip file names.
VERSIONS = [
{"tag": "6.1.0", "name": "6.x"},
{"tag": "4.0.0-alpha.2", "name": "4.x"},
{"tag": "5.0.0-alpha.0", "name": "5.x"},
]