Repository: spack/spack

Issue:
spack activate fails if package is already active with a conflict error 
Example (this is not unique to `py-sphinx`):

`bin/spack -d activate -f py-sphinx` fails if `py-sphinx` is already activated.

Similarity, if I try to activate any package that depends on `py-sphinx`, it will fail.


To get to the root cause, I modified `lib/spack/spack/directory_layout.py` to print out some info.

```
  def check_extension_conflict(self, spec, ext_spec):
        exts = self._extension_map(spec)
        if ext_spec.name in exts:
            installed_spec = exts[ext_spec.name]
            print(dir(installed_spec))
            print("INSTALLED SPEC:\n" + installed_spec.dag_hash() + "\n"+ str(installed_spec))
            print("EXT_SPEC:\n" + ext_spec.dag_hash() + "\n" +  str(ext_spec))
            if ext_spec == installed_spec:
                print("ALREADY INSTALLED")
                raise ExtensionAlreadyInstalledError(spec, ext_spec)
            else:
                print("CONFLICT")
                raise ExtensionConflictError(spec, ext_spec, installed_spec)

```

Details below.

In this case, there is only one install of this package.

Even though the dag_hash() is the same, the spec are not evaled as equal, triggering conflict instead of already installed.


### Error Message
```
INSTALLED SPEC:

l6pskjy72smsk5dnhfr72jey5bcrwn3g

py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake ^apple-libuuid@1353.100.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^bzip2@1.0.8%clang@10.0.0-apple+shared arch=darwin-mojave-skylake ^diffutils@3.7%clang@10.0.0-apple arch=darwin-mojave-skylake ^expat@2.2.10%clang@10.0.0-apple~libbsd arch=darwin-mojave-skylake ^gettext@0.21%clang@10.0.0-apple+bzip2+curses+git~libunistring+libxml2+tar+xz arch=darwin-mojave-skylake ^libc@1.0%clang@10.0.0-apple+iconv~rpc arch=darwin-mojave-skylake ^libffi@3.3%clang@10.0.0-apple patches=26f26c6f29a7ce9bf370ad3ab2610f99365b4bdd7b82e7c31df41a3370d685c0 arch=darwin-mojave-skylake ^libxml2@2.9.10%clang@10.0.0-apple~python arch=darwin-mojave-skylake ^ncurses@6.2%clang@10.0.0-apple~symlinks+termlib arch=darwin-mojave-skylake ^openssl@1.1.1j%clang@10.0.0-apple~docs+systemcerts arch=darwin-mojave-skylake ^perl@5.32.1%clang@10.0.0-apple+cpanm+shared+threads arch=darwin-mojave-skylake ^pkgconf@1.7.3%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-alabaster@0.7.12%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-babel@2.7.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-certifi@2020.6.20%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-chardet@3.0.4%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-docutils@0.15.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-idna@2.8%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-imagesize@1.1.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-jinja2@2.10.3%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-markupsafe@1.1.1%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-packaging@19.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-pygments@2.6.1%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-pyparsing@2.4.7%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-pytest-runner@5.1%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-pytz@2020.1%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-requests@2.24.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-setuptools@50.3.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-setuptools-scm@4.1.2%clang@10.0.0-apple~toml arch=darwin-mojave-skylake ^py-six@1.15.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-snowballstemmer@2.0.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-sphinxcontrib-websupport@1.1.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-urllib3@1.25.6%clang@10.0.0-apple~secure~socks arch=darwin-mojave-skylake ^python@3.8.8%clang@10.0.0-apple+bz2+ctypes~dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93189bc278fbc37a50ed7f183bd8aaf249a8e1670a465f0db6bb4f8cf87 arch=darwin-mojave-skylake ^readline@8.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^sqlite@3.34.0%clang@10.0.0-apple+column_metadata+fts~functions~rtree arch=darwin-mojave-skylake ^tar@1.32%clang@10.0.0-apple arch=darwin-mojave-skylake ^xz@5.2.5%clang@10.0.0-apple~pic arch=darwin-mojave-skylake ^zlib@1.2.11%clang@10.0.0-apple+optimize+pic+shared arch=darwin-mojave-skylake

EXT_SPEC:

l6pskjy72smsk5dnhfr72jey5bcrwn3g

py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake ^apple-libuuid@1353.100.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^bzip2@1.0.8%clang@10.0.0-apple+shared arch=darwin-mojave-skylake ^expat@2.2.10%clang@10.0.0-apple~libbsd arch=darwin-mojave-skylake ^gettext@0.21%clang@10.0.0-apple+bzip2+curses+git~libunistring+libxml2+tar+xz arch=darwin-mojave-skylake ^libc@1.0%clang@10.0.0-apple+iconv~rpc arch=darwin-mojave-skylake ^libffi@3.3%clang@10.0.0-apple patches=26f26c6f29a7ce9bf370ad3ab2610f99365b4bdd7b82e7c31df41a3370d685c0 arch=darwin-mojave-skylake ^libxml2@2.9.10%clang@10.0.0-apple~python arch=darwin-mojave-skylake ^ncurses@6.2%clang@10.0.0-apple~symlinks+termlib arch=darwin-mojave-skylake ^openssl@1.1.1j%clang@10.0.0-apple~docs+systemcerts arch=darwin-mojave-skylake ^py-alabaster@0.7.12%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-babel@2.7.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-certifi@2020.6.20%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-chardet@3.0.4%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-docutils@0.15.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-idna@2.8%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-imagesize@1.1.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-jinja2@2.10.3%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-markupsafe@1.1.1%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-packaging@19.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-pygments@2.6.1%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-pyparsing@2.4.7%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-pytz@2020.1%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-requests@2.24.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-setuptools@50.3.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-six@1.15.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-snowballstemmer@2.0.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-sphinxcontrib-websupport@1.1.2%clang@10.0.0-apple arch=darwin-mojave-skylake ^py-urllib3@1.25.6%clang@10.0.0-apple~secure~socks arch=darwin-mojave-skylake ^python@3.8.8%clang@10.0.0-apple+bz2+ctypes~dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93189bc278fbc37a50ed7f183bd8aaf249a8e1670a465f0db6bb4f8cf87 arch=darwin-mojave-skylake ^readline@8.0%clang@10.0.0-apple arch=darwin-mojave-skylake ^sqlite@3.34.0%clang@10.0.0-apple+column_metadata+fts~functions~rtree arch=darwin-mojave-skylake ^tar@1.32%clang@10.0.0-apple arch=darwin-mojave-skylake ^xz@5.2.5%clang@10.0.0-apple~pic arch=darwin-mojave-skylake ^zlib@1.2.11%clang@10.0.0-apple+optimize+pic+shared arch=darwin-mojave-skylake
CONFLICT
==> [2021-03-18-13:47:42.134398] ExtensionConflictError: py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake/l6pskjy cannot be installed in python@3.8.8%clang@10.0.0-apple+bz2+ctypes~dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93189bc278fbc37a50ed7f183bd8aaf249a8e1670a465f0db6bb4f8cf87 arch=darwin-mojave-skylake/5s5r5wf because it conflicts with py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake/l6pskjy
==> [2021-03-18-13:47:42.134480] Error: py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake/l6pskjy cannot be installed in python@3.8.8%clang@10.0.0-apple+bz2+ctypes~dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93189bc278fbc37a50ed7f183bd8aaf249a8e1670a465f0db6bb4f8cf87 arch=darwin-mojave-skylake/5s5r5wf because it conflicts with py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake/l6pskjy
Traceback (most recent call last):
  File "/Users/harrison37/Work/github/llnl/conduit/ul_here/spack/lib/spack/spack/main.py", line 768, in main
    return _invoke_command(command, parser, args, unknown)
  File "/Users/harrison37/Work/github/llnl/conduit/ul_here/spack/lib/spack/spack/main.py", line 496, in _invoke_command
    return_val = command(parser, args)
  File "/Users/harrison37/Work/github/llnl/conduit/ul_here/spack/lib/spack/spack/cmd/activate.py", line 51, in activate
    spec.package.do_activate(view, with_dependencies=not args.force)
  File "/Users/harrison37/Work/github/llnl/conduit/ul_here/spack/lib/spack/spack/package.py", line 2323, in do_activate
    self.extendee_spec, self.spec)
  File "/Users/harrison37/Work/github/llnl/conduit/ul_here/spack/lib/spack/spack/directory_layout.py", line 441, in check_extension_conflict
    raise ExtensionConflictError(spec, ext_spec, installed_spec)
spack.directory_layout.ExtensionConflictError: py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake/l6pskjy cannot be installed in python@3.8.8%clang@10.0.0-apple+bz2+ctypes~dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93189bc278fbc37a50ed7f183bd8aaf249a8e1670a465f0db6bb4f8cf87 arch=darwin-mojave-skylake/5s5r5wf because it conflicts with py-sphinx@1.8.4%clang@10.0.0-apple arch=darwin-mojave-skylake/l6pskjy
```

### Information on your system

* **Spack:** 0.16.1-1754-03031fa677
* **Python:** 2.7.16
* **Platform:** darwin-mojave-skylake
* **Concretizer:** original


### Additional information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have searched the issues of this repo and believe this is not a duplicate
- [x] I have run the failing commands in debug mode and reported the output



Discussion:

Resolving patch:
diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py
--- a/lib/spack/spack/directory_layout.py
+++ b/lib/spack/spack/directory_layout.py
@@ -429,8 +429,8 @@ def add_extension(self, spec, ext_spec):
     def check_extension_conflict(self, spec, ext_spec):
         exts = self._extension_map(spec)
         if ext_spec.name in exts:
-            installed_spec = exts[ext_spec.name]
-            if ext_spec == installed_spec:
+            installed_spec = exts[ext_spec.name].copy(deps=('link', 'run'))
+            if ext_spec.copy(deps=('link', 'run')) == installed_spec:
                 raise ExtensionAlreadyInstalledError(spec, ext_spec)
             else:
                 raise ExtensionConflictError(spec, ext_spec, installed_spec)


Test patch: