Repository: spack/spack

Issue:
Warning: specifying a "dotkit" module root has no effect
Today I pulled the newest commits from the spack dev branch (since I was affected by [this](https://github.com/spack/spack/pull/12962) bug and now executing setup-env.sh leads to this error:

```
$ $SPACK_ROOT/share/spack/setup-env.sh 

==> Warning: specifying a "dotkit" module root has no effect [support for dotkit module files has been dropped]
Traceback (most recent call last):
  File "/apps/spack/bin/spack", line 64, in <module>
    sys.exit(spack.main.main())
  File "/apps/spack/lib/spack/spack/main.py", line 651, in main
    print_setup_info(*args.print_shell_vars.split(','))
  File "/apps/spack/lib/spack/spack/main.py", line 598, in print_setup_info
    module_to_roots[name].append(path)
KeyError: 'dotkit'

```
The warning is also shown when running just "spack list", here is the (relevant) output with the "-d --stacktrace" option:

```
$ spack -d --stacktrace list

lib/spack/spack/config.py:684 ==> [2019-10-04-08:09:48.160306] Reading config file /apps/spack/etc/spack/defaults/modules.yaml
lib/spack/spack/config.py:684 ==> [2019-10-04-08:09:48.169278] Reading config file /apps/spack/etc/spack/defaults/linux/modules.yaml
lib/spack/spack/config.py:684 ==> [2019-10-04-08:09:48.172336] Reading config file /home/anselmam/.spack/modules.yaml
lib/spack/spack/config.py:684 ==> [2019-10-04-08:09:48.177407] Reading config file /apps/spack/etc/spack/defaults/config.yaml
lib/spack/spack/config.py:684 ==> [2019-10-04-08:09:48.191328] Reading config file /home/anselmam/.spack/config.yaml
lib/spack/spack/schema/__init__.py:93 ==> [2019-10-04-08:09:48.204053] Warning: specifying a "dotkit" module root has no effect [support for dotkit module files has been dropped]
lib/spack/spack/cmd/__init__.py:101 ==> [2019-10-04-08:09:48.206996] Imported list from built-in commands
lib/spack/spack/cmd/__init__.py:101 ==> [2019-10-04-08:09:48.207759] Imported list from built-in commands
lib/spack/spack/config.py:684 ==> [2019-10-04-08:09:48.218166] Reading config file /apps/spack/etc/spack/defaults/repos.yaml
```

Afterwards spack does not change my $MODULEPATH, so the modules created by spack are not available with "module av", if I don't adjust my $MODULEPATH manually.

### Information on your system
 1. Arch linux
 2. lmod for loading module files



Discussion:

Resolving patch:
diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py
--- a/lib/spack/spack/main.py
+++ b/lib/spack/spack/main.py
@@ -588,11 +588,14 @@ def shell_set(var, value):
     shell_set('_sp_compatible_sys_types',
               ':'.join(spack.architecture.compatible_sys_types()))
     # print roots for all module systems
-    module_roots = spack.config.get('config:module_roots')
     module_to_roots = {
         'tcl': list(),
         'lmod': list()
     }
+    module_roots = spack.config.get('config:module_roots')
+    module_roots = dict(
+        (k, v) for k, v in module_roots.items() if k in module_to_roots
+    )
     for name, path in module_roots.items():
         path = spack.util.path.canonicalize_path(path)
         module_to_roots[name].append(path)
@@ -601,6 +604,10 @@ def shell_set(var, value):
         'upstreams') or {}
     for install_properties in other_spack_instances.values():
         upstream_module_roots = install_properties.get('modules', {})
+        upstream_module_roots = dict(
+            (k, v) for k, v in upstream_module_roots.items()
+            if k in module_to_roots
+        )
         for module_type, root in upstream_module_roots.items():
             module_to_roots[module_type].append(root)
 


Test patch:
diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py
--- a/lib/spack/spack/test/config.py
+++ b/lib/spack/spack/test/config.py
@@ -16,6 +16,7 @@
 
 import spack.paths
 import spack.config
+import spack.main
 import spack.schema.compilers
 import spack.schema.config
 import spack.schema.env
@@ -759,3 +760,19 @@ def test_bad_compilers_yaml(tmpdir):
     - compiler:
          fenfironfent: /bad/value
 """)
+
+
+@pytest.mark.regression('13045')
+def test_dotkit_in_config_does_not_raise(
+        mock_config, write_config_file, capsys
+):
+    write_config_file('config',
+                      {'config': {'module_roots': {'dotkit': '/some/path'}}},
+                      'high')
+    spack.main.print_setup_info('sh')
+    captured = capsys.readouterr()
+
+    # Check that we set the variables we expect and that
+    # we throw a a deprecation warning without raising
+    assert '_sp_sys_type' in captured[0]  # stdout
+    assert 'Warning' in captured[1]  # stderr