Repository: spack/spack

Issue:
Installation issue: eccodes
### Steps to reproduce the issue

```console
$ spack spec -I eccodes +fortran+netcdf
Input spec
--------------------------------
 -   eccodes+fortran+netcdf

Concretized
--------------------------------
 -   eccodes@2.25.0%gcc@12.2.0~aec+fortran~ipo~memfs+netcdf~openmp~png~pthreads+shared+tools build_system=cmake build_type=Release definitions=auto generator=make jp2k=openjpeg samples=auto arch=linux-almalinux8-icelake
[+]      ^cmake@3.26.3%gcc@12.2.0~doc+ncurses+ownlibs~qt build_system=generic build_type=Release arch=linux-almalinux8-icelake
[+]          ^ncurses@6.4%gcc@12.2.0~symlinks+termlib abi=none build_system=autotools arch=linux-almalinux8-icelake
[+]              ^pkgconf@1.9.5%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]          ^openssl@1.1.1t%gcc@12.2.0~docs~shared build_system=generic certs=mozilla arch=linux-almalinux8-icelake
[+]              ^ca-certificates-mozilla@2023-01-10%gcc@12.2.0 build_system=generic arch=linux-almalinux8-icelake
[+]              ^perl@5.36.0%gcc@12.2.0+cpanm+open+shared+threads build_system=generic arch=linux-almalinux8-icelake
[+]                  ^berkeley-db@18.1.40%gcc@12.2.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-almalinux8-icelake
[+]                  ^gdbm@1.23%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]      ^gmake@4.4.1%gcc@12.2.0~guile build_system=autotools arch=linux-almalinux8-icelake
[+]      ^netcdf-c@4.9.2%gcc@12.2.0+blosc~byterange~dap~fsync~hdf4~jna+mpi~nczarr_zip+optimize~parallel-netcdf+pic+shared+szip+zstd build_system=autotools arch=linux-almalinux8-icelake
[+]          ^bzip2@1.0.8%gcc@12.2.0~debug~pic+shared build_system=generic arch=linux-almalinux8-icelake
[+]              ^diffutils@3.9%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^libiconv@1.17%gcc@12.2.0 build_system=autotools libs=shared,static arch=linux-almalinux8-icelake
[+]          ^c-blosc@1.21.2%gcc@12.2.0+avx2~ipo build_system=cmake build_type=Release generator=make arch=linux-almalinux8-icelake
[+]              ^lz4@1.9.4%gcc@12.2.0 build_system=makefile libs=shared,static arch=linux-almalinux8-icelake
[+]              ^snappy@1.1.10%gcc@12.2.0~ipo+pic+shared build_system=cmake build_type=Release generator=make arch=linux-almalinux8-icelake
[+]          ^hdf5@1.14.1-2%gcc@12.2.0~cxx+fortran+hl~ipo~java~map+mpi+shared~szip~threadsafe+tools api=default build_system=cmake build_type=Release generator=make arch=linux-almalinux8-icelake
[+]          ^libaec@1.0.6%gcc@12.2.0~ipo+shared build_system=cmake build_type=Release generator=make arch=linux-almalinux8-icelake
[+]          ^openmpi@4.1.5%gcc@12.2.0~atomics~cuda~cxx~cxx_exceptions~gpfs~internal-hwloc~java+legacylaunchers~lustre~memchecker~orterunprefix+pmi+romio+rsh~singularity+static+vt+wrapper-rpath build_system=autotools fabrics=ucx schedulers=slurm arch=linux-almalinux8-icelake
[+]              ^hwloc@2.9.1%gcc@12.2.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~oneapi-level-zero~opencl+pci~rocm build_system=autotools libs=shared,static arch=linux-almalinux8-icelake
[+]                  ^libpciaccess@0.17%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                      ^util-macros@1.19.3%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^libxml2@2.10.3%gcc@12.2.0~python build_system=autotools arch=linux-almalinux8-icelake
[+]                      ^xz@5.4.1%gcc@12.2.0~pic build_system=autotools libs=shared,static arch=linux-almalinux8-icelake
[+]              ^numactl@2.0.14%gcc@12.2.0 build_system=autotools patches=4e1d78c,62fc8a8,ff37630 arch=linux-almalinux8-icelake
[+]                  ^autoconf@2.69%gcc@12.2.0 build_system=autotools patches=35c4492,7793209,a49dd5b arch=linux-almalinux8-icelake
[+]                  ^automake@1.16.5%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^libtool@2.4.7%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^m4@1.4.19%gcc@12.2.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-almalinux8-icelake
[+]                      ^libsigsegv@2.14%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]              ^openssh@9.3p1%gcc@12.2.0+gssapi build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^krb5@1.20.1%gcc@12.2.0+shared build_system=autotools arch=linux-almalinux8-icelake
[+]                      ^bison@3.8.2%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                      ^gettext@0.21.1%gcc@12.2.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=linux-almalinux8-icelake
[+]                          ^tar@1.34%gcc@12.2.0 build_system=autotools zip=pigz arch=linux-almalinux8-icelake
[+]                              ^pigz@2.7%gcc@12.2.0 build_system=makefile arch=linux-almalinux8-icelake
[+]                  ^libedit@3.1-20210216%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^libxcrypt@4.4.33%gcc@12.2.0~obsolete_api build_system=autotools arch=linux-almalinux8-icelake
[+]              ^pmix@4.2.3%gcc@12.2.0~docs+pmi_backwards_compatibility~python~restful build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^libevent@2.1.12%gcc@12.2.0+openssl build_system=autotools arch=linux-almalinux8-icelake
[+]              ^slurm@23-02-1-1%gcc@12.2.0~gtk~hdf5~hwloc~mariadb~pmix+readline~restd build_system=autotools sysconfdir=PREFIX/etc arch=linux-almalinux8-icelake
[+]                  ^curl@8.0.1%gcc@12.2.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2~nghttp2 build_system=autotools libs=shared,static tls=openssl arch=linux-almalinux8-icelake
[+]                  ^glib@2.76.1%gcc@12.2.0~libmount build_system=generic patches=fa31180 tracing=none arch=linux-almalinux8-icelake
[+]                      ^elfutils@0.189%gcc@12.2.0~debuginfod+nls build_system=autotools arch=linux-almalinux8-icelake
[+]                      ^libffi@3.4.4%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                      ^meson@1.1.0%gcc@12.2.0 build_system=python_pip patches=0f0b1bd arch=linux-almalinux8-icelake
[+]                          ^py-pip@23.0%gcc@12.2.0 build_system=generic arch=linux-almalinux8-icelake
[+]                          ^py-setuptools@67.6.0%gcc@12.2.0 build_system=generic arch=linux-almalinux8-icelake
[+]                          ^py-wheel@0.37.1%gcc@12.2.0 build_system=generic arch=linux-almalinux8-icelake
[+]                      ^ninja@1.11.1%gcc@12.2.0+re2c build_system=generic arch=linux-almalinux8-icelake
[+]                          ^re2c@2.2%gcc@12.2.0 build_system=generic arch=linux-almalinux8-icelake
[+]                      ^pcre2@10.42%gcc@12.2.0~jit+multibyte build_system=autotools arch=linux-almalinux8-icelake
[+]                      ^python@3.10.10%gcc@12.2.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=0d98e93,7d40923,f2fd060 arch=linux-almalinux8-icelake
[+]                          ^expat@2.5.0%gcc@12.2.0+libbsd build_system=autotools arch=linux-almalinux8-icelake
[+]                              ^libbsd@0.11.7%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                                  ^libmd@1.0.4%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                          ^sqlite@3.40.1%gcc@12.2.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=linux-almalinux8-icelake
[+]                          ^util-linux-uuid@2.38.1%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^json-c@0.16%gcc@12.2.0~ipo build_system=cmake build_type=Release generator=make arch=linux-almalinux8-icelake
[+]                  ^munge@0.5.15%gcc@12.2.0 build_system=autotools localstatedir=PREFIX/var arch=linux-almalinux8-icelake
[+]                      ^libgcrypt@1.10.2%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                          ^libgpg-error@1.47%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                              ^gawk@5.2.1%gcc@12.2.0~nls build_system=autotools arch=linux-almalinux8-icelake
[+]                                  ^gmp@6.2.1%gcc@12.2.0+cxx build_system=autotools libs=shared,static patches=69ad2e2 arch=linux-almalinux8-icelake
[+]                                  ^mpfr@4.2.0%gcc@12.2.0 build_system=autotools libs=shared,static arch=linux-almalinux8-icelake
[+]                                      ^autoconf-archive@2023.02.20%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                                      ^texinfo@7.0.3%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                  ^readline@8.2%gcc@12.2.0 build_system=autotools patches=bbf97f1 arch=linux-almalinux8-icelake
[+]              ^ucx@1.14.0%gcc@12.2.0~assertions~backtrace_detail+cma~cuda~dc~debug~dm+examples~gdrcopy~gtest~ib_hw_tm~java~knem~logging+mlx5_dv+openmp+optimizations~parameter_checking+pic~rc+rdmacm~rocm+thread_multiple~ucg~ud+verbs~vfs~xpmem build_system=autotools libs=shared,static opt=3 simd=auto arch=linux-almalinux8-icelake
[+]                  ^rdma-core@41.0%gcc@12.2.0~ipo+static build_system=cmake build_type=Release generator=make arch=linux-almalinux8-icelake
[+]                      ^libnl@3.3.0%gcc@12.2.0 build_system=autotools arch=linux-almalinux8-icelake
[+]                          ^flex@2.6.3%gcc@12.2.0+lex~nls build_system=autotools arch=linux-almalinux8-icelake
[+]                              ^findutils@4.9.0%gcc@12.2.0 build_system=autotools patches=440b954 arch=linux-almalinux8-icelake
[+]                      ^py-docutils@0.19%gcc@12.2.0 build_system=python_pip arch=linux-almalinux8-icelake
[+]          ^zlib@1.2.13%gcc@12.2.0+optimize+pic+shared build_system=makefile arch=linux-almalinux8-icelake
[+]          ^zstd@1.5.5%gcc@12.2.0+programs build_system=makefile compression=none libs=shared,static arch=linux-almalinux8-icelake
[+]      ^openjpeg@1.5.2%gcc@12.2.0~codec~ipo build_system=cmake build_type=Release generator=make arch=linux-almalinux8-icelake
```


### Error message

<details><summary>Error message</summary>

<pre>
==> eccodes: Executing phase: 'cmake'                   
==> Error: NameError: name 'python' is not defined 
                                                             
/apps/local/spack/cache/repos/builtin/packages/eccodes/package.py:356, in cmake_args:
        353            args.append(self.define("AEC_DIR", self.spec["libaec"].prefix))
        354                                                  
        355        if "^python" in self.spec:   
  >>    356            args.append(self.define("PYTHON_EXECUTABLE", python.path))
        357                                                  
        358        definitions = self.spec.variants["definitions"].value
        359

See build log for details:
  /tmp/root/spack-stage/spack-stage-eccodes-2.25.0-4gdqdqvsdnydzrjsnhalgdwgw4mf6o3h/spack-build-out.txt
</pre></details>


### Information on your system

* **Spack:** 0.21.0.dev0 (4c2531d5fbc2022dd144d1c59dd6faa7ce2c9607)
* **Python:** 3.10.10
* **Platform:** linux-almalinux8-icelake
* **Concretizer:** clingo

### Additional information

@skosukhin
[spack-build-env.txt](https://github.com/spack/spack/files/12036036/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/12036052/spack-build-out.txt)


### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/eccodes/package.py b/var/spack/repos/builtin/packages/eccodes/package.py
--- a/var/spack/repos/builtin/packages/eccodes/package.py
+++ b/var/spack/repos/builtin/packages/eccodes/package.py
@@ -321,6 +321,9 @@ def cmake_args(self):
             self.define_from_variant("ENABLE_ECCODES_THREADS", "pthreads"),
             self.define_from_variant("ENABLE_ECCODES_OMP_THREADS", "openmp"),
             self.define_from_variant("ENABLE_MEMFS", "memfs"),
+            self.define(
+                "ENABLE_PYTHON{0}".format("2" if self.spec.satisfies("@2.20.0:") else ""), False
+            ),
             self.define_from_variant("ENABLE_FORTRAN", "fortran"),
             self.define("BUILD_SHARED_LIBS", "BOTH" if "+shared" in self.spec else "OFF"),
             self.define("ENABLE_TESTS", self.run_tests),
@@ -332,15 +335,14 @@ def cmake_args(self):
         ]
 
         if "+netcdf" in self.spec:
-            args.extend(
-                [
-                    # Prevent possible overriding by environment variables
-                    # NETCDF_ROOT, NETCDF_DIR, and NETCDF_PATH:
-                    self.define("NETCDF_PATH", self.spec["netcdf-c"].prefix),
-                    # Prevent overriding by environment variable HDF5_ROOT:
-                    self.define("HDF5_ROOT", self.spec["hdf5"].prefix),
-                ]
-            )
+            # Prevent possible overriding by environment variables NETCDF_ROOT, NETCDF_DIR, and
+            # NETCDF_PATH:
+            args.append(self.define("NETCDF_PATH", self.spec["netcdf-c"].prefix))
+            # Prevent overriding by environment variable HDF5_ROOT (starting version 2.14.0,
+            # ecCodes is shipped with ecBuild 3.1.0+, which does not seem to rely on the HDF5_ROOT
+            # variable):
+            if self.spec.satisfies("@:2.13"):
+                args.append(self.define("HDF5_ROOT", self.spec["hdf5"].prefix))
 
         if jp2k == "openjpeg":
             args.append(self.define("OPENJPEG_PATH", self.spec["openjpeg"].prefix))
@@ -352,7 +354,7 @@ def cmake_args(self):
             # Prevent overriding by environment variables AEC_DIR and AEC_PATH:
             args.append(self.define("AEC_DIR", self.spec["libaec"].prefix))
 
-        if "^python" in self.spec:
+        if "+memfs" in self.spec:
             args.append(self.define("PYTHON_EXECUTABLE", python.path))
 
         definitions = self.spec.variants["definitions"].value


Test patch: