diff --git a/MANIFEST.in b/MANIFEST.in index 0eec8242f..a4adca7d1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -26,3 +26,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..bd05c2b3e --- /dev/null +++ b/_build/backend.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import logging +import os +from setuptools.build_meta import * +import subprocess + + +fmt = logging.Formatter("\n=== NETCDF4 BUILD DEBUG: %(message)s\n") +hdlr = logging.StreamHandler() +hdlr.setFormatter(fmt) +log = logging.getLogger(__name__) +log.setLevel(logging.DEBUG) +log.addHandler(hdlr) + + +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" + ) + log.debug(f"{ncconfig = }") + 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 3ec2da2de..4d34cdcd6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,9 +3,12 @@ requires = [ "Cython>=0.29", "oldest-supported-numpy ; python_version < '3.9'", "numpy>=2.0.0rc1 ; python_version >= '3.9'", - "setuptools>=61", "setuptools_scm[toml]>=3.4" + "setuptools>=61", + "setuptools_scm[toml]>=3.4", + "wheel" ] -build-backend = "setuptools.build_meta" +build-backend = "backend" +backend-path = ["_build"] [project] name = "netCDF4"