From 92611c50bc26b1c5e01b2ab8479ff855391e9851 Mon Sep 17 00:00:00 2001 From: "Garth N. Wells" Date: Mon, 30 Oct 2023 10:00:29 +0000 Subject: [PATCH 1/4] Improve comment (#2839) --- cpp/dolfinx/fem/utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/dolfinx/fem/utils.h b/cpp/dolfinx/fem/utils.h index 70ef91aceec..54b0ae5c2b8 100644 --- a/cpp/dolfinx/fem/utils.h +++ b/cpp/dolfinx/fem/utils.h @@ -1195,8 +1195,8 @@ pack_coefficients(const Expression& e, return {std::move(c), cstride}; } -/// @brief Pack constants of u of generic type U ready for assembly -/// @warning This function is subject to change +/// @brief Pack constants of u into a sigle array ready for assembly. +/// @warning This function is subject to change. template std::vector pack_constants(const U& u) { From 92108620082cdd615ca1555f6a6e8b7e47fd03c8 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Mon, 30 Oct 2023 10:29:36 +0000 Subject: [PATCH 2/4] Use `pyproject.toml` for install of Python part (#2707) * Try using pyproject * fixup pip command * Find python * debug * Try by adding path explicitly * Try no build isolation on mac. * Try this on macos. * Update CI * Typo * Fix. * Should be dependency of scikit-build-core. * Attempt fix for ubuntu. * Fix? * Add pyproject variant * Typo. * Explicit python intepreter. * Try forcing x86-64 arch. * Try this ordering. * Upgrade pip etc. * And on mac. * This works locally on my macOS system. pip install --no-build-isolation is required. * Works locally, not totally happy with the RPATH stuff. * Tidy. * Fix circleci * Tidy. * Update minimum pybind11. * Don't think these belong here. * Change email. * Tweaks to Dockerfiles and workflows. * Update macos workflow * Typo * Fix. * Get cmake to set rpath automatically. * Don't understand why but doesn't run on circleci, try this. * Typo * Tweak. * Update macos.yml * Try removing. * Exclude .cpp files as suggested. * Add --check-build-dependencies * Not necessary, think this is well known now. * Fix typo no install. * Update build-requirements.txt * Update pyproject.toml --------- Co-authored-by: Jack S. Hale Co-authored-by: Garth N. Wells --- .circleci/config.yml | 11 +++-- .github/workflows/ccpp.yml | 12 ++--- .github/workflows/macos.yml | 23 +++++----- .github/workflows/oneapi.yml | 12 +++-- .github/workflows/redhat.yml | 8 +++- docker/Dockerfile.end-user | 4 +- docker/Dockerfile.oneapi | 2 +- docker/Dockerfile.redhat | 2 +- docker/Dockerfile.test-env | 4 +- python/.flake8 | 3 ++ python/CMakeLists.txt | 36 ++++++--------- python/README.rst | 31 ++++--------- python/build-requirements.txt | 4 ++ python/demo/conftest.py | 2 +- python/pyproject.toml | 48 +++++++++++++++++++ python/setup.cfg | 21 --------- python/setup.py | 86 ----------------------------------- 17 files changed, 124 insertions(+), 185 deletions(-) create mode 100644 python/.flake8 create mode 100644 python/build-requirements.txt create mode 100644 python/pyproject.toml delete mode 100644 python/setup.cfg delete mode 100644 python/setup.py diff --git a/.circleci/config.yml b/.circleci/config.yml index cda66cd03ca..7018c4f3406 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,7 +55,8 @@ build-python-interface: &build-python-interface command: | export CMAKE_BUILD_PARALLEL_LEVEL=2 cd python - pip3 -v install --global-option build --global-option --debug . --user + pip3 install -r build-requirements.txt + pip3 -v install --config-setting cmake.build-type=Debug --no-build-isolation --user . demos-python: &demos-python name: Run demos (Python, serial) @@ -80,14 +81,14 @@ unit-tests-python: &unit-tests-python name: Run unit tests (Python, serial) command: | mkdir -p ~/junit - cd python/test/unit - python3 -m pytest -n=4 --durations=50 --junitxml=~/junit/test-results.xml . + cd python/test + python3 -m pytest -n=4 --durations=50 --junitxml=~/junit/test-results.xml unit/ unit-tests-python-mpi: &unit-tests-python-mpi name: Run unit tests (Python, MPI) command: | - cd python/test/unit - mpirun -np 3 python3 -m pytest . + cd python/test + mpirun -np 3 python3 -m pytest unit/ jobs: build-real: diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 6a23810bfc1..c42eb6554b8 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -65,8 +65,6 @@ jobs: python3 -m pip install git+https://github.com/FEniCS/basix.git@${{ github.event.inputs.basix_ref }} python3 -m pip install git+https://github.com/FEniCS/ffcx.git@${{ github.event.inputs.ffcx_ref }} - - name: Install matplotlib - run: pip3 install matplotlib - name: Flake8 checks run: | cd python/ @@ -80,7 +78,7 @@ jobs: python3 -m isort --check . - name: mypy checks run: | - python3 -m pip install types-setuptools mypy --upgrade + python3 -m pip install mypy types-setuptools --upgrade # TO REMOVE cd python/ mypy dolfinx mypy demo @@ -112,7 +110,7 @@ jobs: - name: Build C++ interface documentation run: | - python3 -m pip install breathe + python3 -m pip install breathe # TO REMOVE export DOLFINX_VERSION=`cmake -L build | grep DOXYGEN_DOLFINX_VERSION | cut -f2 -d "="` echo $DOLFINX_VERSION cd cpp/doc @@ -140,10 +138,12 @@ jobs: ctest -V -R demo -R mpi_2 - name: Build Python interface - run: CMAKE_BUILD_TYPE=Debug python3 -m pip -v install python/ + run: | + python3 -m pip install -r python/build-requirements.txt # TO REMOVE + python3 -m pip -v install --check-build-dependencies --no-build-isolation python/ - name: Build Python interface documentation run: | - python3 -m pip install sphinx==5.0.2 + python3 -m pip install sphinx==5.0.2 # TO REMOVE cd python/doc make html diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index dc7250399bf..0e391ff08c6 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -28,32 +28,31 @@ jobs: - name: Install Python dependencies run: | - pip install pip --upgrade - pip install numpy setuptools wheel - pip install cython - pip install mpi4py + python -m pip install --upgrade pip setuptools wheel + python -m pip install cython numpy mpi4py - - name: Install minimal PETSc and petsc4y + - name: Install minimal PETSc and petsc4py run: | export PATH="$(brew --prefix bison)/bin:$PATH" git clone -b release https://gitlab.com/petsc/petsc.git petsc cd petsc - ./configure \ + python ./configure \ --with-64-bit-indices=no \ --with-debugging=no \ --with-fortran-bindings=no \ --with-scalar-type=real \ --with-shared-libraries \ --with-scalar-type=real \ - -–with-petsc4py=yes \ --download-ptscotch make all + cd src/binding/petsc4py + PETSC_DIR=$GITHUB_WORKSPACE/petsc PETSC_ARCH=arch-darwin-c-opt arch -x86_64 python -m pip install --no-cache-dir -v . - name: Install FEniCSx dependencies run: | - pip install git+https://github.com/FEniCS/basix.git - pip install git+https://github.com/FEniCS/ufl.git - pip install git+https://github.com/FEniCS/ffcx.git + python -m pip install git+https://github.com/FEniCS/basix.git + python -m pip install git+https://github.com/FEniCS/ufl.git + python -m pip install git+https://github.com/FEniCS/ffcx.git - uses: actions/checkout@v4 with: @@ -69,8 +68,8 @@ jobs: env: PYTHONPATH: ${{ github.workspace }}/petsc/${{ env.PETSC_ARCH }}/lib:${{ env.PYTHONPATH }} run: | - echo "Path: ${PYTHONPATH}" - pip install dolfinx/python/ + python -m pip install -r dolfinx/python/build-requirements.txt + python -m pip install --check-build-dependencies --no-build-isolation dolfinx/python/ - name: Basic test env: PYTHONPATH: ${{ github.workspace }}/petsc/${{ env.PETSC_ARCH }}/lib:${{ env.PYTHONPATH }} diff --git a/.github/workflows/oneapi.yml b/.github/workflows/oneapi.yml index 25d0d64a342..772c27cb99e 100644 --- a/.github/workflows/oneapi.yml +++ b/.github/workflows/oneapi.yml @@ -87,7 +87,8 @@ jobs: - name: Build DOLFINx Python interface run: | . /opt/intel/oneapi/setvars.sh - pip -v install python/ + pip -v install -r python/build-requirements.txt # TO REMOVE + pip -v install --check-build-dependencies --no-build-isolation python/ - name: Set default DOLFINx JIT options run: | mkdir -p ~/.config/dolfinx @@ -95,7 +96,7 @@ jobs: - name: Run DOLFINx demos (Python, serial) run: | . /opt/intel/oneapi/setvars.sh - pip install matplotlib + pip install matplotlib # TO REMOVE pytest -v -n=2 -m serial --durations=10 python/demo/test.py - name: Run DOLFINx demos (Python, MPI (np=2)) run: | @@ -104,9 +105,10 @@ jobs: - name: Run DOLFINx Python unit tests (serial) run: | . /opt/intel/oneapi/setvars.sh - pytest -n=auto --durations=50 python/test/unit/ + cd python/test + pytest -n=auto --durations=50 unit/ - name: Run DOLFINx Python unit tests (MPI, np=2) run: | . /opt/intel/oneapi/setvars.sh - cd python/test/unit - mpiexec -n 2 pytest -vs . + cd python/test + mpiexec -n 2 pytest -vs unit/ diff --git a/.github/workflows/redhat.yml b/.github/workflows/redhat.yml index 6b65c6e836e..c454aea6bf5 100644 --- a/.github/workflows/redhat.yml +++ b/.github/workflows/redhat.yml @@ -23,6 +23,10 @@ jobs: steps: - uses: actions/checkout@v4 + + - name: Upgrade pip and setuptools + run: | + python3 -m pip install --upgrade pip setuptools wheel - name: Install FEniCS Python components run: | @@ -59,7 +63,9 @@ jobs: ctest -V -R demo -R mpi_2 - name: Build Python interface - run: python3 -m pip -v install --global-option build --global-option --debug python/ + run: | + python3 -m pip -v install -r python/build-requirements.txt # TO REMOVE + python3 -m pip -v install --check-build-dependencies --no-build-isolation --config-settings=cmake.build-type=Debug python/ - name: Set default DOLFINx JIT options run: | diff --git a/docker/Dockerfile.end-user b/docker/Dockerfile.end-user index bdd088411a2..290a123b424 100644 --- a/docker/Dockerfile.end-user +++ b/docker/Dockerfile.end-user @@ -90,7 +90,7 @@ ONBUILD RUN cd dolfinx && \ PETSC_ARCH=linux-gnu-real64-32 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local/dolfinx-real -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -DCMAKE_CXX_FLAGS=${DOLFINX_CMAKE_CXX_FLAGS} ../cpp && \ ninja install && \ cd ../python && \ - CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-real64-32 pip3 install -v --target /usr/local/dolfinx-real/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir . && \ + CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-real64-32 pip3 install -v --no-build-isolation --target /usr/local/dolfinx-real/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir . && \ git clean -fdx && \ cd ../ && \ mkdir -p build-complex && \ @@ -99,7 +99,7 @@ ONBUILD RUN cd dolfinx && \ ninja install && \ . /usr/local/dolfinx-complex/lib/dolfinx/dolfinx.conf && \ cd ../python && \ - CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-complex128-32 pip3 install -v --target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir . + CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-complex128-32 pip3 install -v --no-build-isolation --target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir . # Real by default. ONBUILD ENV PKG_CONFIG_PATH=/usr/local/dolfinx-real/lib/pkgconfig:$PKG_CONFIG_PATH \ diff --git a/docker/Dockerfile.oneapi b/docker/Dockerfile.oneapi index f20eb513a4c..21cfd3d512d 100644 --- a/docker/Dockerfile.oneapi +++ b/docker/Dockerfile.oneapi @@ -58,7 +58,7 @@ ENV CC=icx \ # Install Python packages (via pip) RUN . /opt/intel/oneapi/setvars.sh && \ - pip install --no-cache-dir cppimport mpi4py pybind11==${PYBIND11_VERSION} pytest pytest-xdist + pip install --no-cache-dir cppimport matplotlib mpi4py pybind11==${PYBIND11_VERSION} pytest pytest-xdist scikit-build-core[pyproject] # Install KaHIP RUN . /opt/intel/oneapi/setvars.sh && \ diff --git a/docker/Dockerfile.redhat b/docker/Dockerfile.redhat index 5ed19666a89..b9f5a04bead 100644 --- a/docker/Dockerfile.redhat +++ b/docker/Dockerfile.redhat @@ -63,7 +63,7 @@ RUN curl -L -O https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-${HDF5_SERIES # First set of dependencies for building and running Python DOLFINx # Second set of dependencies for running DOLFINx tests -RUN python3 -m pip install --no-cache-dir cffi numba mpi4py pybind11 wheel && \ +RUN python3 -m pip install --no-cache-dir cffi numba mpi4py pybind11 scikit-build-core[pyproject] wheel && \ python3 -m pip install --no-cache-dir cppimport pytest pytest-xdist scipy matplotlib # Build PETSc diff --git a/docker/Dockerfile.test-env b/docker/Dockerfile.test-env index 6b560f3f385..6f2e770bdce 100644 --- a/docker/Dockerfile.test-env +++ b/docker/Dockerfile.test-env @@ -153,8 +153,8 @@ RUN if [ "$MPI" = "mpich" ]; then \ # - Second set of packages are recommended and/or required to build # documentation or run tests. RUN pip3 install --no-cache-dir --upgrade setuptools pip && \ - pip3 install --no-cache-dir cffi mpi4py numba numpy==${NUMPY_VERSION} scipy && \ - pip3 install --no-cache-dir clang-format cppimport cmakelang flake8 isort jupytext matplotlib mypy myst-parser pybind11==${PYBIND11_VERSION} pytest pytest-xdist sphinx sphinx_rtd_theme + pip3 install -no-cache-dir cffi mpi4py numba numpy==${NUMPY_VERSION} scikit-build-core[pyproject] && \ + pip3 install --no-cache-dir breath clang-format cppimport cmakelang flake8 isort jupytext matplotlib mypy myst-parser pybind11==${PYBIND11_VERSION} pytest pytest-xdist scipy sphinx==5.0.2 sphinx_rtd_theme types-setuptools # Install KaHIP RUN wget -nc --quiet https://github.com/kahip/kahip/archive/v${KAHIP_VERSION}.tar.gz && \ diff --git a/python/.flake8 b/python/.flake8 new file mode 100644 index 00000000000..91b7e39c592 --- /dev/null +++ b/python/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 120 +ignore = W503 diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index fdf9b6018f5..c03faba2736 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,32 +1,21 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.18) -project(dolfinx_pybind11) +project(fenics-dolfinx) # Set C++ standard before finding pybind11 set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -# Development component which includes both Development.Module and -# Development.Embed is not required for building a Python module. Correct -# COMPONENT specification Development.Module added only in CMake 3.18 and above. -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.18.0") - find_package( - Python3 - COMPONENTS Interpreter Development.Module - REQUIRED - ) -else() - find_package( - Python3 - COMPONENTS Interpreter Development - REQUIRED - ) -endif() +find_package( + Python3 + COMPONENTS Interpreter Development.Module + REQUIRED +) find_package( pybind11 - 2.7.0 + 2.9.1 REQUIRED CONFIG HINTS @@ -38,11 +27,12 @@ find_package( execute_process( COMMAND - ${Python3_EXECUTABLE} -c "import basix, os, sys; sys.stdout.write(os.path.dirname(basix.__file__))" + ${Python3_EXECUTABLE} -c "import os, sys, basix; sys.stdout.write(os.path.dirname(basix.__file__))" OUTPUT_VARIABLE BASIX_PY_DIR RESULT_VARIABLE BASIX_PY_COMMAND_RESULT - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE BASIX_ERROR_OUT OUTPUT_STRIP_TRAILING_WHITESPACE ) + find_package(Basix REQUIRED CONFIG HINTS ${BASIX_PY_DIR}) find_package(DOLFINX REQUIRED CONFIG) @@ -114,3 +104,7 @@ if(NOT MPI4PY_COMMAND_RESULT) else() message(FATAL_ERROR "mpi4py could not be found.") endif() + +set_target_properties(cpp PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) + +install(TARGETS cpp DESTINATION dolfinx) diff --git a/python/README.rst b/python/README.rst index d6b829d4e4b..db76a94bbf2 100644 --- a/python/README.rst +++ b/python/README.rst @@ -1,32 +1,21 @@ DOLFINx Python interface ======================== -Building the DOLFINx Python interface uses pybind11. +This document explains how to install the DOLFINx Python interface. Note that +this interface must be built without PEP517 build isolation by passing +`--no-build-isolation` flag to `pip install`. This is because the Python +interface explicitly depends on the system built petsc4py and mpi4py. -1. Install pybdind11 version 2.2.1 or later. Use CMake to install - pybind11, e.g.:: +1. Build and install the DOLFINx C++ library in the usual way. - wget -nc --quiet https://github.com/pybind/pybind11/archive/v2.2.1.tar.gz - tar -xf v2.2.1.tar.gz - cd pybind11-2.2.1 - mkdir build-dir - cd build-dir - cmake -DPYBIND11_TEST=off -DCMAKE_INSTALL_PREFIX=/path/to/pybind11/install .. - make install +2. Ensure the build time requirements are installed:: - The FEniCS Docker images are configured with pybind11. - -2. Build and install the DOLFINx C++ library in the usual way. + pip install -v -r build-requirements.txt 3. Build DOLFINx Python interface:: - export PYBIND11_DIR=/path/to/pybind11/install - pip3 -v install . --user - -To install in a local build directory:: - - python3 setup.py build + pip -v install --check-build-dependencies --no-build-isolation . -and set the ``PYTHONPATH``. To build in debug mode:: + To build in debug and editable mode for development:: - python3 setup.py build --debug + pip -v install --check-build-dependencies --config-settings=build-dir="build" --config-settings=cmake.build-type="Debug" --no-build-isolation -e . diff --git a/python/build-requirements.txt b/python/build-requirements.txt new file mode 100644 index 00000000000..3c0a50244ae --- /dev/null +++ b/python/build-requirements.txt @@ -0,0 +1,4 @@ +pybind11>=2.9.1 +scikit-build-core[pyproject] +petsc4py +mpi4py diff --git a/python/demo/conftest.py b/python/demo/conftest.py index 66dbb04d0a4..da9450b3306 100644 --- a/python/demo/conftest.py +++ b/python/demo/conftest.py @@ -3,7 +3,7 @@ def pytest_addoption(parser): parser.addoption("--mpiexec", action="store", default="mpirun", - help="Name of program to run MPI, e.g. mpiexex") + help="Name of program to run MPI, e.g. mpiexec") parser.addoption("--num-proc", action="store", default=1, help="Number of MPI processes to use") diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 00000000000..6eccc429e53 --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,48 @@ +# The DOLFINx Python interface must be built without build isolation (PEP517) +# due to its runtime and build time dependency on system built petsc4py and +# mpi4py. +# pip install -r build-requirements.txt +[build-system] +requires = ["scikit-build-core[pyproject]", "pybind11>=2.9.1", "petsc4py", "mpi4py"] +build-backend = "scikit_build_core.build" + +[project] +name = "fenics-dolfinx" +version = "0.8.0.dev0" +description = "DOLFINx Python interface" +readme = "../README.md" +requires-python = ">=3.8.0" +license = {file = "../COPYING"} +authors = [{email="fenics-steering-council@googlegroups.com"}, {name="FEniCS Steering Council"}] +packages = ["dolfinx"] +dependencies = ["numpy>=1.21", "cffi", "petsc4py", "mpi4py", + "fenics-ffcx>=0.8.0.dev0,<0.9.0", + "fenics-ufl>=2023.3.0.dev0,<2023.4.0"] + +[project.optional-dependencies] +docs = ["markdown", "pylit3", "pyyaml", "sphinx==5.0.2", "sphinx_rtd_theme"] +lint = ["flake8", "pydocstyle"] +optional = ["numba"] +test = ["pytest", "sympy", "scipy", "matplotlib", "fenics-dolfinx[optional]"] +ci = ["mypy", "pytest-xdist", "types-setuptools", "fenics-dolfinx[build]", + "fenics-dolfinx[docs]", "fenics-dolfinx[lint]", "fenics-dolfinx[optional]", + "fenics-dolfinx[test]"] + +[tool.scikit-build] +wheel.packages = ["dolfinx"] +sdist.exclude = ["*.cpp"] + +[tool.pytest] +junit_family = "xunit2" + +[tool.mypy] +# Suggested at https://blog.wolt.com/engineering/2021/09/30/professional-grade-mypy-configuration/ +# Goal would be to make all of the below True long-term +disallow_untyped_defs = false +disallow_any_unimported = false +no_implicit_optional = false +check_untyped_defs = false +warn_return_any = false +warn_unused_ignores = false +show_error_codes = true +ignore_missing_imports = true diff --git a/python/setup.cfg b/python/setup.cfg deleted file mode 100644 index dc75aeb54de..00000000000 --- a/python/setup.cfg +++ /dev/null @@ -1,21 +0,0 @@ -[flake8] -max-line-length = 120 -ignore = W503 - -[tool:pytest] -junit_family = xunit2 - -[pycodestyle] -max_line_length = 120 - -[mypy] -# Suggested at https://blog.wolt.com/engineering/2021/09/30/professional-grade-mypy-configuration/ -# Goal would be to make all of the below True long-term -disallow_untyped_defs = False -disallow_any_unimported = False -no_implicit_optional = False -check_untyped_defs = False -warn_return_any = False -warn_unused_ignores = False -show_error_codes = True -ignore_missing_imports = True diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index 1ca8ccb8dd9..00000000000 --- a/python/setup.py +++ /dev/null @@ -1,86 +0,0 @@ -import os -import shlex -import subprocess -import sys -import sysconfig - -from setuptools import Extension, setup -from setuptools.command.build_ext import build_ext - -if sys.version_info < (3, 8): - print("Python 3.8 or higher required, please upgrade.") - sys.exit(1) - -VERSION = "0.8.0.dev0" - -REQUIREMENTS = [ - "cffi", - "numpy>=1.21", - "mpi4py", - "petsc4py", - "fenics-ffcx>=0.8.0.dev0,<0.9.0", - "fenics-ufl>=2023.3.0.dev0,<2023.4.0" -] - - -class CMakeExtension(Extension): - def __init__(self, name, sourcedir=''): - Extension.__init__(self, name, sources=[]) - self.sourcedir = os.path.abspath(sourcedir) - - -class CMakeBuild(build_ext): - def run(self): - try: - _ = subprocess.check_output(['cmake', '--version']) - except OSError: - raise RuntimeError("CMake must be installed to build the following extensions: " - + ", ".join(e.name for e in self.extensions)) - - for ext in self.extensions: - self.build_extension(ext) - - def build_extension(self, ext): - extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) - cmake_args = shlex.split(os.environ.get("CMAKE_ARGS", "")) - cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, - '-DPython3_EXECUTABLE=' + sys.executable, - f'-DPython3_LIBRARIES={sysconfig.get_config_var("LIBDEST")}', - f'-DPython3_INCLUDE_DIRS={sysconfig.get_config_var("INCLUDEPY")}'] - - env = os.environ.copy() - build_args = [] - if "CMAKE_BUILD_TYPE" not in env: - cfg = 'Debug' if self.debug else 'Release' - build_args += ['--config', cfg] - cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] - - # default to 3 build threads - if "CMAKE_BUILD_PARALLEL_LEVEL" not in env: - env["CMAKE_BUILD_PARALLEL_LEVEL"] = "3" - - import pybind11 - env['pybind11_DIR'] = pybind11.get_cmake_dir() - - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) - subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp, env=env) - - -setup(name='fenics-dolfinx', - version=VERSION, - author='FEniCS Project', - description='DOLFINx Python interface', - long_description='', - packages=["dolfinx", - "dolfinx.fem", - "dolfinx.io", - "dolfinx.nls", - "dolfinx.wrappers"], - package_data={'dolfinx.wrappers': ['*.h'], 'dolfinx': ['py.typed']}, - ext_modules=[CMakeExtension('dolfinx.cpp')], - cmdclass=dict(build_ext=CMakeBuild), - install_requires=REQUIREMENTS, - setup_requires=["pybind11"], - zip_safe=False) From bdf892ca57e33f7e69c8a80648edb07ba585bf65 Mon Sep 17 00:00:00 2001 From: "Garth N. Wells" Date: Mon, 30 Oct 2023 15:11:03 +0000 Subject: [PATCH 3/4] Update config --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 6eccc429e53..9cf7b1a29a6 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -3,7 +3,7 @@ # mpi4py. # pip install -r build-requirements.txt [build-system] -requires = ["scikit-build-core[pyproject]", "pybind11>=2.9.1", "petsc4py", "mpi4py"] +requires = ["scikit-build-core[pyproject]", "nanobind>=1.6.0", "petsc4py", "mpi4py"] build-backend = "scikit_build_core.build" [project] From 0ad1dad91d3a3cc43331de56f2b1a5115b4050b8 Mon Sep 17 00:00:00 2001 From: "Garth N. Wells" Date: Mon, 30 Oct 2023 15:24:00 +0000 Subject: [PATCH 4/4] Small updates --- .circleci/config.yml | 2 +- docker/Dockerfile.test-env | 2 +- python/build-requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6752dcf4789..3260fb4aded 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -52,7 +52,7 @@ regression-tests-cpp-mpi: ®ression-tests-cpp-mpi ctest --verbose -R demo -R mpi_3 build-python-interface: &build-python-interface - name: Build Python/pybind11 interface + name: Build Python/nanobind interface command: | export CMAKE_BUILD_PARALLEL_LEVEL=2 cd python diff --git a/docker/Dockerfile.test-env b/docker/Dockerfile.test-env index 2d44c2ff438..d73b5834856 100644 --- a/docker/Dockerfile.test-env +++ b/docker/Dockerfile.test-env @@ -154,7 +154,7 @@ RUN if [ "$MPI" = "mpich" ]; then \ # documentation or run tests. RUN pip3 install --no-cache-dir --upgrade setuptools pip && \ pip3 install -no-cache-dir cffi mpi4py numba numpy==${NUMPY_VERSION} scikit-build-core[pyproject] && \ - pip3 install --no-cache-dir breath clang-format cppimport cmakelang flake8 isort jupytext matplotlib mypy myst-parser nanobind==${PYBIND11_VERSION} pytest pytest-xdist scipy sphinx==5.0.2 sphinx_rtd_theme types-setuptools + pip3 install --no-cache-dir breath clang-format cppimport cmakelang flake8 isort jupytext matplotlib mypy myst-parser nanobind==${NANOBIND_VERSION} pytest pytest-xdist scipy sphinx==5.0.2 sphinx_rtd_theme types-setuptools # Install KaHIP RUN wget -nc --quiet https://github.com/kahip/kahip/archive/v${KAHIP_VERSION}.tar.gz && \ diff --git a/python/build-requirements.txt b/python/build-requirements.txt index 3c0a50244ae..75f16923e57 100644 --- a/python/build-requirements.txt +++ b/python/build-requirements.txt @@ -1,4 +1,4 @@ -pybind11>=2.9.1 +nanobind>=1.7.0 scikit-build-core[pyproject] petsc4py mpi4py