Skip to content

Commit

Permalink
Add cross-compilation as an option for deploy script (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster authored Oct 28, 2024
1 parent 9873b12 commit be8d674
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Micropython files
*.mpy
39 changes: 25 additions & 14 deletions ci/deploy_to_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@


@click.command()
def deploy():
@click.option("-march", "arch", type=str, help="Compile to the specified architecture.")
def deploy(arch=""):
"""Deploy files to a device via mpremote"""
try:
deploy_py_files(Path("examples"), ":", clear=False)
deploy_py_files(Path("examples/devices"), ":/devices")
deploy_py_files(Path("examples/data"), ":/data")
deploy_py_files(Path("examples/example_fonts"), ":/example_fonts")
deploy_py_files(Path("src/tempe"), ":/lib/tempe")
deploy_py_files(Path("src/tempe/colors"), ":/lib/tempe/colors")
# deploy_py_files(Path("src/tempe/fonts"), ":/lib/tempe/fonts")
deploy_py_files(Path("src/tempe/colormaps"), ":/lib/tempe/colormaps")
deploy_py_files(Path("examples"), ":", clear=False, arch="")
deploy_py_files(Path("examples/devices"), ":/devices", arch="")
deploy_py_files(Path("examples/data"), ":/data", arch=arch)
deploy_py_files(Path("examples/example_fonts"), ":/example_fonts", arch=arch)
deploy_py_files(Path("src/tempe"), ":/lib/tempe", arch=arch)
deploy_py_files(Path("src/tempe/colors"), ":/lib/tempe/colors", arch=arch)
deploy_py_files(Path("src/tempe/fonts"), ":/lib/tempe/fonts", arch=arch)
deploy_py_files(Path("src/tempe/colormaps"), ":/lib/tempe/colormaps", arch=arch)
except subprocess.CalledProcessError as exc:
print("Error:")
print(exc.stderr)
raise


def deploy_py_files(path: Path, destination, clear=True):
def deploy_py_files(path: Path, destination, clear=True, arch=""):
try:
mpremote("mkdir", destination)
except subprocess.CalledProcessError as exc:
Expand All @@ -50,12 +51,15 @@ def deploy_py_files(path: Path, destination, clear=True):
pass

for file in path.glob("*.py"):
mpremote("cp", str(file), f"{destination}/{file.name}")
if arch:
print(f"Compiling {file}")
result = mpycross(arch, file)
else:
print(f"Copying {file}")
mpremote("cp", str(file), f"{destination}/{file.name}")

for file in path.glob("*.mpy"):
mpremote("cp", str(file), f"{destination}/{file.name}")

for file in path.glob("*.af"):
print(f"Copying {file}")
mpremote("cp", str(file), f"{destination}/{file.name}")


Expand All @@ -75,5 +79,12 @@ def mpremote(command, *args):
return result.stdout


def mpycross(arch, *args):
result = subprocess.run(
["mpy-cross", f"-march={arch}", *args], capture_output=True, check=True
)
return result.stdout


if __name__ == "__main__":
deploy()
19 changes: 14 additions & 5 deletions docs/source/user_guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ Ensure that the Pico is plugged in to your computer and no other program
python -m ci.deploy_to_device
and this will install the tempe code in the ``/lib`` directory (which is
on :py:obj:`sys.path`) and the examples in the main directory (with
example drivers in ``/devices``).
on :py:obj:`sys.path`) and the examples in the main directory, with
example drivers in ``/devices``, example data in ``/data`` and example fonts
in ``/example_fonts``.

You can optionally used the ``-march`` argument to have the files (other than
the examples and example driveers) cross-compiled for the specified architecture.
Eg. for a Raspberry Pi Pico, you would do:

.. code-block:: console
python -m ci.deploy_to_device -march armv6m
Running the Examples
--------------------
Expand All @@ -63,6 +72,6 @@ Writing Code Using Tempe

Although Tempe is a Micropython library, it provides ``.pyi`` stub files for
typing support. If you add the tempe sources to the paths where tools like
``mypy`` and ``pyright`` look for stubs (in particular, ``pip install -e ...``
will likely work), then you should be able to get type-hints for the code you
are writing in your IDE or as a check step as part of your CI.
``mypy`` and ``pyright`` look for stubs, then you should be able to get
type-hints for the code you are writing in your IDE or as a check step as
part of your CI.

0 comments on commit be8d674

Please sign in to comment.