Repository: spack/spack

Issue:
lmod modules generated for intel packages include LMOD_* environment variables
When I build lmod modules from installed intel packages (including intel, intel-mkl, and intel-mpi) the generated modules include LMOD and related environment variables from the point-in-time environment. This breaks for us because our default lmod environment is different from the environment I'm building the modulefiles for.

### Spack version
```console
$ spack --version
0.14.1-415-cbcac72
```

### Steps to reproduce the issue

```console
$ spack install intel
$ spack module lmod refresh --delete-tree
$ module show intel/19.0.5 2>&1 | grep 'LMOD_'
```

### Error Message

```console
setenv("LMOD_CMD","/curc/sw/lmod/lmod/libexec/lmod")
setenv("LMOD_DIR","/curc/sw/lmod/lmod/libexec")
setenv("LMOD_PKG","/curc/sw/lmod/lmod")
setenv("LMOD_VERSION","6.3.7")
...
```

### Information on your system

1. RHEL7.6

```
modules:
  enable:
  - lmod
  lmod:
    hash_length: 0
    core_compilers:
    - gcc@4.8.5
    hierarchy:
    - mpi
    - lapack
    blacklist:
      - '%gcc'
      - '%intel'
    whitelist:
      - intel@19.0.5
      - gcc@9.3.0
      - intel-mkl
      - intel-mpi
      - openmpi
```

```
packages:
  intel:
    variants: auto_dispatch=AVX,CORE-AVX2,CORE-AVX512,SSE4.2
```

### General information

- [X] I have run `spack --version` and reported the version of Spack
- [X] I have searched the issues of this repo and believe this is not a duplicate
lmod modules generated for intel packages include LMOD_* environment variables
When I build lmod modules from installed intel packages (including intel, intel-mkl, and intel-mpi) the generated modules include LMOD and related environment variables from the point-in-time environment. This breaks for us because our default lmod environment is different from the environment I'm building the modulefiles for.

### Spack version
```console
$ spack --version
0.14.1-415-cbcac72
```

### Steps to reproduce the issue

```console
$ spack install intel
$ spack module lmod refresh --delete-tree
$ module show intel/19.0.5 2>&1 | grep 'LMOD_'
```

### Error Message

```console
setenv("LMOD_CMD","/curc/sw/lmod/lmod/libexec/lmod")
setenv("LMOD_DIR","/curc/sw/lmod/lmod/libexec")
setenv("LMOD_PKG","/curc/sw/lmod/lmod")
setenv("LMOD_VERSION","6.3.7")
...
```

### Information on your system

1. RHEL7.6

```
modules:
  enable:
  - lmod
  lmod:
    hash_length: 0
    core_compilers:
    - gcc@4.8.5
    hierarchy:
    - mpi
    - lapack
    blacklist:
      - '%gcc'
      - '%intel'
    whitelist:
      - intel@19.0.5
      - gcc@9.3.0
      - intel-mkl
      - intel-mpi
      - openmpi
```

```
packages:
  intel:
    variants: auto_dispatch=AVX,CORE-AVX2,CORE-AVX512,SSE4.2
```

### General information

- [X] I have run `spack --version` and reported the version of Spack
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
To be clear, this appears to _only_ be happening for intel packages.

```
$ find /curc/sw/modules/spack/spring2020/linux-rhel7-x86_64 -type f -exec grep LMOD_CMD {} +
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/gcc/9.3.0/intel-mkl/2019.5.281.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/intel/19.0.5/intel-mkl/2019.5.281.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/intel/19.0.5/intel-mpi/2019.6.166.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/Core/intel/19.0.5.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
```
I have tracked this down to https://github.com/spack/spack/blob/3f190a432e41edc2bc33027b63e7b345898dacb9/lib/spack/spack/build_systems/intel.py#L1018, where sourcing a file upstream appears to produce the noted environment variables. I'll look into that file.
@anderbubble I tried reproducing this issue and I couldn't. With 628516c7611126f2a1b1f72d57e4cfd95535cf30 I was able to install `intel`:
```console
$ spack find
==> 3 installed packages
-- linux-rhel7-haswell / gcc@4.8.5 ------------------------------
intel@19.1.0  libsigsegv@2.12  m4@1.4.18
```
but there is no trace of any `LMOD_*` variable:
```console
$ ls /home/culpo/github/spack/share/spack/lmod/linux-rhel7-x86_64/Core/intel/19.1.0.lua
/home/culpo/github/spack/share/spack/lmod/linux-rhel7-x86_64/Core/intel/19.1.0.lua
$ grep LMOD /home/culpo/github/spack/share/spack/lmod/linux-rhel7-x86_64/Core/intel/19.1.0.lua
```
I think this might be dependent on the configuration of your machines, but I'd like to figure out why you don't have `LMOD_*` variables in the shell that starts Spack while you have them / they are modified when you source that file in a new child shell. That said it seems similar to #10753 and can be probably resolved in the same way.
@alalazo I agree, there's some element here of our local environment. I'm still trying to figure out why the sourced file has LMOD variables in its environment if the original comparison environment does not. Otherwise, adding these variables to the blacklist might be the right thing. (I'll try your patch after I look around a bit more.)

> I'd like to figure out why you don't have LMOD_* variables in the shell that starts Spack while you have them / they are modified when you source that file in a new child shell.

Turns out we're on the same page. Let me know if you have any suggestions for investigation.
I have confirmed this in isolation. Still looking into why these variables appear as new by sourcing the file.

```
[spring2020] [rcops@shas0136 ~]$ PYTHONPATH=/curc/admin/spack/lib/spack python
Python 2.7.5 (default, May 20 2019, 12:21:26) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from spack.util.environment import EnvironmentModifications
>>> env = EnvironmentModifications.from_sourcing_file('/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/compilervars.sh', *('intel64',))
==> Warning: Quotes in command arguments can confuse scripts like configure.
  The following arguments may cause problems when executed:
      source /curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/compilervars.sh intel64 &> /dev/null && python3 -c "import os, json; print(json.dumps(dict(os.environ)))"
  Quotes aren't needed because spack doesn't use a shell.
  Consider removing them
>>> for mod in env:
...     print((mod.name, mod.value))
... 
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/intel-19.0.5/intel-mpi-2019.6.166-f54mwospzosqmvbx6drpqijvhlwzca65/compilers_and_libraries_2020.0.166/linux/mpi/intel64/lib/mpi.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/mpi.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/daal.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/daal.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/mpi.jar')
('CPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/include')
('FI_PROVIDER_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib/prov')
('INTEL_LICENSE_FILE', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/licenses')
('INTEL_LICENSE_FILE', '/opt/intel/licenses')
('INTEL_LICENSE_FILE', '/home/rcops/intel/licenses')
('I_MPI_ROOT', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/release')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib')
('LMOD_CMD', '/curc/sw/lmod/lmod/libexec/lmod')
('LMOD_DIR', '/curc/sw/lmod/lmod/libexec')
('LMOD_PKG', '/curc/sw/lmod/lmod')
('LMOD_VERSION', '6.3.7')
('MANPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/man')
('MANPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/man/common')
('MODULESHOME', '/curc/sw/lmod/lmod')
('NLSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/gdb/intel64/share/locale/%l_%t/%N')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/bin')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/bin')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/intel64')
('PKG_CONFIG_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/bin/pkgconfig')
```
I have also now successfully confirmed to my satisfaction that just sourcing the file doesn't insert the LMOD variables; so something is apparently preventing `EnvironmentModifications.from_sourcing_file` from detecting that the variables are present before sourcing the file, so it doesn't filter them out.

```
[spring2020] [rcops@shas0136 ~]$ env -i bash -c 'source /curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/compilervars.sh intel64; env'   
which: no manpath in ((null))
MKLROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl
MANPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/man/common:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/man:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/documentation_2019/en/debugger/gdb-ia/man/
INTEL_LICENSE_FILE=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/licenses:/opt/intel/licenses:/intel/licenses
IPPROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp
LIBRARY_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/../tbb/lib/intel64_lin/gcc4.4
LD_LIBRARY_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/release:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/libipt/intel64/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/../tbb/lib/intel64_lin/gcc4.4
PSTLROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl
FI_PROVIDER_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib/prov
CPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/include
NLSPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/gdb/intel64/share/locale/%l_%t/%N
PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/intel64:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/bin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/bin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/gdb/intel64/bin:/usr/local/bin:/usr/bin
TBBROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb
PWD=/home/rcops
DAALROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal
INTEL_PYTHONHOME=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/python/intel64/
SHLVL=1
CLASSPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/mpi.jar:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/daal.jar
PKG_CONFIG_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/bin/pkgconfig
INFOPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/documentation_2019/en/debugger/gdb-ia/info/
I_MPI_ROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi
_=/usr/bin/env
```
ok, I think I get what's going on here now.

In my local environment I have an lmod loaded; but it's a _different_ lmod than is loaded by default. (I'm building a new one as part of this process.) But when spack sources the file to see how the environment changes, not only does it see what sourcing the file does; it also sees what bash brings in as its default environment. This includes ~loading~ initiating modules from our profiles. So since spack sees these variables _change_ it declares them part of the sourced environment, and includes them.

I suggest that `spack.util.environment_after_sourcing_files` should use `--noprofile --norc` by default, at least if the shell is bash.

But that's probably too much special casing; a better option would probably be to compare the default bash environment against the sourced environment, rather than just comparing against the current environment.

I'll see if I can get a working patch together.
@alalazo I get why someone might object to this, but it works, and it's easier than building a whole new function just to get the default shell environment.

```
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
index 248a6d3..862f04f 100644
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -602,7 +602,8 @@ def from_sourcing_file(filename, *arguments, **kwargs):
 
         # Compute the environments before and after sourcing
         before = sanitize(
-            dict(os.environ), blacklist=blacklist, whitelist=whitelist
+            environment_after_sourcing_files(os.devnull, **kwargs),
+            blacklist=blacklist, whitelist=whitelist
         )
         file_and_args = (filename,) + arguments
         after = sanitize(
```

What do you think? If this won't get me laughed out of the room, I'll submit a PR. :)
To be clear, this appears to _only_ be happening for intel packages.

```
$ find /curc/sw/modules/spack/spring2020/linux-rhel7-x86_64 -type f -exec grep LMOD_CMD {} +
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/gcc/9.3.0/intel-mkl/2019.5.281.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/intel/19.0.5/intel-mkl/2019.5.281.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/intel/19.0.5/intel-mpi/2019.6.166.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
/curc/sw/modules/spack/spring2020/linux-rhel7-x86_64/Core/intel/19.0.5.lua:setenv("LMOD_CMD", "/curc/sw/lmod/lmod/libexec/lmod")
```
I have tracked this down to https://github.com/spack/spack/blob/3f190a432e41edc2bc33027b63e7b345898dacb9/lib/spack/spack/build_systems/intel.py#L1018, where sourcing a file upstream appears to produce the noted environment variables. I'll look into that file.
@anderbubble I tried reproducing this issue and I couldn't. With 628516c7611126f2a1b1f72d57e4cfd95535cf30 I was able to install `intel`:
```console
$ spack find
==> 3 installed packages
-- linux-rhel7-haswell / gcc@4.8.5 ------------------------------
intel@19.1.0  libsigsegv@2.12  m4@1.4.18
```
but there is no trace of any `LMOD_*` variable:
```console
$ ls /home/culpo/github/spack/share/spack/lmod/linux-rhel7-x86_64/Core/intel/19.1.0.lua
/home/culpo/github/spack/share/spack/lmod/linux-rhel7-x86_64/Core/intel/19.1.0.lua
$ grep LMOD /home/culpo/github/spack/share/spack/lmod/linux-rhel7-x86_64/Core/intel/19.1.0.lua
```
I think this might be dependent on the configuration of your machines, but I'd like to figure out why you don't have `LMOD_*` variables in the shell that starts Spack while you have them / they are modified when you source that file in a new child shell. That said it seems similar to #10753 and can be probably resolved in the same way.
@alalazo I agree, there's some element here of our local environment. I'm still trying to figure out why the sourced file has LMOD variables in its environment if the original comparison environment does not. Otherwise, adding these variables to the blacklist might be the right thing. (I'll try your patch after I look around a bit more.)

> I'd like to figure out why you don't have LMOD_* variables in the shell that starts Spack while you have them / they are modified when you source that file in a new child shell.

Turns out we're on the same page. Let me know if you have any suggestions for investigation.
I have confirmed this in isolation. Still looking into why these variables appear as new by sourcing the file.

```
[spring2020] [rcops@shas0136 ~]$ PYTHONPATH=/curc/admin/spack/lib/spack python
Python 2.7.5 (default, May 20 2019, 12:21:26) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from spack.util.environment import EnvironmentModifications
>>> env = EnvironmentModifications.from_sourcing_file('/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/compilervars.sh', *('intel64',))
==> Warning: Quotes in command arguments can confuse scripts like configure.
  The following arguments may cause problems when executed:
      source /curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/compilervars.sh intel64 &> /dev/null && python3 -c "import os, json; print(json.dumps(dict(os.environ)))"
  Quotes aren't needed because spack doesn't use a shell.
  Consider removing them
>>> for mod in env:
...     print((mod.name, mod.value))
... 
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/intel-19.0.5/intel-mpi-2019.6.166-f54mwospzosqmvbx6drpqijvhlwzca65/compilers_and_libraries_2020.0.166/linux/mpi/intel64/lib/mpi.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/mpi.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/daal.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/daal.jar')
('CLASSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/mpi.jar')
('CPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/include')
('FI_PROVIDER_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib/prov')
('INTEL_LICENSE_FILE', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/licenses')
('INTEL_LICENSE_FILE', '/opt/intel/licenses')
('INTEL_LICENSE_FILE', '/home/rcops/intel/licenses')
('I_MPI_ROOT', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/release')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib')
('LD_LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64')
('LIBRARY_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib')
('LMOD_CMD', '/curc/sw/lmod/lmod/libexec/lmod')
('LMOD_DIR', '/curc/sw/lmod/lmod/libexec')
('LMOD_PKG', '/curc/sw/lmod/lmod')
('LMOD_VERSION', '6.3.7')
('MANPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/man')
('MANPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/man/common')
('MODULESHOME', '/curc/sw/lmod/lmod')
('NLSPATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/gdb/intel64/share/locale/%l_%t/%N')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/bin')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/bin')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin')
('PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/intel64')
('PKG_CONFIG_PATH', '/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/bin/pkgconfig')
```
I have also now successfully confirmed to my satisfaction that just sourcing the file doesn't insert the LMOD variables; so something is apparently preventing `EnvironmentModifications.from_sourcing_file` from detecting that the variables are present before sourcing the file, so it doesn't filter them out.

```
[spring2020] [rcops@shas0136 ~]$ env -i bash -c 'source /curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/compilervars.sh intel64; env'   
which: no manpath in ((null))
MKLROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl
MANPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/man/common:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/man:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/documentation_2019/en/debugger/gdb-ia/man/
INTEL_LICENSE_FILE=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/licenses:/opt/intel/licenses:/intel/licenses
IPPROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp
LIBRARY_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/../tbb/lib/intel64_lin/gcc4.4
LD_LIBRARY_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/release:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/lib/intel64:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/lib/intel64/gcc4.7:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/libipt/intel64/lib:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/intel64_lin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/../tbb/lib/intel64_lin/gcc4.4
PSTLROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl
FI_PROVIDER_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/lib/prov
CPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/ipp/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/pstl/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb/include:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/include
NLSPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/compiler/lib/intel64/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/lib/intel64_lin/locale/%l_%t/%N:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/gdb/intel64/share/locale/%l_%t/%N
PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin/intel64:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/bin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/libfabric/bin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/bin:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/gdb/intel64/bin:/usr/local/bin:/usr/bin
TBBROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/tbb
PWD=/home/rcops
DAALROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal
INTEL_PYTHONHOME=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/debugger_2019/python/intel64/
SHLVL=1
CLASSPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi/intel64/lib/mpi.jar:/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/daal/lib/daal.jar
PKG_CONFIG_PATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mkl/bin/pkgconfig
INFOPATH=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/documentation_2019/en/debugger/gdb-ia/info/
I_MPI_ROOT=/curc/sw/opt/spack/linux-rhel7-haswell/gcc-4.8.5/intel-19.0.5-kunu3stjnxwn4r3mndan3hgi3cudfsos/compilers_and_libraries_2019.5.281/linux/mpi
_=/usr/bin/env
```
ok, I think I get what's going on here now.

In my local environment I have an lmod loaded; but it's a _different_ lmod than is loaded by default. (I'm building a new one as part of this process.) But when spack sources the file to see how the environment changes, not only does it see what sourcing the file does; it also sees what bash brings in as its default environment. This includes ~loading~ initiating modules from our profiles. So since spack sees these variables _change_ it declares them part of the sourced environment, and includes them.

I suggest that `spack.util.environment_after_sourcing_files` should use `--noprofile --norc` by default, at least if the shell is bash.

But that's probably too much special casing; a better option would probably be to compare the default bash environment against the sourced environment, rather than just comparing against the current environment.

I'll see if I can get a working patch together.
@alalazo I get why someone might object to this, but it works, and it's easier than building a whole new function just to get the default shell environment.

```
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
index 248a6d3..862f04f 100644
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -602,7 +602,8 @@ def from_sourcing_file(filename, *arguments, **kwargs):
 
         # Compute the environments before and after sourcing
         before = sanitize(
-            dict(os.environ), blacklist=blacklist, whitelist=whitelist
+            environment_after_sourcing_files(os.devnull, **kwargs),
+            blacklist=blacklist, whitelist=whitelist
         )
         file_and_args = (filename,) + arguments
         after = sanitize(
```

What do you think? If this won't get me laughed out of the room, I'll submit a PR. :)

Resolving patch:
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -602,7 +602,8 @@ def from_sourcing_file(filename, *arguments, **kwargs):
 
         # Compute the environments before and after sourcing
         before = sanitize(
-            dict(os.environ), blacklist=blacklist, whitelist=whitelist
+            environment_after_sourcing_files(os.devnull, **kwargs),
+            blacklist=blacklist, whitelist=whitelist
         )
         file_and_args = (filename,) + arguments
         after = sanitize(


Test patch: