This is an automated email from the ASF dual-hosted git repository. linguini1 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit c00dc4052548606190bc9a10a4889c65f6ab1695 Author: Filipe Cavalcanti <[email protected]> AuthorDate: Thu Jun 11 08:16:59 2026 -0300 interpreters/python: support nuttx-periphery package Adds support for installing nuttx-periphery Python package by default on Python support. This package provides API for accessing Nuttx character drivers. Signed-off-by: Filipe Cavalcanti <[email protected]> --- interpreters/python/Kconfig | 7 +++++++ interpreters/python/Makefile | 30 +++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/interpreters/python/Kconfig b/interpreters/python/Kconfig index a0582835f..752bb08b5 100644 --- a/interpreters/python/Kconfig +++ b/interpreters/python/Kconfig @@ -47,6 +47,13 @@ config INTERPRETERS_CPYTHON_ENABLE_PIP site-packages .pth entry that points to ensurepip's bundled wheel. Disable this to skip pip wheel download/integration entirely. +config INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE + bool "Install NuttX Python package" + default y + ---help--- + Installs the nuttx-periphery Python package into the CPython module image. + This allows importing the nuttx-periphery package into the CPython interpreter, + which provides a Python interface to the NuttX's peripheral drivers. config INTERPRETERS_CPYTHON_PYTHONPATH string "CPython Python path" diff --git a/interpreters/python/Makefile b/interpreters/python/Makefile index 1b1392cac..36aaed3ab 100644 --- a/interpreters/python/Makefile +++ b/interpreters/python/Makefile @@ -179,25 +179,45 @@ $(TARGETBUILD)/Makefile: $(HOSTPYTHON) $(CONFIG_SITE) $(SETUP_LOCAL) $(Q) sed -i 's/^#define HAVE_LIBB2 1/\/* #undef HAVE_LIBB2 *\//' $(TARGETBUILD)/pyconfig.h $(Q) sed -i 's/-lb2//g' $(TARGETBUILD)/Makefile +BUNDLED_WHEELS_DIR = $(CPYTHON_PATH)/Lib/ensurepip/_bundled +# PyPI downloads use the host system pip, not $(HOSTPYTHON)'s ensurepip bundle: +# pip 24.x vendors urllib3 that breaks on Python 3.13 (zlib.Decompress.unused_data). +HOSTPIP = python3 -m pip + $(TARGETLIBPYTHON): $(TARGETBUILD)/Makefile +ifneq ($(or $(filter y,$(CONFIG_INTERPRETERS_CPYTHON_ENABLE_PIP)),$(filter y,$(CONFIG_INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE))),) + $(Q) mkdir -p $(BUNDLED_WHEELS_DIR) +endif ifeq ($(CONFIG_INTERPRETERS_CPYTHON_ENABLE_PIP),y) - $(Q) mkdir -p $(CPYTHON_PATH)/Lib/ensurepip/_bundled $(Q) ( \ PIP_WHEEL_VERSION=$$($(HOSTPYTHON) -c "import ensurepip; print(ensurepip._PIP_VERSION)"); \ - PIP_WHEEL=$(CPYTHON_PATH)/Lib/ensurepip/_bundled/pip-$${PIP_WHEEL_VERSION}-py3-none-any.whl; \ + PIP_WHEEL=$(BUNDLED_WHEELS_DIR)/pip-$${PIP_WHEEL_VERSION}-py3-none-any.whl; \ if [ ! -f "$${PIP_WHEEL}" ]; then \ echo "Fetching pip wheel $${PIP_WHEEL_VERSION} for ensurepip bundle"; \ - $(HOSTPYTHON) -m pip download --only-binary=:all: --no-deps --dest $(CPYTHON_PATH)/Lib/ensurepip/_bundled pip==$${PIP_WHEEL_VERSION}; \ + $(HOSTPIP) download --only-binary=:all: --no-deps --dest $(BUNDLED_WHEELS_DIR) pip==$${PIP_WHEEL_VERSION}; \ fi; \ echo "Pre-compiling pip wheel with build Python (must match embedded CPython version)"; \ - $(HOSTPYTHON) $(CURDIR)/repack_wheel_add_pyc.py "$${PIP_WHEEL}"; \ + $(HOSTPYTHON) $(CURDIR)/repack_wheel_add_pyc.py --package pip "$${PIP_WHEEL}"; \ + ) +endif +ifeq ($(CONFIG_INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE),y) + $(Q) ( \ + set -e; \ + NUTTX_WHEEL=$$(ls $(BUNDLED_WHEELS_DIR)/nuttx_periphery-*-py3-none-any.whl 2>/dev/null | head -1 || true); \ + if [ -z "$${NUTTX_WHEEL}" ]; then \ + echo "Fetching latest nuttx-periphery wheel for ensurepip bundle"; \ + $(HOSTPIP) download --only-binary=:all: --no-deps --dest $(BUNDLED_WHEELS_DIR) nuttx-periphery; \ + NUTTX_WHEEL=$$(ls $(BUNDLED_WHEELS_DIR)/nuttx_periphery-*-py3-none-any.whl); \ + fi; \ + echo "Pre-compiling nuttx-periphery wheel with build Python (must match embedded CPython version)"; \ + $(HOSTPYTHON) $(CURDIR)/repack_wheel_add_pyc.py --package nuttx_periphery "$${NUTTX_WHEEL}"; \ ) endif $(MAKE) -C $(TARGETBUILD) regen-frozen $(MAKE) -C $(TARGETBUILD) libpython$(CPYTHON_VERSION_MINOR).a wasm_stdlib $(Q) ( cp $(TARGETBUILD)/libpython$(CPYTHON_VERSION_MINOR).a $(TARGETLIBPYTHON) ) $(Q) $(UNPACK) $(TARGETMODULESPACK) -d $(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR) -ifeq ($(CONFIG_INTERPRETERS_CPYTHON_ENABLE_PIP),y) +ifneq ($(or $(filter y,$(CONFIG_INTERPRETERS_CPYTHON_ENABLE_PIP)),$(filter y,$(CONFIG_INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE))),) $(Q) mkdir -p $(TARGETMODULES)/python$(CPYTHON_VERSION_MINOR)/site-packages $(Q) ( \ set -e; \
