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

View File

@ -12,9 +12,10 @@ Features include
Downsides Downsides
- $25 USD per microcontroller at most retailers - $25 USD per microcontroller at most retailers
- Not enough space to run KMK without compiling
### Pre-compiling KMK for nice!nano ### 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 Common Retailers

View File

@ -1,32 +1,13 @@
import nox
import shutil import shutil
import subprocess
from os import devnull, system
from pathlib import Path from pathlib import Path
source_dir = Path('kmk') source_dir = Path('kmk')
build_dir = Path('build') build_dir = Path('build')
@nox.session def clean():
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):
build_dir.mkdir(exist_ok=True) build_dir.mkdir(exist_ok=True)
for child in build_dir.iterdir(): for child in build_dir.iterdir():
if child.is_file(): if child.is_file():
@ -35,10 +16,7 @@ def clean(session):
shutil.rmtree(child) shutil.rmtree(child)
@nox.session def compile():
def compile(session):
clean(session)
shutil.copy2('boot.py', 'build/boot.py') shutil.copy2('boot.py', 'build/boot.py')
@ -50,7 +28,15 @@ def compile(session):
# Compile every python file # Compile every python file
for x in source_dir.glob('**/*.py'): for x in source_dir.glob('**/*.py'):
out_path = str(build_dir.joinpath(x).with_suffix('.mpy')) 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()