From fcfee6ff423af26c399f5530608bb411ed8263e3 Mon Sep 17 00:00:00 2001 From: MilhouseVH Date: Thu, 24 Oct 2019 22:51:28 +0100 Subject: [PATCH] config/functions: add Python bytecode/source code helper functions --- config/functions | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config/functions b/config/functions index cbd44b4dd4..e77c5a59eb 100644 --- a/config/functions +++ b/config/functions @@ -1046,6 +1046,22 @@ source_package() { fi } +# arg1: file, or directory to recursively compile. +python_compile() { + local path="${1:-${INSTALL}/usr/lib/${PKG_PYTHON_VERSION}}" + ${TOOLCHAIN}/bin/python3 -Wi -t -B ${TOOLCHAIN}/lib/${PKG_PYTHON_VERSION}/compileall.py -f -d "${path#${INSTALL}}" "${path}" + python_remove_source "${path}" +} + +# arg1: file, or directory from which to recursively remove all py source code +python_remove_source() { + local path="${1:-${INSTALL}/usr/lib/${PKG_PYTHON_VERSION}}" + if [ -d "${path}" ]; then + find "${path}" -type f -name '*.py' -delete + else + rm -f "${path}" + fi +} ### KERNEL HELPERS ### kernel_path() {