From f62d32157afdf26be273cd2c6267db4c0310b5ca Mon Sep 17 00:00:00 2001 From: Luke D Russell Date: Sun, 28 Aug 2022 19:57:13 +1000 Subject: [PATCH] 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 --- docs/Officially_Supported_Microcontrollers.md | 3 +- noxfile.py => util/compile.py | 42 +++++++------------ 2 files changed, 16 insertions(+), 29 deletions(-) rename noxfile.py => util/compile.py (52%) diff --git a/docs/Officially_Supported_Microcontrollers.md b/docs/Officially_Supported_Microcontrollers.md index b99df4a..c7fbd88 100644 --- a/docs/Officially_Supported_Microcontrollers.md +++ b/docs/Officially_Supported_Microcontrollers.md @@ -12,9 +12,10 @@ Features include Downsides - $25 USD per microcontroller at most retailers +- Not enough space to run KMK without compiling ### Pre-compiling KMK for nice!nano -nice!nano has limited flash memory which does not fit CircuitPython, adafruit-ble, and KMK by default. You will need to use pre-compiled KMK to get it to fit. Grab [compatible mpy-cross](https://adafruit-circuit-python.s3.amazonaws.com/index.html?prefix=bin/mpy-cross/) and run `make compile` to generate `.mpy` version of KMK files before copying them over. +As the nice!nano has limited flash memory you'll need to compile KMK. To do that you'll need to download and install the [compatible mpy-cross](https://adafruit-circuit-python.s3.amazonaws.com/index.html?prefix=bin/mpy-cross/) for your Operating System. Don't forget to add it to your PATH, test by running `mpy-cross` from a shell (Powershell, Bash, Fish, etc). Once that's set up, run either `make compile` (if you have `make`) or `python util/compile.py`to generate the `.mpy` versions of KMK files. Then copy the whole compiled `kmk/` directory to your keyboard. Common Retailers diff --git a/noxfile.py b/util/compile.py similarity index 52% rename from noxfile.py rename to util/compile.py index ac273c0..1f74f7d 100644 --- a/noxfile.py +++ b/util/compile.py @@ -1,32 +1,13 @@ -import nox import shutil +import subprocess +from os import devnull, system from pathlib import Path source_dir = Path('kmk') build_dir = Path('build') -@nox.session -def black(session): - '''Format python code with `black`.''' - session.install('black') - session.run('black', source_dir) - - -@nox.session -def isort(session): - session.install('isort') - session.run('isort', source_dir) - - -@nox.session -def flake8(session): - session.install('flake8') - session.run('flake8', source_dir) - - -@nox.session -def clean(session): +def clean(): build_dir.mkdir(exist_ok=True) for child in build_dir.iterdir(): if child.is_file(): @@ -35,10 +16,7 @@ def clean(session): shutil.rmtree(child) -@nox.session -def compile(session): - - clean(session) +def compile(): shutil.copy2('boot.py', 'build/boot.py') @@ -50,7 +28,15 @@ def compile(session): # Compile every python file for x in source_dir.glob('**/*.py'): out_path = str(build_dir.joinpath(x).with_suffix('.mpy')) - session.run('mpy-cross', f'{x}', '-o', f'{out_path}', external=True) + system(f'mpy-cross {x} -o {out_path}') -nox.options.sessions = ['black', 'isort'] # Default sessions +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()