Repository: spack/spack

Issue:
--config-scope seems to be ignored
Starting with commit 43b0356e14a8227f33040302cf948d3c98508d59, configuration scopes seem to be ignored.  For example, with one commit before (dc36b4737d16ea4aa49daa14fb782b5ea85b60e3):

```console
$ cd $spack_root
$ git checkout dc36b4737d16ea4aa49daa14fb782b5ea85b60e3
$ ./bin/spack --config-scope=<some path> config blame repos
---                                            repos:
<some path>/repos.yaml:2                       - $nevada_toolset2_root/var/nevada/spack/repo
<spack root>/etc/spack/defaults/repos.yaml:14  - $spack/var/spack/repos/builtin
```

but, after 43b0356e14a8227f33040302cf948d3c98508d59 I get

```console
$ cd $spack_root
$ git checkout develop
$ ./bin/spack --config-scope=<some path> config blame repos
---                                            repos:
<spack root>/etc/spack/defaults/repos.yaml:14  - $spack/var/spack/repos/builtin
```

Checking out `lib/spack/spack/relocate.py` from dc36b4737d16ea4aa49daa14fb782b5ea85b60e3 seems to resolve the issue:

```console
$ cd $spack_root
$ git co dc36b4737d16ea4aa49daa14fb782b5ea85b60e3 -- lib/spack/spack/relocate.py
$ ./bin/spack --config-scope=<some path> config blame repos
---                                            repos:
<some path>/repos.yaml:2                       - $nevada_toolset2_root/var/nevada/spack/repo
<spack root>/etc/spack/defaults/repos.yaml:14  - $spack/var/spack/repos/builtin
```

One of the changes in 43b0356e14a8227f33040302cf948d3c98508d59 is to the function signature of `file_is_relocatable` from

```python
def file_is_relocatable(file):
    ...
```

To

```python
def file_is_relocatable(
    file, paths_to_relocate=[spack.store.layout.root, spack.paths.prefix]):
```

`paths_to_relocate` is then used in the function.  Simply making the following change fixes the config scope issue for me:

```python
def file_is_relocatable(file):
    paths_to_relocate = [spack.store.layout.root, spack.paths.prefix]
```

That said, this makes no sense to me.  The function `file_is_relocatable` is not called when `spack config blame ...` is issued (tested by dropping `assert 0` as the first line of `file_is_relocatable`).  Nevertheless, the change does fix my issue.

A grep of the spack source shows:

```console
$ cd $spack_root
$ grep -irl  --include=*.py file_is_relocatable .
./lib/spack/spack/test/relocate.py
./lib/spack/spack/binary_distribution.py
./lib/spack/spack/relocate.py
```

and none of the calls use the `paths_to_relocate` argument, so the change above should be fine, and it might be best to leave mutable arguments from function signature, if possible.


@becker33, since he was the author of 43b0356e



Discussion:

Resolving patch:
diff --git a/lib/spack/spack/relocate.py b/lib/spack/spack/relocate.py
--- a/lib/spack/spack/relocate.py
+++ b/lib/spack/spack/relocate.py
@@ -651,8 +651,7 @@ def is_relocatable(spec):
     return True
 
 
-def file_is_relocatable(
-        file, paths_to_relocate=[spack.store.layout.root, spack.paths.prefix]):
+def file_is_relocatable(file, paths_to_relocate=None):
     """Returns True if the file passed as argument is relocatable.
 
     Args:
@@ -665,6 +664,8 @@ def file_is_relocatable(
 
         ValueError: if the file does not exist or the path is not absolute
     """
+    default_paths_to_relocate = [spack.store.layout.root, spack.paths.prefix]
+    paths_to_relocate = paths_to_relocate or default_paths_to_relocate
 
     if not (platform.system().lower() == 'darwin'
             or platform.system().lower() == 'linux'):


Test patch: