From 5b3c4dde21eb831a36644acdb008613425901c72 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee <107522312+lavafroth@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:06:26 +0530 Subject: [PATCH] Fix build script file copying issue. --- build.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/build.py b/build.py index ccd9268..d5c024f 100644 --- a/build.py +++ b/build.py @@ -1,34 +1,44 @@ import glob from subprocess import PIPE, Popen from os import listdir, makedirs -from os.path import join, splitext, isfile +from os.path import join, splitext from shutil import copytree, copy +from errno import ENOTDIR SRC = 'src' DST = 'build' -def lib_files(s: str): +def cp(src, dst): + try: + copytree(src, dst) + except OSError as exc: + if exc.errno == ENOTDIR: + copy(src, dst) + else: + raise + + +def to_compile(s: str): name, ext = splitext(s) - if name not in ("code", "boot") and ext == ".py" and isfile(s): + if name not in ("code", "boot") and ext == ".py": return name return None makedirs(DST, exist_ok=True) +mpy_cross_bin = join(".", glob.glob("mpy-cross.static*")[0]) for entry in listdir(SRC): src_path = join(SRC, entry) - if name := lib_files(entry): + if name := to_compile(entry): Popen([ - join(".", glob.glob("mpy-cross.static*")[0]), - src_path, "-o", - join(DST, f'{name}.mpy') + mpy_cross_bin, + "-o", + join(DST, f'{name}.mpy'), + src_path, ], - stdout=PIPE + stdout=PIPE, ).communicate() else: dst_path = join(DST, entry) - if isfile(join(SRC, entry)): - copy(src_path, dst_path) - else: - copytree(src_path, dst_path) + cp(src_path, dst_path)