Repository: spack/spack

Issue:
Spack trying to use a python that it was told to build but never actually built
CC: @fryeguy52 

Tag: snl-atdm-issue

When I upgraded to Spack 0.13.0, if you tell spack to build python but it is not able to actually built it because another package build fails, then spack still tries to use that package (it would appear automatically).

For example, I ran `spack install` which tried to build:

```
==> Concretized snl-atdm-tools arch=linux-rhel6-x86_64
 -   7kjcq22  snl-atdm-tools@snl-atdm-0.1.0%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   jolfhsi      ^autoconf@2.69%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   z4usolp          ^m4@1.4.18%gcc@7.2.0 patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 +sigsegv arch=linux-rhel6-x86_64
 -   ulj5yaz              ^libsigsegv@2.12%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   rvc7wh4          ^perl@5.26.2%gcc@7.2.0+cpanm patches=0eac10ed90aeb0459ad8851f88081d439a4e41978e586ec743069e8b059370ac +shared+threads arch=linux-rhel6-x86_64
 -   7yddwkq              ^gdbm@1.18.1%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   kw32bm5                  ^readline@8.0%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   dqth77n                      ^ncurses@6.1%gcc@7.2.0~symlinks~termlib arch=linux-rhel6-x86_64
 -   qmt4kcm                          ^pkgconf@1.6.3%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   r3sudpm      ^automake@1.16.1%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   dmkkwab      ^cmake@3.15.4%gcc@7.2.0~doc+ncurses+openssl+ownlibs~qt arch=linux-rhel6-x86_64
 -   7e4sofy          ^openssl@1.1.1d%gcc@7.2.0+systemcerts arch=linux-rhel6-x86_64
 -   aqhxxoj              ^zlib@1.2.11%gcc@7.2.0+optimize+pic+shared arch=linux-rhel6-x86_64
 -   izajihb      ^diffutils@3.7%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   yevortw          ^libiconv@1.16%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   ezbbcix      ^git@2.20.1%gcc@7.2.0~tcltk arch=linux-rhel6-x86_64
 -   sbhfryx          ^curl@7.63.0%gcc@7.2.0~darwinssl~gssapi~libssh~libssh2~nghttp2 arch=linux-rhel6-x86_64
 -   z2qfmtc          ^expat@2.2.9%gcc@7.2.0+libbsd arch=linux-rhel6-x86_64
 -   5ncvr6g              ^libbsd@0.9.1%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   zzbkzji          ^gettext@0.20.1%gcc@7.2.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-rhel6-x86_64
 -   zlyhddn              ^bzip2@1.0.8%gcc@7.2.0+shared arch=linux-rhel6-x86_64
 -   p5gcyal              ^libxml2@2.9.9%gcc@7.2.0~python arch=linux-rhel6-x86_64
 -   4mfrw3e                  ^xz@5.2.4%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   ea6lvla              ^tar@1.31%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   njk2pzu          ^libtool@2.4.6%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   aofumyv          ^pcre@8.42%gcc@7.2.0+jit+multibyte+utf arch=linux-rhel6-x86_64
 -   vx2iy34      ^ninja-fortran@1.9.0.2.g99df1%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   bfndwzi          ^python@2.7.15%gcc@7.2.0+bz2+ctypes+dbm+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4~uuid+zlib arch=linux-rhel6-x86_64
 -   3kyw4xp              ^libffi@3.2.1%gcc@7.2.0 arch=linux-rhel6-x86_64
 -   6fozjh5              ^sqlite@3.30.1%gcc@7.2.0~column_metadata+fts~functions~rtree arch=linux-rhel6-x86_64
 -   rjakshk      ^util-macros@1.19.1%gcc@7.2.0 arch=linux-rhel6-x86_64
```

but there was a build error in the package 'perl' reported in #13505 so it never got to actually build python@2.1.15.  But when I go  to run the spack command after this:

```
./atdm-spack/spack/bin/spack compiler find --scope site
```

it dies with:

```
Traceback (most recent call last):
  File "./atdm-spack/spack/bin/spack", line 64, in <module>
    sys.exit(spack.main.main())
  File "/home/rabartl/Spack.base4/atdm-spack/spack/lib/spack/spack/main.py", line 653, in main
    ev.activate(env, args.use_env_repo)
  File "/home/rabartl/Spack.base4/atdm-spack/spack/lib/spack/spack/environment.py", line 163, in activate
    cmds += env.add_default_view_to_shell(shell)
  File "/home/rabartl/Spack.base4/atdm-spack/spack/lib/spack/spack/environment.py", line 1074, in add_default_view_to_shell
    spec, self.default_view))
  File "/home/rabartl/Spack.base4/atdm-spack/spack/lib/spack/spack/environment.py", line 1055, in environment_modifications_for_spec
    spec, context='run'
  File "/home/rabartl/Spack.base4/atdm-spack/spack/lib/spack/spack/build_environment.py", line 759, in modifications_from_dependencies
    dpkg.setup_dependent_package(pkg.module, spec)
  File "/home/rabartl/Spack.base4/atdm-spack/spack/var/spack/repos/builtin/packages/python/package.py", line 729, in setup_dependent_package
    module.setup_py = Executable(
  File "/home/rabartl/Spack.base4/atdm-spack/spack/var/spack/repos/builtin/packages/python/package.py", line 526, in command
    
RuntimeError: Unable to locate python command in /home/rabartl/Spack.base4/atdm-spack/spack/opt/spack/linux-rhel6-x86_64/gcc-7.2.0/python-2.7.15-bfndwzimloeo5odtb656tkcsid4jzg42/bin
```

What is spack doing that it things that this python actually got installed?  This is new behavior for spack.

How can I work around this for now?  This is a major impediment to upgrading spack to version 0.13.0.







Discussion:
So it appears that if I remove the spack.yaml file then the command `spack compilers find` works.  So it seems that Spack has a defect where if a spack.yaml file exists and it determines the build of python, that spack will automatically try to use that python with other spack commands even if that python is not actually built!

So I think I have a workaround now.  Just more scripting ...


Resolving patch:
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -1109,7 +1109,7 @@ def add_default_view_to_shell(self, shell):
             self.default_view))
 
         for _, spec in self.concretized_specs():
-            if spec in self.default_view:
+            if spec in self.default_view and spec.package.installed:
                 env_mod.extend(self.environment_modifications_for_spec(
                     spec, self.default_view))
 
@@ -1130,7 +1130,7 @@ def rm_default_view_from_shell(self, shell):
             self.default_view).reversed())
 
         for _, spec in self.concretized_specs():
-            if spec in self.default_view:
+            if spec in self.default_view and spec.package.installed:
                 env_mod.extend(
                     self.environment_modifications_for_spec(
                         spec, self.default_view).reversed())


Test patch: