From 0744c89bb06489b17f1ed190eb26eed435268da9 Mon Sep 17 00:00:00 2001 From: stubbiali Date: Tue, 9 Jan 2024 15:11:50 +0100 Subject: [PATCH] Add in-tree build backend. --- MANIFEST.in | 1 + _build/backend.py | 25 +++++++++++++++++++++++++ pyproject.toml | 5 +++-- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 _build/backend.py diff --git a/MANIFEST.in b/MANIFEST.in index e3497466e..545dec44b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -22,3 +22,4 @@ include *.py include *.release include *.sh include LICENSE +include _build/*.py diff --git a/_build/backend.py b/_build/backend.py new file mode 100644 index 000000000..cefffa925 --- /dev/null +++ b/_build/backend.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +import os +from setuptools.build_meta import * +import subprocess + + +def netcdf_has_parallel_support(): + netcdf4_dir = os.environ.get("NETCDF4_DIR") + ncconfig = os.path.join(netcdf4_dir, "bin", "nc-config") if netcdf4_dir else "nc-config" + process = subprocess.run([ncconfig, "--has-parallel4"], capture_output=True) + out = process.stdout.decode("utf-8").rstrip() + return out == "yes" + + +def get_requires_for_build_editable(config_settings=None): + return ["mpi4py>=3.1"] if netcdf_has_parallel_support() else [] + + +def get_requires_for_build_wheel(config_settings=None): + return ["mpi4py>=3.1"] if netcdf_has_parallel_support() else [] + + +def get_requires_for_build_sdist(config_settings=None): + return ["mpi4py>=3.1"] if netcdf_has_parallel_support() else [] + diff --git a/pyproject.toml b/pyproject.toml index cb3d98717..f0467a670 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,12 @@ [build-system] requires = [ "Cython>=0.29", - "mpi4py>=3.1", "oldest-supported-numpy", "setuptools>=61", + "wheel" ] -build-backend = "setuptools.build_meta" +build-backend = "backend" +backend-path = ["_build"] [project] name = "netCDF4"