diff --git a/Config.uk b/Config.uk index 5a3ff929038258dde40a6b9d5ddb5b4ada67bc27..84311e9e308b402f3eec476e45c3f388138db6de 100644 --- a/Config.uk +++ b/Config.uk @@ -100,5 +100,29 @@ config LIBPYTHON3_EXTENSION_PILLOW default y endif +if LIBTFLITE +config LIBPYTHON3_EXTENSION_TFLITE + bool "tflite" + default y +endif + +if LIBPYTHON_TFLITE_SUPPORT +config LIBPYTHON3_EXTENSION_TFLITE_SUPPORT + bool "tflite-support" + default y +endif + +if LIBPYBIND11_ABSEIL +config LIBPYTHON3_EXTENSION_PYBIND11_ABSEIL + bool "pybind11_abseil" + default y +endif + +if LIBPYTHON_OPENCV +config LIBPYTHON3_EXTENSION_OPENCV + bool "opencv" + default y +endif + endif endif diff --git a/Makefile.uk b/Makefile.uk index 7622bb0033555ab5880b509384c478f0659cdddc..037fd6ee5184d9990bb4e5f31b28e3fa7def2026 100644 --- a/Makefile.uk +++ b/Makefile.uk @@ -57,8 +57,11 @@ LIBPYTHON3_VERSION_LONG=$(LIBPYTHON3_VERSION).$(LIBPYTHON3_REVISION) LIBPYTHON3_BASENAME=Python-$(LIBPYTHON3_VERSION_LONG) LIBPYTHON3_URL=https://www.python.org/ftp/python/$(LIBPYTHON3_VERSION_LONG)/$(LIBPYTHON3_BASENAME).tgz LIBPYTHON3_PATCHDIR=$(LIBPYTHON3_BASE)/patches + +ifeq ($(CONFIG_LIBPYTHON3), y) $(eval $(call fetch,libpython3,$(LIBPYTHON3_URL))) $(eval $(call patch,libpython3,$(LIBPYTHON3_PATCHDIR),$(LIBPYTHON3_BASENAME))) +endif ################################################################################ # Helpers @@ -493,32 +496,49 @@ LIBPYTHON3_EXTENSIONS_SRCS-y += $(LIBPYTHON3_SRC)/Modules/_zoneinfo.c # Build root filesystem for Python interpreter PYTHON_ROOTFS = $(APP_BASE)/$(path) +ifeq ($(CONFIG_LIBPYTHON3), y) # Create virtual environment $(PYTHON_ROOTFS)/.keep: $(LIBPYTHON3_BUILD)/.origin - @test $(LIBPYTHON3_VERSION) = `python -V | cut -d' ' -f2 | cut -d. -f1,2` || \ + @test $(LIBPYTHON3_VERSION) = `python3 -V | cut -d' ' -f2 | cut -d. -f1,2` || \ (echo -e "WARNING: creating virtualenv with wrong python version, pip might not work correctly\nPress return to continue" && read) - python -m venv $(PYTHON_ROOTFS) + python3 -m venv $(PYTHON_ROOTFS) find "$(PYTHON_ROOTFS)" -type d -name '__pycache__' | xargs rm -rf touch $@ +$(PYTHON_ROOTFS)/.patched: $(PYTHON_ROOTFS)/.keep + cd $(LIBPYTHON3_SRC) && \ + for patchfile in $(LIBPYTHON3_PATCHDIR)/*.patch; do \ + echo "$$patchfile"; \ + patch -p1 < $$patchfile || { echo "Failed to apply patch $$patchfile"; exit 1; } \ + done + touch $@ + # Configure origin -$(PYTHON_ROOTFS)/.configured: $(PYTHON_ROOTFS)/.keep +$(PYTHON_ROOTFS)/.configured: $(PYTHON_ROOTFS)/.keep $(PYTHON_ROOTFS)/.patched cd $(LIBPYTHON3_SRC) && ./configure --prefix=$(shell realpath $(APP_BASE)/$(path)) - rm -f $(LIBPYTHON3_SRC)/pyconfig.h +# rm -f $(LIBPYTHON3_SRC)/pyconfig.h touch $@ # Install Python standard library into virtual environment $(PYTHON_ROOTFS)/.done: $(PYTHON_ROOTFS)/.configured cd $(LIBPYTHON3_SRC) && make libinstall + rm -f $(LIBPYTHON3_SRC)/pyconfig.h cp $(LIBPYTHON3_BASE)/_sysconfigdata.py $(PYTHON_ROOTFS)/lib/python$(LIBPYTHON3_VERSION)/ touch $@ + cd $(LIBPYTHON3_SRC) && \ + for patchfile in $(LIBPYTHON3_PATCHDIR)/*.patch; do \ + echo "$$patchfile"; \ + patch -R -p1 < $$patchfile || { echo "Failed to apply cancel patch $$patchfile"; exit 1; } \ + done + $(PYTHON_ROOTFS)/.compiled: python-rootfs - test $(LIBPYTHON3_VERSION) = `python -V | cut -d' ' -f2 | cut -d. -f1,2` || \ + test $(LIBPYTHON3_VERSION) = `python3 -V | cut -d' ' -f2 | cut -d. -f1,2` || \ (echo "ERROR: local Python version is not $(LIBPYTHON3_VERSION), cannot compile .py files" && false) - python -m compileall -x 'lib2to3/|test/bad' "$(PYTHON_ROOTFS)/lib" + python3 -m compileall -x 'lib2to3/|test/bad' "$(PYTHON_ROOTFS)/lib" touch $@ .PHONY: python-rootfs python-rootfs: $(PYTHON_ROOTFS)/.done python-rootfs-compiled: $(PYTHON_ROOTFS)/.compiled +endif diff --git a/init.c b/init.c index 2ae151bb49b15d981256ecfbea06570b26b33484..5b7332eb6518885af8e5b71e2b0e26dfafcd3d08 100644 --- a/init.c +++ b/init.c @@ -38,7 +38,7 @@ void __constructor python_init(void) { setenv("PYTHONHOME", CONFIG_LIBPYTHON3_PYTHONHOME, 0); setenv("PYTHONPATH", CONFIG_LIBPYTHON3_PYTHONPATH, 0); - setenv("PYTHONUSERBASE", "site-packages", 0); + setenv("PYTHONUSERBASE", "./", 0); setenv("TMPDIR", CONFIG_LIBPYTHON3_TMPDIR, 0); setenv("_PYTHON_SYSCONFIGDATA_NAME", "_sysconfigdata", 0); } diff --git a/modules_config.c b/modules_config.c index 1829eee6b960d16c0e65ff532047958415d26c63..f6a147ed96f611a8ad7253b9a9f7cf89b16c6eab 100644 --- a/modules_config.c +++ b/modules_config.c @@ -182,7 +182,7 @@ extern PyObject* PyInit__sfc64(void); extern PyObject* PyInit__simd(void); extern PyObject* PyInit__struct_ufunc_tests(void); extern PyObject* PyInit__umath_linalg(void); -extern PyObject* PyInit__umath_tests(void); +// extern PyObject* PyInit__umath_tests(void); /* Numpy end */ #endif @@ -206,6 +206,39 @@ extern PyObject* PyInit__webp(void); /* Pillow end */ #endif +#if CONFIG_LIBPYTHON3_EXTENSION_TFLITE +/* tflite */ +extern PyObject* PyInit__pywrap_tensorflow_interpreter_wrapper(void); +/* tflite end */ +#endif + +#if CONFIG_LIBPYTHON3_EXTENSION_TFLITE_SUPPORT +/* tflite-support */ +extern PyObject* PyInit_index_builder(void); +extern PyObject* PyInit__pywrap_metadata_version(void); +extern PyObject* PyInit__pywrap_flatbuffers(void); +extern PyObject* PyInit_image_utils(void); +extern PyObject* PyInit__pywrap_image_embedder(void); +extern PyObject* PyInit__pywrap_image_searcher(void); +extern PyObject* PyInit__pywrap_object_detector(void); +extern PyObject* PyInit__pywrap_image_segmenter(void); +extern PyObject* PyInit__pywrap_image_classifier(void); +/* tflite-support end */ +#endif + +#if CONFIG_LIBPYTHON3_EXTENSION_PYBIND11_ABSEIL +/* pybind11_abseil */ +extern PyObject* PyInit_ok_status_singleton(void); +extern PyObject* PyInit_status(void); +/* pybind11_abseil end */ +#endif + +#if CONFIG_LIBPYTHON3_EXTENSION_OPENCV +/* opencv */ +extern PyObject* PyInit_cv2(void); +/* opencv end */ +#endif + struct _inittab _PyImport_Inittab[] = { {"posix", PyInit_posix}, @@ -401,7 +434,7 @@ struct _inittab _PyImport_Inittab[] = { {"numpy_core__simd", PyInit__simd}, {"numpy_core__struct_ufunc_tests", PyInit__struct_ufunc_tests}, {"numpy_linalg__umath_linalg", PyInit__umath_linalg}, - {"numpy_core__umath_tests", PyInit__umath_tests}, + // {"numpy_core__umath_tests", PyInit__umath_tests}, #endif #if CONFIG_LIBPYTHON3_EXTENSION_SHAPELY @@ -426,6 +459,31 @@ struct _inittab _PyImport_Inittab[] = { #endif #endif +#if CONFIG_LIBPYTHON3_EXTENSION_TFLITE + {"tflite_runtime__pywrap_tensorflow_interpreter_wrapper", PyInit__pywrap_tensorflow_interpreter_wrapper}, +#endif + +#if CONFIG_LIBPYTHON3_EXTENSION_TFLITE_SUPPORT + {"tflite_support_scann_ondevice_index_builder", PyInit_index_builder}, + {"tflite_support_metadata__pywrap_metadata_version", PyInit__pywrap_metadata_version}, + {"tflite_support_metadata__pywrap_flatbuffers", PyInit__pywrap_flatbuffers}, + {"tflite_support_vision_image_utils", PyInit_image_utils}, + {"tflite_support_vision__pywrap_image_embedder", PyInit__pywrap_image_embedder}, + {"tflite_support_vision__pywrap_image_searcher", PyInit__pywrap_image_searcher}, + {"tflite_support_vision__pywrap_object_detector", PyInit__pywrap_object_detector}, + {"tflite_support_vision__pywrap_image_segmenter", PyInit__pywrap_image_segmenter}, + {"tflite_support_vision__pywrap_image_classifier", PyInit__pywrap_image_classifier}, +#endif + +#if CONFIG_LIBPYTHON3_EXTENSION_PYBIND11_ABSEIL + {"pybind11_abseil_ok_status_singleton", PyInit_ok_status_singleton}, + {"pybind11_abseil_status", PyInit_status}, +#endif + +#if CONFIG_LIBPYTHON3_EXTENSION_OPENCV + {"cv2",PyInit_cv2}, +#endif + /* Sentinel */ {0, 0} };