From 9524f770b3edfc735b445fe528737538ffc67048 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 16 Jun 2024 11:40:19 -0500 Subject: [PATCH] Add circuitpython-mpy-cross This wraps the process of building or downloading mpy-cross for a specified version, then running it with specified arguments. e.g., ``` $ circuitpython-mpy-cross --circuitpython-version 9.x -- --version CircuitPython 9.0.0-alpha.2 on 2023-10-27; mpy-cross emitting mpy v6.1 ``` --- .../scripts/circuitpython_mpy_cross.py | 21 +++++++++++++++++++ setup.py | 1 + 2 files changed, 22 insertions(+) create mode 100644 circuitpython_build_tools/scripts/circuitpython_mpy_cross.py diff --git a/circuitpython_build_tools/scripts/circuitpython_mpy_cross.py b/circuitpython_build_tools/scripts/circuitpython_mpy_cross.py new file mode 100644 index 0000000..d8e5cb2 --- /dev/null +++ b/circuitpython_build_tools/scripts/circuitpython_mpy_cross.py @@ -0,0 +1,21 @@ +import subprocess + +import click + +from ..target_versions import VERSIONS +from ..build import mpy_cross + +@click.command(context_settings={"ignore_unknown_options": True}) +@click.option("--circuitpython-version", type=click.Choice([version["name"] for version in VERSIONS])) +@click.option("--quiet/--no-quiet", "quiet", type=bool, default=True) +@click.argument("mpy-cross-args", nargs=-1, required=True) +def main(circuitpython_version, quiet, mpy_cross_args): + version_info, = [v for v in VERSIONS if v["name"] == circuitpython_version] + mpy_cross_exe = str(mpy_cross(version_info, quiet)) + try: + subprocess.check_call([mpy_cross_exe, *mpy_cross_args]) + except subprocess.CalledProcessError as e: + raise SystemExit(e.returncode) + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 9052130..4358300 100644 --- a/setup.py +++ b/setup.py @@ -18,5 +18,6 @@ entry_points=''' [console_scripts] circuitpython-build-bundles=circuitpython_build_tools.scripts.build_bundles:build_bundles + circuitpython-mpy-cross=circuitpython_build_tools.scripts.circuitpython_mpy_cross:main ''' )