From bb317eb07ca58bf284282da1bdab5e8ca723c267 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Sat, 20 Sep 2025 15:53:38 -0400 Subject: [PATCH 1/3] Move imports to hopefully lower memory footprint on non-wifi models --- software/firmware/europi.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 056386a88..5a34869fd 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -30,7 +30,6 @@ from version import __version__ -from configuration import ConfigSettings from framebuf import FrameBuffer, MONO_HLSB from europi_config import load_europi_config, MODEL_PICO_2W, MODEL_PICO_W @@ -39,7 +38,6 @@ from europi_log import * from experimental.experimental_config import load_experimental_config -from experimental.wifi import WifiConnection, WifiError if sys.implementation.name == "micropython": @@ -127,6 +125,7 @@ def bootsplash(): # Connect to wifi, if supported if europi_config.PICO_MODEL == MODEL_PICO_W or europi_config.PICO_MODEL == MODEL_PICO_2W: try: + from experimental.wifi import WifiConnection, WifiError oled.centre_text( f"""WiFi connecting {experimental_config.WIFI_SSID} From e351de55fa8f999a7cd04ff6ff3b52e13dec6039 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Tue, 25 Nov 2025 17:18:34 -0500 Subject: [PATCH 2/3] Linting --- software/firmware/europi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 5a34869fd..c0b3e968f 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -126,6 +126,7 @@ def bootsplash(): if europi_config.PICO_MODEL == MODEL_PICO_W or europi_config.PICO_MODEL == MODEL_PICO_2W: try: from experimental.wifi import WifiConnection, WifiError + oled.centre_text( f"""WiFi connecting {experimental_config.WIFI_SSID} From af9ec741b5d95e3cbf96df63af61926ce5f9d299 Mon Sep 17 00:00:00 2001 From: Chris I-B Date: Thu, 11 Jun 2026 19:00:23 -0400 Subject: [PATCH 3/3] Upgrade micropython version used when building UF2 files. Strip comments and docstrings from bundled files to reduce disk usage --- software/uf2_build/Dockerfile | 5 ++- software/uf2_build/copy_and_compile.sh | 20 ++++++++-- software/uf2_build/strip_python.py | 51 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 software/uf2_build/strip_python.py diff --git a/software/uf2_build/Dockerfile b/software/uf2_build/Dockerfile index 8cc017209..f766235e6 100644 --- a/software/uf2_build/Dockerfile +++ b/software/uf2_build/Dockerfile @@ -3,11 +3,11 @@ FROM ubuntu:22.04 ENV TERM=xterm DEBIAN_FRONTEND=noninteractive RUN apt update && apt install -y \ - cmake git-core gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential wget python3 + cmake git-core gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential wget python3 sed WORKDIR / -RUN git clone -b v1.25.0 --depth=1 --recursive https://github.com/micropython/micropython.git +RUN git clone -b v1.28.0 --depth=1 --recursive https://github.com/micropython/micropython.git WORKDIR micropython @@ -25,6 +25,7 @@ BootloaderMenu(EUROPI_SCRIPTS).main()\n\ ' > ports/rp2/modules/main.py COPY software/uf2_build/copy_and_compile.sh / +COPY software/uf2_build/strip_python.py / WORKDIR / diff --git a/software/uf2_build/copy_and_compile.sh b/software/uf2_build/copy_and_compile.sh index 8ab4d0266..4606c8679 100644 --- a/software/uf2_build/copy_and_compile.sh +++ b/software/uf2_build/copy_and_compile.sh @@ -5,10 +5,22 @@ echo "Copying EuroPi firmware and scripts to container..." mkdir /micropython/ports/rp2/modules/contrib mkdir /micropython/ports/rp2/modules/experimental mkdir /micropython/ports/rp2/modules/tools -cp -r europi/software/firmware/*.py /micropython/ports/rp2/modules -cp -r europi/software/firmware/experimental/*.py /micropython/ports/rp2/modules/experimental -cp -r europi/software/firmware/tools/*.py /micropython/ports/rp2/modules/tools -cp -r europi/software/contrib/*.py /micropython/ports/rp2/modules/contrib +for pyfile in $(ls europi/software/firmware/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/$f" +done +for pyfile in $(ls europi/software/firmware/experimental/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/experimental/$f" +done +for pyfile in $(ls europi/software/firmware/tools/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/tools/$f" +done +for pyfile in $(ls europi/software/contrib/*.py); do + f=$(basename $pyfile) + python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/contrib/$f" +done echo "Compiling micropython and firmware modules..." cd /micropython/ports/rp2 diff --git a/software/uf2_build/strip_python.py b/software/uf2_build/strip_python.py new file mode 100644 index 000000000..a8cadcc13 --- /dev/null +++ b/software/uf2_build/strip_python.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +""" +Strip comments and docstrings from a file. + +Copied from https://gist.github.com/BroHui/aca2b8e6e6bdf3cb4af4b246c9837fa3 with modifications. +""" + +import sys, token, tokenize + + +def process_file(infile, outfile): + """ + Remove comments and docstrings from one file and write the result to another. + + @param infile The path to the file to process + @param outfile The path to the file we're generating + """ + source = open(infile, "r") + mod = open(outfile, "w") + + prev_toktype = token.INDENT + last_lineno = -1 + last_col = 0 + + tokgen = tokenize.generate_tokens(source.readline) + for toktype, ttext, (slineno, scol), (elineno, ecol), ltext in tokgen: + if 0: # Change to if 1 to see the tokens fly by. + print("%10s %-14s %-20r %r" % ( + tokenize.tok_name.get(toktype, toktype), + "%d.%d-%d.%d" % (slineno, scol, elineno, ecol), + ttext, ltext + )) + if slineno > last_lineno: + last_col = 0 + if scol > last_col: + mod.write(" " * (scol - last_col)) + if toktype == token.STRING and prev_toktype == token.INDENT: + # Docstring + mod.write("#--") + elif toktype == tokenize.COMMENT: + # Comment + mod.write("##") + else: + mod.write(ttext) + prev_toktype = toktype + last_col = ecol + last_lineno = elineno + + +if __name__ == '__main__': + process_file(sys.argv[1], sys.argv[2])