Reimplemented as a util script with std lib only.

Reimplemented as a util script with std lib only.

Decision to add dependencies moved elsewhere. This script should be able to stand alone.

Add some docu on how to use compile.py
This commit is contained in:
Luke D Russell
2022-08-28 19:57:13 +10:00
committed by Kyle Brown
parent b4363c73a7
commit f62d32157a
2 changed files with 16 additions and 29 deletions

42
util/compile.py Normal file
View File

@@ -0,0 +1,42 @@
import shutil
import subprocess
from os import devnull, system
from pathlib import Path
source_dir = Path('kmk')
build_dir = Path('build')
def clean():
build_dir.mkdir(exist_ok=True)
for child in build_dir.iterdir():
if child.is_file():
child.unlink()
else:
shutil.rmtree(child)
def compile():
shutil.copy2('boot.py', 'build/boot.py')
# Make sure the full folder heirarchy exists
for d in source_dir.glob('**/'):
if not build_dir.joinpath(d).exists():
Path.mkdir(build_dir.joinpath(d))
# Compile every python file
for x in source_dir.glob('**/*.py'):
out_path = str(build_dir.joinpath(x).with_suffix('.mpy'))
system(f'mpy-cross {x} -o {out_path}')
if __name__ == '__main__':
try:
subprocess.run('mpy-cross', stdout=devnull, stderr=devnull)
except (FileNotFoundError):
print()
print('`mpy-cross` not found. Ensure mpy-cross is working from a shell.')
print()
clean()
compile()