Repository: spack/spack

Issue:
Installation issue: ufs-weather-model@2.0.0 has python build dependency
### Steps to reproduce the issue

```console
$ spack spec -lI ufs-weather-model
Input spec
--------------------------------
 -   ufs-weather-model

Concretized
--------------------------------
 -   t5glllw  ufs-weather-model@2.0.0%gcc@9.4.0+32bit+avx2+ccpp~inline_post+ipo+multi_gases+openmp+parallel_netcdf+quad_precision+simdmultiarch build_type=RelWithDebInfo ccpp_suites=FV3_GFS_v15p2,FV3_RRFS_v1alpha arch=linux-rhel8-zen2
[+]  nudngc4      ^bacio@2.4.1%gcc@9.4.0+ipo build_type=RelWithDebInfo arch=linux-rhel8-zen2
[+]  axyq2vh          ^cmake@3.21.4%gcc@9.4.0~doc+ncurses+ownlibs~qt build_type=Release arch=linux-rhel8-zen2
[+]  3qluxow              ^ncurses@6.2%gcc@9.4.0+symlinks+termlib abi=5 arch=linux-rhel8-zen2
[+]  x6zqidr                  ^pkg-config@0.29.2%gcc@9.4.0+internal_glib arch=linux-rhel8-zen2
[+]  fwls555              ^openssl@1.1.1o%gcc@9.4.0~docs~shared certs=system arch=linux-rhel8-zen2
[+]  tnotv7g                  ^perl@5.34.0%gcc@9.4.0+cpanm+shared+threads arch=linux-rhel8-zen2
[+]  tln7nr2                      ^berkeley-db@18.1.40%gcc@9.4.0+cxx+docs+stl arch=linux-rhel8-zen2
[+]  nm3jdl7                      ^bzip2@1.0.8%gcc@9.4.0~debug+pic+shared arch=linux-rhel8-zen2
[+]  dvhds5a                          ^diffutils@3.8%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  hujtin6                              ^libiconv@1.16%gcc@9.4.0 libs=shared,static arch=linux-rhel8-zen2
[+]  imdanzb                      ^gdbm@1.19%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  tjugnhr                          ^readline@8.1%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  ftmxxsd                      ^zlib@1.2.12%gcc@9.4.0+optimize+pic+shared patches=0d38234 arch=linux-rhel8-zen2
[+]  iwa5bha      ^esmf@8.0.0%gcc@9.4.0~debug+external-lapack+mpi+netcdf+pio+pnetcdf+xerces arch=linux-rhel8-zen2
[+]  oawew7n          ^libxml2@2.9.12%gcc@9.4.0~python arch=linux-rhel8-zen2
[+]  onv26yt              ^xz@5.2.5%gcc@9.4.0+pic libs=shared,static arch=linux-rhel8-zen2
[+]  3vo5ljd          ^netcdf-c@4.8.1%gcc@9.4.0+dap~fsync+hdf4+jna+mpi+parallel-netcdf+pic+shared patches=de556da arch=linux-rhel8-zen2
[+]  z6fmxk5              ^curl@7.78.0%gcc@9.4.0+gssapi~ldap+libidn2~librtmp+libssh+libssh2+nghttp2 libs=shared,static tls=gnutls,mbedtls,openssl arch=linux-rhel8-zen2
[+]  iftjgbf                  ^gnutls@3.6.15%gcc@9.4.0+guile+zlib arch=linux-rhel8-zen2
[+]  kbon7os                      ^gettext@0.21%gcc@9.4.0+bzip2+curses+git+libunistring+libxml2+tar+xz arch=linux-rhel8-zen2
[+]  xjuydbp                          ^libunistring@0.9.10%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  eosattb                          ^tar@1.34%gcc@9.4.0 zip=pigz arch=linux-rhel8-zen2
[+]  ccbedyj                              ^pigz@2.7%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  rihae2k                              ^zstd@1.5.0%gcc@9.4.0+programs compression=lz4,lzma,zlib libs=shared,static arch=linux-rhel8-zen2
[+]  37vfsml                                  ^lz4@1.9.3%gcc@9.4.0 libs=shared,static arch=linux-rhel8-zen2
[+]  i44ot45                      ^guile@2.2.6%gcc@9.4.0+readline threads=posix arch=linux-rhel8-zen2
[+]  i3w4ejv                          ^bdw-gc@8.0.6%gcc@9.4.0+libatomic-ops threads=posix arch=linux-rhel8-zen2
[+]  j2bz423                              ^libatomic-ops@7.6.12%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  d7i35qg                          ^gmp@6.2.1%gcc@9.4.0 libs=shared,static arch=linux-rhel8-zen2
[+]  p552xph                              ^autoconf@2.69%gcc@9.4.0 patches=35c4492,7793209,a49dd5b arch=linux-rhel8-zen2
[+]  3ah2vi7                                  ^m4@1.4.19%gcc@9.4.0+sigsegv patches=9dc5fbd,bfdffa7 arch=linux-rhel8-zen2
[+]  c5iako4                                      ^libsigsegv@2.13%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  wm7sa36                              ^automake@1.16.3%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  5g67po2                              ^libtool@2.4.7%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  6su6nc7                          ^libffi@3.4.2%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  s3jgont                      ^libidn2@2.3.0%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  d32ikss                      ^nettle@3.4.1%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  zlfjzmv                  ^krb5@1.19.2%gcc@9.4.0+shared arch=linux-rhel8-zen2
[+]  i2cmmjh                      ^bison@3.8.2%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  v3c2aub                  ^libssh@0.8.5%gcc@9.4.0+gssapi+ipo build_type=RelWithDebInfo arch=linux-rhel8-zen2
[+]  zn36jin                  ^libssh2@1.10.0%gcc@9.4.0+ipo+shared build_type=RelWithDebInfo crypto=mbedtls arch=linux-rhel8-zen2
[+]  vnl3vin                      ^mbedtls@2.28.0%gcc@9.4.0+pic build_type=Release libs=shared,static arch=linux-rhel8-zen2
[+]  astngov                  ^nghttp2@1.44.0%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  l33aswh              ^hdf@4.2.15%gcc@9.4.0+external-xdr+fortran~java~netcdf+pic~shared+szip patches=49733dd,5434f29,ce75518,d54592d,f7d67e8 arch=linux-rhel8-zen2
[+]  3xantiy                  ^flex@2.6.4%gcc@9.4.0+lex+nls patches=f8b85a0 arch=linux-rhel8-zen2
[+]  fkc3uda                      ^findutils@4.9.0%gcc@9.4.0 patches=440b954 arch=linux-rhel8-zen2
[+]  62y2tjv                      ^help2man@1.47.16%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  mlfqtw4                  ^libjpeg-turbo@2.1.3%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  oh7a7yb                      ^nasm@2.15.05%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  omhlfdr                  ^libszip@2.1.1%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  4eftfjj                  ^libtirpc@1.2.6%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  fjan65e              ^hdf5@1.10.7%gcc@9.4.0+cxx+fortran+hl+ipo+java+mpi+shared+szip+threadsafe+tools api=v110 build_type=RelWithDebInfo patches=2a1e311 arch=linux-rhel8-zen2
[+]  nx3dpg3                  ^openjdk@11.0.12_7%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  hm2fkyf                  ^openmpi@4.1.1%gcc@9.4.0+atomics+cuda+cxx+cxx_exceptions~gpfs~internal-hwloc~java+legacylaunchers~lustre~memchecker+pmi+romio+rsh~singularity+static~vt+wrapper-rpath cuda_arch=35,37,50,52,53,60,61,62,70,72,75,80,86 fabrics=ucx schedulers=slurm arch=linux-rhel8-zen2
[+]  eonihhh                      ^cuda@11.6.2%gcc@9.4.0+allow-unsupported-compilers+dev arch=linux-rhel8-zen2
[+]  n4n56xf                      ^hwloc@2.6.0%gcc@9.4.0~cairo+cuda~gl+libudev+libxml2~netloc~nvml~opencl+pci~rocm+shared arch=linux-rhel8-zen2
[+]  rsypzio                          ^libpciaccess@0.16%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  4n6qp2u                              ^util-macros@1.19.3%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  i3blv6e                      ^numactl@2.0.14%gcc@9.4.0 patches=4e1d78c,62fc8a8,ff37630 arch=linux-rhel8-zen2
[+]  hx4o2eg                      ^openssh@9.0p1%gcc@9.4.0+gssapi arch=linux-rhel8-zen2
[+]  cnyzstp                          ^libedit@3.1-20210216%gcc@9.4.0 arch=linux-rhel8-zen2
[+]  6w7d4hm                      ^pmix@3.2.1%gcc@9.4.0~docs+pmi_backwards_compatibility arch=linux-rhel8-zen2
[+]  xqlb5yi                          ^libevent@2.1.8%gcc@9.4.0+openssl arch=linux-rhel8-zen2
[+]  y4kr5pz                      ^slurm@system%gcc@9.4.0~gtk~hdf5~hwloc~mariadb~pmix+readline~restd sysconfdir=/etc/slurm arch=linux-rhel8-zen2
[+]  r7i3swb                      ^ucx@system%gcc@9.4.0~assertions~backtrace_detail~cm+cma~cuda~dc~debug~dm+examples~gdrcopy~ib_hw_tm~java+knem~logging~mlx5_dv+openmp+optimizations~parameter_checking+pic~rc+rdmacm~rocm+thread_multiple~ucg~ud~verbs+xpmem libs=shared opt=3 simd=auto arch=linux-rhel8-zen2
[+]  dslw2lj              ^parallel-netcdf@1.12.2%gcc@9.4.0~burstbuffer+cxx+fortran+pic+shared arch=linux-rhel8-zen2
[+]  zj24ojt          ^netcdf-fortran@4.5.3%gcc@9.4.0~doc+pic+shared arch=linux-rhel8-zen2
[+]  naq4v5i          ^openblas@0.3.18%gcc@9.4.0~bignuma~consistent_fpcsr~ilp64+locking+pic+shared symbol_suffix=none threads=openmp arch=linux-rhel8-zen2
[+]  qe62elj          ^xerces-c@3.2.3%gcc@9.4.0 cxxstd=17 netaccessor=curl transcoder=iconv arch=linux-rhel8-zen2
[+]  a3n4mhg      ^nemsio@2.5.4%gcc@9.4.0+ipo+mpi build_type=RelWithDebInfo arch=linux-rhel8-zen2
[+]  tikyxvm          ^w3emc@2.9.2%gcc@9.4.0+ipo build_type=RelWithDebInfo arch=linux-rhel8-zen2
[+]  zz4a7j6      ^sp@2.3.3%gcc@9.4.0+ipo build_type=RelWithDebInfo arch=linux-rhel8-zen2
[+]  3imeprc      ^w3nco@2.4.1%gcc@9.4.0+ipo build_type=RelWithDebInfo arch=linux-rhel8-zen2
```


### Error message

The ufs-weather-model package seems to have a python build dependency which is not declared in Spack.  
This is causing it to erroneously use the system python, or fail if system python not found (e.g. on the RHEL8 system I am using where python2 andpython3 commands are installed by system but no generic python command).

This leads to errors:
<details><summary>Error message in spack-built-out.txt</summary>
<pre>
...
Found Python: /bin/python3.6
Calling CCPP code generator (ccpp_prebuild.py) ...
CMake Error at CMakeLists.txt:145 (message):
  An error occured while running ccpp_prebuild.py, check
  /tmp/spackswinst/spack-stage/spack-stage-ufs-weather-model-2.0.0-t5glllwskgknwxtspm7skdoyktaezmrc/spack-build-t5glllw/ccpp_prebuild.{out,err}


-- Configuring incomplete, errors occurred!
...
</details>

<details><summary>Error message in ccpp_prebuild.err</summary>

<pre>
/usr/bin/env: 'python': No such file or directory
</pre></details>


### Information on your system

```console
spack debug report
* **Spack:** 0.19.0.dev0 (0205fefe0c80dc1fe03b9ec5da93bf24b1c9103f)
* **Python:** 3.6.8
* **Platform:** linux-rhel8-zen2
* **Concretizer:** clingo
```

### Additional information

[spack-build-env.txt](https://github.com/spack/spack/files/13689224/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/13689225/spack-build-out.txt)

Maintainer: @t-brown

### 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/ufs-weather-model/package.py b/var/spack/repos/builtin/packages/ufs-weather-model/package.py
--- a/var/spack/repos/builtin/packages/ufs-weather-model/package.py
+++ b/var/spack/repos/builtin/packages/ufs-weather-model/package.py
@@ -68,6 +68,7 @@ class UfsWeatherModel(CMakePackage):
     depends_on("sp")
     depends_on("w3emc")
     depends_on("w3nco")
+    depends_on("python", type="build")
 
     def setup_build_environment(self, env):
         spec = self.spec


Test patch: