Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom build backend for parallel NetCDF4 #1307

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ 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 []
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading