From eaabde6ee9060b886e5a11dc362cee9f48c9b0a7 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Tue, 29 Apr 2025 11:30:27 -0600 Subject: [PATCH] py-netcdf4: enable non-MPI build per variant, even if netcdf-c was built with MPI (#48694) * Add patch for py-netcdf4 so that we can build py-netcdf4 with ~mpi when netCDF was built with +mpi * Address reviewer requests for py-netcdf4. Add conflict for 'pynetcdf4~mpi ^netcdf-c~mpi ^hdf5+mpi' * Make py-netcdf4~mpi ^netcdf-c~mpi ^hdf5+mpi work * Apply suggestions from code review Co-authored-by: Sergey Kosukhin * Update var/spack/repos/builtin/packages/py-netcdf4/disable_parallel_support.patch * Apply suggestions from code review Co-authored-by: Sergey Kosukhin --------- Co-authored-by: Sergey Kosukhin --- .../py-netcdf4/disable_parallel_support.patch | 11 ++++++++ .../builtin/packages/py-netcdf4/package.py | 27 ++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 var/spack/repos/builtin/packages/py-netcdf4/disable_parallel_support.patch diff --git a/var/spack/repos/builtin/packages/py-netcdf4/disable_parallel_support.patch b/var/spack/repos/builtin/packages/py-netcdf4/disable_parallel_support.patch new file mode 100644 index 00000000000..6c547dd3716 --- /dev/null +++ b/var/spack/repos/builtin/packages/py-netcdf4/disable_parallel_support.patch @@ -0,0 +1,11 @@ +--- a/setup.py ++++ b/setup.py +@@ -392,7 +392,7 @@ + (netcdf_lib_version > "4.4" and netcdf_lib_version < "4.5"): + has_cdf5_format = True + +- has_parallel_support = check_has_parallel_support(inc_dirs) ++ has_parallel_support = False + has_has_not = "has" if has_parallel_support else "does not have" + print(f"netcdf lib {has_has_not} parallel functions") + diff --git a/var/spack/repos/builtin/packages/py-netcdf4/package.py b/var/spack/repos/builtin/packages/py-netcdf4/package.py index 3749b3ec139..94eb5e1f083 100644 --- a/var/spack/repos/builtin/packages/py-netcdf4/package.py +++ b/var/spack/repos/builtin/packages/py-netcdf4/package.py @@ -44,12 +44,19 @@ class PyNetcdf4(PythonPackage): # https://github.com/Unidata/netcdf4-python/pull/1317 depends_on("py-numpy@:1", when="@:1.6", type=("build", "link", "run")) depends_on("py-mpi4py", when="+mpi", type=("build", "run")) - # These forced variant requests are due to py-netcdf4 build scripts - # https://github.com/spack/spack/pull/47824#discussion_r1882473998 - depends_on("netcdf-c~mpi", when="~mpi") - depends_on("netcdf-c+mpi", when="+mpi") - depends_on("hdf5@1.8.0:+hl~mpi", when="~mpi") - depends_on("hdf5@1.8.0:+hl+mpi", when="+mpi") + + depends_on("netcdf-c") + depends_on("hdf5") + with when("@:1.6~mpi"): + # These forced variant requests are due to py-netcdf4 build scripts + # https://github.com/spack/spack/pull/47824#discussion_r1882473998 + depends_on("netcdf-c~mpi") + depends_on("hdf5~mpi") + with when("+mpi"): + depends_on("netcdf-c+mpi") + depends_on("hdf5+mpi") + # We cannot build py-netcdf4~mpi ^netcdf-c~mpi ^hdf5+mpi + conflicts("hdf5+mpi", when="~mpi ^netcdf-c~mpi") # The installation script tries to find hdf5 using pkg-config. However, the # version of hdf5 installed with Spack does not have pkg-config files. @@ -58,6 +65,14 @@ class PyNetcdf4(PythonPackage): # following patch disables the usage of pkg-config at all. patch("disable_pkgconf.patch") + # Allow building py-netcdf4 ~mpi when netCDF was build with +mpi. This patch + # overrides the auto-decect feature (has_parallel_support) in setup.py. The + # logic in setup.py changed between 1.6 and 1.7, therefore this patch only + # works for versions 1.7.0 and later. + # See also: https://github.com/Unidata/netcdf4-python/issues/1389 + with when("@1.7:~mpi"): + patch("disable_parallel_support.patch", when="^netcdf-c+mpi") + # https://github.com/Unidata/netcdf4-python/pull/1322 patch( "https://github.com/Unidata/netcdf4-python/commit/49dcd0b5bd25824c254770c0d41445133fc13a46.patch?full_index=1",