Skip to content
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ include *.md
include *.py
include *.release
include *.sh
include LICENSE
include _build/*.py
36 changes: 36 additions & 0 deletions _build/backend.py
Original file line number Diff line number Diff line change
@@ -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 []
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ requires = [
"setuptools>=77.0.1",
"setuptools_scm[toml]>=3.4",
]
build-backend = "setuptools.build_meta"
build-backend = "backend"
backend-path = ["_build"]

[project]
name = "netCDF4"
Expand Down Expand Up @@ -139,6 +140,7 @@ environment = {MACOSX_DEPLOYMENT_TARGET="14.0"}

[tool.cibuildwheel.windows]
before-build = "python -m pip install delvewheel"
environment = "PATH=$PATH:$CONDA_PREFIX/bin"
repair-wheel-command = [
"delvewheel show {wheel}",
"delvewheel repair -w {dest_dir} {wheel}",
Expand Down
Loading