From 16c9adf06a982c97e67f549334532771a83ecf40 Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Fri, 1 May 2026 15:18:54 +0100 Subject: [PATCH 1/5] Don't add quite so many libraries as they are redundant and can make long command lines --- climatology/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/climatology/Makefile.in b/climatology/Makefile.in index 98eef68ae6..186af045e6 100644 --- a/climatology/Makefile.in +++ b/climatology/Makefile.in @@ -32,7 +32,7 @@ LINKER = $(CXX) CXXFLAGS = -I../include @CXXFLAGS@ @CPPFLAGS@ LFLAGS = @LDFLAGS@ -LIBS = -L../lib/ @LIBS@ @FLIBS@ @LAPACK_LIBS@ +LIBS = -L../lib/ @LIBS@ .SUFFIXES: .cpp .o From ea8b321ab1388284340115926203579af5285c4d Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Fri, 1 May 2026 15:19:31 +0100 Subject: [PATCH 2/5] Support for NumPY 2.0 --- femtools/embed_python.c | 23 +++++++++++++++++++++-- femtools/python_statec.c | 19 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/femtools/embed_python.c b/femtools/embed_python.c index 0de35faac6..1050044337 100644 --- a/femtools/embed_python.c +++ b/femtools/embed_python.c @@ -43,6 +43,17 @@ USA #ifdef HAVE_NUMPY #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include "numpy/arrayobject.h" + +static int ensure_numpy_api(void) { + if (PyArray_API != NULL) { + return 0; + } +#if NPY_ABI_VERSION < 0x02000000 + return _import_array(); +#else + return PyArray_ImportNumPyAPI(); +#endif +} #endif void deallocate_c_array(void *ptr) { @@ -448,7 +459,11 @@ void set_tensor_field_from_python(char *function, int function_len, int dim, *stat = 1; return; #else - import_array(); + if (ensure_numpy_api() < 0) { + PyErr_Print(); + *stat = 1; + return; + } set_field_from_python(function, function_len, dim, nodes, NULL, x, y, z, t, NULL, stat, result_dim, (void**)&result, set_tensor_result_double, NULL); @@ -637,7 +652,11 @@ void set_field_from_python_fields(char *function, int function_len, int dim, int #else PyObject *pLocals, *pFunc, *pNames, *pT, *pdT, *pPos, *pArgs, *pKwArgs, *pResult; - import_array(); + if (ensure_numpy_api() < 0) { + PyErr_Print(); + *stat = 1; + return; + } // load the user's function as a Python object -- borrows locals pLocals = PyDict_New(); diff --git a/femtools/python_statec.c b/femtools/python_statec.c index bf584012e0..f3e46af589 100644 --- a/femtools/python_statec.c +++ b/femtools/python_statec.c @@ -1,6 +1,19 @@ #define ALLOW_IMPORT_ARRAY #include "python_statec.h" +#ifdef HAVE_NUMPY +static int ensure_numpy_api(void) { + if (PyArray_API != NULL) { + return 0; + } +#if NPY_ABI_VERSION < 0x02000000 + return _import_array(); +#else + return PyArray_ImportNumPyAPI(); +#endif +} +#endif + #if PY_MAJOR_VERSION >= 3 #define PyInt_FromLong PyLong_FromLong #define PyString_FromString PyUnicode_FromString @@ -47,7 +60,11 @@ void python_init_(void){ #endif #ifdef HAVE_NUMPY // Enable use of NumPy arrays in C - import_array(); + if (ensure_numpy_api() < 0) { + PyErr_Print(); + fprintf(stderr, "Error: Initializing the NumPy C API failed.\n"); + return; + } // Import the NumPy module in our Python interpreter if(PyRun_SimpleString("import numpy") == -1) From 2a2fa783735f6c36f624a5ad4417d4140eac9386 Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Fri, 1 May 2026 15:20:12 +0100 Subject: [PATCH 3/5] Remove clean-python --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 8c10866c76..045cbf86d7 100755 --- a/Makefile.in +++ b/Makefile.in @@ -340,7 +340,7 @@ endif @cd main; $(MAKE) clean @rm -fr bin lib -clean: clean-light clean-test python_clean clean-debian +clean: clean-light clean-test clean-debian @echo " CLEAN libvtkfortran" @cd libvtkfortran; $(MAKE) clean @echo " CLEAN libjudy" From 510d042e718574bdc269cd3667f8b462a7d25a8b Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Tue, 9 Jun 2026 16:01:09 +0100 Subject: [PATCH 4/5] Update some CI parameters --- .github/workflows/ubuntu.yml | 2 +- .pre-commit-config.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 772681c29b..fdc87e9b56 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -32,7 +32,7 @@ jobs: steps: - name: Check Out Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to Docker Hub uses: docker/login-action@v2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 11302f6a89..bd0018d779 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: - id: isort args: ["--profile", "black", "--filter-files"] - repo: https://github.com/asottile/pyupgrade - rev: v3.6.0 + rev: v3.21.2 hooks: - id: pyupgrade - repo: https://github.com/PyCQA/flake8 From 5c2a08969f9f06945696bf530843c4bc87f0f95a Mon Sep 17 00:00:00 2001 From: Ben Fulton Date: Wed, 10 Jun 2026 08:56:30 +0100 Subject: [PATCH 5/5] Modernize Python install process --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 045cbf86d7..f3e4972a47 100755 --- a/Makefile.in +++ b/Makefile.in @@ -547,7 +547,7 @@ install: default fltools cp -R schemas $(DESTDIR)$(datadir)/fluidity/ mkdir -p $(DESTDIR)$(datadir)/diamond/schemata $(SED) 's/$${datadir}/$(subst /,\/,$(datadir))/g' schemas/flml.in > $(DESTDIR)$(datadir)/diamond/schemata/flml - cd python ; python3 setup.py install --root=$(shell echo ${DESTDIR} | sed 's/^$$/\//') --prefix="$(prefix)" $$FLUIDITY_PYTHON_INSTALL_ARGS + cd python ; python3 -m pip install --root=$(shell echo ${DESTDIR} | sed 's/^$$/\//') --prefix="$(prefix)" $$FLUIDITY_PYTHON_INSTALL_ARGS . cp -R examples $(DESTDIR)$(docdir)/fluidity find $(DESTDIR)$(docdir)/fluidity/examples -type f -exec $(SED) -i "s/\.\.\/\.\.\/\.\.\/bin\///" '{}' \; find $(DESTDIR)$(docdir)/fluidity/examples -type f -exec $(SED) -i "s/\.\.\/\.\.\/bin\///" '{}' \;