Repository: spack/spack

Issue:
bug: spack install from yaml fails
I am still seeing the issue using `spack install --only dependencies <pkg>` . For example, try this in Docker image `spack/ubuntu-bionic`:

```
spack mirror add e4s https://instinct.nic.uoregon.edu:8083/e4s
spack spec -y py-ptyprocess > py-ptyprocess.spec.yaml
spack install --cache-only --only dependencies ./py-ptyprocess.spec.yaml
```

Output (truncated to only show final error):
```
==> Error: Detected uninstalled dependencies for diffutils: {'libiconv'}
==> Error: Cannot proceed with diffutils: 1 uninstalled dependency: libiconv
```

The KEY is that libiconv IS INSTALLED, despite the above error message:
```
$> spack find libiconv
--- linux-ubuntu18.04-x86_64 / gcc@7.4.0 --------------
libiconv@1.16
```

_Originally posted by @eugeneswalker in https://github.com/spack/spack/pull/15197#issuecomment-591005144_


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -1919,9 +1919,7 @@ def from_dict(data):
 
             yaml_deps = node[name]['dependencies']
             for dname, dhash, dtypes in Spec.read_yaml_dep_specs(yaml_deps):
-                # Fill in dependencies by looking them up by name in deps dict
-                deps[name]._dependencies[dname] = DependencySpec(
-                    deps[name], deps[dname], dtypes)
+                deps[name]._add_dependency(deps[dname], dtypes)
 
         return spec
 


Test patch:
diff --git a/lib/spack/spack/test/concretize_preferences.py b/lib/spack/spack/test/concretize_preferences.py
--- a/lib/spack/spack/test/concretize_preferences.py
+++ b/lib/spack/spack/test/concretize_preferences.py
@@ -15,15 +15,15 @@
 
 
 @pytest.fixture()
-def concretize_scope(config, tmpdir):
+def concretize_scope(mutable_config, tmpdir):
     """Adds a scope for concretization preferences"""
     tmpdir.ensure_dir('concretize')
-    config.push_scope(
+    mutable_config.push_scope(
         ConfigScope('concretize', str(tmpdir.join('concretize'))))
 
     yield
 
-    config.pop_scope()
+    mutable_config.pop_scope()
     spack.repo.path._provider_index = None
 
 
@@ -84,16 +84,24 @@ def test_preferred_variants(self):
             'mpileaks', debug=True, opt=True, shared=False, static=False
         )
 
-    def test_preferred_compilers(self, mutable_mock_repo):
+    def test_preferred_compilers(self):
         """Test preferred compilers are applied correctly
         """
-        update_packages('mpileaks', 'compiler', ['clang@3.3'])
+        # Need to make sure the test uses an available compiler
+        compiler_list = spack.compilers.all_compiler_specs()
+        assert compiler_list
+
+        # Try the first available compiler
+        compiler = str(compiler_list[0])
+        update_packages('mpileaks', 'compiler', [compiler])
         spec = concretize('mpileaks')
-        assert spec.compiler == spack.spec.CompilerSpec('clang@3.3')
+        assert spec.compiler == spack.spec.CompilerSpec(compiler)
 
-        update_packages('mpileaks', 'compiler', ['gcc@4.5.0'])
+        # Try the last available compiler
+        compiler = str(compiler_list[-1])
+        update_packages('mpileaks', 'compiler', [compiler])
         spec = concretize('mpileaks')
-        assert spec.compiler == spack.spec.CompilerSpec('gcc@4.5.0')
+        assert spec.compiler == spack.spec.CompilerSpec(compiler)
 
     def test_preferred_target(self, mutable_mock_repo):
         """Test preferred compilers are applied correctly