internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: spack/spack

Issue:
Some spack tests fail because they find system executables instead of spack-provided
We observed this issue operating on the spock system at olcf using the gnu-PrgEnv module and the latest pull of spack to install the e4s environment. Running `spack test run` to do all internal smoke tests resulted in several errors indicating that the spack test for some basic utilities was finding the system executable instead of the one provided by spack. We did not attempt to find any externals in this install of spack.

The error takes the form:

`Executable 'perl' expected in prefix, found in /usr/bin/perl instead`

Packages that exhibited this testing result were: binutils (for 11 of its internally provided executables), cmake, m4 and perl.


Discussion:
I have experienced this problem as well with packages depending on a specific `CMake`.
I just encountered this as well. This affected `cmake`, `hdf5`, `m4`, `perl`, `python`, and `sqlite`, all of which expect to find their executables in their installation prefix. Are we not running `setup_run_environment` before running these tests?

Resolving patch:
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -61,6 +61,7 @@
 import spack.schema.environment
 import spack.store
 import spack.subprocess_context
+import spack.user_environment
 import spack.util.path
 from spack.error import NoHeadersError, NoLibrariesError
 from spack.util.cpus import cpus_available
@@ -69,6 +70,7 @@
     env_flag,
     filter_system_paths,
     get_path,
+    inspect_path,
     is_system_path,
     preserve_environment,
     system_dirs,
@@ -781,6 +783,13 @@ def setup_package(pkg, dirty, context='build'):
                       "config to assume that the package is part of the system"
                       " includes and omit it when invoked with '--cflags'.")
     elif context == 'test':
+        env.extend(
+            inspect_path(
+                pkg.spec.prefix,
+                spack.user_environment.prefix_inspections(pkg.spec.platform),
+                exclude=is_system_path
+            )
+        )
         pkg.setup_run_environment(env)
         env.prepend_path('PATH', '.')
 


Test patch:
Repository: spack/spack

Issue:
Possible bug due to typo in "subprocess_context.py"
I think these two lines:
https://github.com/spack/spack/blob/f92580240e8e4b50b68d4a26a0c6286a096dcd4f/lib/spack/spack/subprocess_context.py#L135-L136

are incorrect, since we have a double loop onto the same list and `patch` is never used. Not sure at the moment (didn't look into it carefully) if the fix is to remove the outer loop or iterate over `patch` instead of `patches` in the inner loop. 



Discussion:

Resolving patch:
diff --git a/lib/spack/spack/subprocess_context.py b/lib/spack/spack/subprocess_context.py
--- a/lib/spack/spack/subprocess_context.py
+++ b/lib/spack/spack/subprocess_context.py
@@ -139,16 +139,15 @@ def store_patches():
     class_patches = list()
     if not patches:
         return TestPatches(list(), list())
-    for patch in patches:
-        for target, name, _ in patches:
-            if isinstance(target, ModuleType):
-                new_val = getattr(target, name)
-                module_name = target.__name__
-                module_patches.append((module_name, name, new_val))
-            elif isinstance(target, type):
-                new_val = getattr(target, name)
-                class_fqn = '.'.join([target.__module__, target.__name__])
-                class_patches.append((class_fqn, name, new_val))
+    for target, name, _ in patches:
+        if isinstance(target, ModuleType):
+            new_val = getattr(target, name)
+            module_name = target.__name__
+            module_patches.append((module_name, name, new_val))
+        elif isinstance(target, type):
+            new_val = getattr(target, name)
+            class_fqn = '.'.join([target.__module__, target.__name__])
+            class_patches.append((class_fqn, name, new_val))
 
     return TestPatches(module_patches, class_patches)
 


Test patch:
Repository: spack/spack

Issue:
Spack tests leak active environment between tests
### Steps to reproduce

```
$ spack unit-test -k 'test_env_activate_broken_view or test_extensions'
...
============= 1 failed, 4 passed, 3022 deselected in 4.62 seconds ==============
```

This fails because `test_extensions` suddenly runs an environment aware SpackCommand that can't find certain specs in the active env.




Discussion:

Resolving patch:
diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py
--- a/lib/spack/spack/config.py
+++ b/lib/spack/spack/config.py
@@ -442,7 +442,8 @@ def pop_scope(self):
 
     @_config_mutator
     def remove_scope(self, scope_name):
-        return self.scopes.pop(scope_name)
+        """Remove scope by name; has no effect when ``scope_name`` does not exist"""
+        return self.scopes.pop(scope_name, None)
 
     @property
     def file_scopes(self):


Test patch:
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -92,24 +92,24 @@ def no_path_access(monkeypatch):
 
 
 #
-# Disable any activate Spack environment BEFORE all tests
+# Disable any active Spack environment BEFORE all tests
 #
 @pytest.fixture(scope='session', autouse=True)
 def clean_user_environment():
-    env_var = ev.spack_env_var in os.environ
-    active = ev._active_environment
+    spack_env_value = os.environ.pop(ev.spack_env_var, None)
+    with ev.deactivate_environment():
+        yield
+    if spack_env_value:
+        os.environ[ev.spack_env_var] = spack_env_value
 
-    if env_var:
-        spack_env_value = os.environ.pop(ev.spack_env_var)
-    if active:
-        ev.deactivate()
 
+#
+# Make sure global state of active env does not leak between tests.
+#
+@pytest.fixture(scope='function', autouse=True)
+def clean_test_environment():
     yield
-
-    if env_var:
-        os.environ[ev.spack_env_var] = spack_env_value
-    if active:
-        ev.activate(active)
+    ev.deactivate()
 
 
 def _verify_executables_noop(*args):
Repository: spack/spack

Issue:
Installation issue: bedops
### Steps to reproduce the issue

```console
$ spack install bedops
==> Installing bedops-2.4.40-ta56zs2zrm5xquuw4addbzchbcapvogz
==> No binary for bedops-2.4.40-ta56zs2zrm5xquuw4addbzchbcapvogz found: installing from source
==> Fetching https://github.com/bedops/bedops/archive/v2.4.40.tar.gz
==> Error: ChecksumError: sha256 checksum failed for /tmp/pan14001/spack-stage/spack-stage-bedops-2.4.40-ta56zs2zrm5xquuw4addbzchbcapvogz/v2.4.40.tar.gz
    Expected 0670f9ce2da4b68ab13f82c023c84509c7fce5aeb5df980c385fac76eabed4fb but got 8c01db76669dc58c595e2e1b9bdb6d462f3363fc569b15c460a63a63b8b6bf30

/opt/spack/lib/spack/spack/package.py:1380, in do_fetch:
       1377        self.stage.fetch(mirror_only, err_msg=err_msg)
       1378        self._fetch_time = time.time() - start_time
       1379
  >>   1380        if checksum and self.version in self.versions:
       1381            self.stage.check()
       1382
       1383        self.stage.cache_local()
```



### Information on your system

```console
$ spack debug report
* **Spack:** 0.16.2-4243-f6eb16982a
* **Python:** 3.6.9
* **Platform:** linux-ubuntu18.04-zen
* **Concretizer:** original
```

### Additional information

N/A

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/bedops/package.py b/var/spack/repos/builtin/packages/bedops/package.py
--- a/var/spack/repos/builtin/packages/bedops/package.py
+++ b/var/spack/repos/builtin/packages/bedops/package.py
@@ -15,7 +15,7 @@ class Bedops(MakefilePackage):
     homepage = "https://bedops.readthedocs.io"
     url      = "https://github.com/bedops/bedops/archive/v2.4.39.tar.gz"
 
-    version('2.4.40', sha256='0670f9ce2da4b68ab13f82c023c84509c7fce5aeb5df980c385fac76eabed4fb')
+    version('2.4.40', sha256='8c01db76669dc58c595e2e1b9bdb6d462f3363fc569b15c460a63a63b8b6bf30')
     version('2.4.39', sha256='f8bae10c6e1ccfb873be13446c67fc3a54658515fb5071663883f788fc0e4912')
     version('2.4.35', sha256='da0265cf55ef5094834318f1ea4763d7a3ce52a6900e74f532dd7d3088c191fa')
     version('2.4.34', sha256='533a62a403130c048d3378e6a975b73ea88d156d4869556a6b6f58d90c52ed95')


Test patch:
Repository: spack/spack

Issue:
Installation issue: amdlibflame
`amdlibflame` doesn't have a build dependency on `python +pythoncmd` so it fails to build when a `python` binary/symlink isn't present.

### Steps to reproduce the issue

```console
$ spack install amdlibflame
(...)
==> Installing amdlibflame-3.0-bycjukuru44crh5dkhekz2ftp6p3yefy
==> No binary for amdlibflame-3.0-bycjukuru44crh5dkhekz2ftp6p3yefy found: installing from source
==> Using cached archive: /home/bc/spack/var/spack/cache/_source-cache/archive/d9/d94e08b688539748571e6d4c1ec1ce42732eac18bd75de989234983c33f01ced.tar.gz
==> Applied patch /home/bc/spack/var/spack/repos/builtin/packages/amdlibflame/cray-compiler-wrapper.patch
==> amdlibflame: Executing phase: 'autoreconf'
==> amdlibflame: Executing phase: 'configure'
==> amdlibflame: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j16' 'V=1'

1 error found in build log:
     248    You may now run 'make' to build all libflame libraries and then 'make install'
     249    to install the libraries.
     250    
     251    ==> amdlibflame: Executing phase: 'build'
     252    ==> [2021-09-09-20:32:26.584483] 'make' '-j16' 'V=1'
     253    (huge line here...)
  >> 254    /usr/bin/env: 'python': No such file or directory
     255    make: *** [Makefile:462: include/x86_64-unknown-linux-gnu/FLAME.h] Error 127
```

### Information on your system

```console
$ spack debug report
* **Spack:** 0.16.2-4209-9084ad69b4
* **Python:** 3.6.8
* **Platform:** linux-rocky8-zen2
* **Concretizer:** original
```

Rocky 8.4 python externals in packages.yaml:
```
  python:
    externals:
    - spec: python@2.7.18+bz2+ctypes+dbm~lzma+nis+pyexpat+readline+sqlite3+ssl~tix~tkinter+uuid+zlib
      prefix: /usr
    - spec: python@3.6.8+bz2+ctypes+dbm+lzma+nis+pyexpat+readline+sqlite3+ssl~tix~tkinter+uuid+zlib
      prefix: /usr
```

### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/7140267/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/7140268/spack-build-env.txt)


### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
@amd-toolchain-support please take a look at this.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/amdlibflame/package.py b/var/spack/repos/builtin/packages/amdlibflame/package.py
--- a/var/spack/repos/builtin/packages/amdlibflame/package.py
+++ b/var/spack/repos/builtin/packages/amdlibflame/package.py
@@ -44,6 +44,8 @@ class Amdlibflame(LibflameBase):
 
     provides('flame@5.2', when='@2:')
 
+    depends_on('python+pythoncmd', type='build')
+
     @property
     def lapack_libs(self):
         """find lapack_libs function"""


Test patch:
Repository: spack/spack

Issue:
librsb update to 1.2.0.10
### Summary

Hi!
librsb-1.2.0.10 is out, at https://sourceforge.net/projects/librsb/files/
it would be good to update its package.py.

### Rationale

_No response_

### Description

_No response_

### Additional information

_No response_

### 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:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/librsb/package.py b/var/spack/repos/builtin/packages/librsb/package.py
--- a/var/spack/repos/builtin/packages/librsb/package.py
+++ b/var/spack/repos/builtin/packages/librsb/package.py
@@ -11,9 +11,10 @@ class Librsb(AutotoolsPackage):
     library for the Recursive Sparse Blocks format"""
 
     homepage = "http://librsb.sourceforge.net/"
-    url      = "http://download.sourceforge.net/librsb/librsb-1.2.0.9.tar.gz"
+    url      = "http://download.sourceforge.net/librsb/librsb-1.2.0.10.tar.gz"
     list_url = "https://sourceforge.net/projects/librsb/files/"
 
+    version('1.2.0.10',  'ec49f3f78a7c43fc9e10976593d100aa49b1863309ed8fa3ccbb7aad52d2f7b8')
     version('1.2.0.9',   'f421f5d572461601120933e3c1cfee2ca69e6ecc92cbb11baa4e86bdedd3d9fa')
     version('1.2.0.8',   '8bebd19a1866d80ade13eabfdd0f07ae7e8a485c0b975b5d15f531ac204d80cb')
 


Test patch:
Repository: spack/spack

Issue:
CentOS 6 image doesn't build with clingo on Dockerhub
### Steps to reproduce

Has to do with failure on centos:6

```
Step 17/19 : RUN spack spec hdf5+mpi
 ---> Running in 8335d48ff53f
==> Warning: Spack will not check SSL certificates. You need to update your Python to enable certificate verification.
==> Warning: Spack will not check SSL certificates. You need to update your Python to enable certificate verification.
==> Warning: the original concretizer is currently being used.
        Upgrade to "clingo" at your earliest convenience. The original concretizer will be removed from Spack starting at v0.18.0
==> Error: cannot bootstrap the "clingo" Python module from spec "clingo-bootstrap@spack+python %gcc target=x86_64"
Input spec
--------------------------------
hdf5+mpi

Concretized
--------------------------------
==> Bootstrapping clingo from pre-built binaries
The command 'docker-shell spack spec hdf5+mpi' returned a non-zero code: 3
```

---

So it bootstraps *during* concretization?


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/schema/container.py b/lib/spack/spack/schema/container.py
--- a/lib/spack/spack/schema/container.py
+++ b/lib/spack/spack/schema/container.py
@@ -12,8 +12,7 @@
             'type': 'string',
             'enum': ['ubuntu:18.04',
                      'ubuntu:16.04',
-                     'centos:7',
-                     'centos:6']
+                     'centos:7']
         },
         'spack': {
             'type': 'string',


Test patch:
Repository: spack/spack

Issue:
Installation issue: py-torchvision can't fetch src from master branch
### Steps to reproduce the issue

```console
$ spack install py-torchvision@master ^/q7k2fue
==> Installing py-torchvision-master-sqxyxoywdk4g5xaffbdqmrjdavwsvu6i
==> No binary for py-torchvision-master-sqxyxoywdk4g5xaffbdqmrjdavwsvu6i found: installing from source
warning: Could not find remote branch master to clone.
fatal: Remote branch master not found in upstream origin
==> Error: FetchError: All fetchers failed

/data/public/spack/lib/spack/spack/package.py:1331, in do_fetch:
       1328                                 self.spec.format('{name}{@version}'), ck_msg)
       1329
       1330        self.stage.create()
  >>   1331        err_msg = None if not self.manual_download else self.download_instr
       1332        self.stage.fetch(mirror_only, err_msg=err_msg)
       1333        self._fetch_time = time.time() - start_time
       1334
```

The deps with hash `q7k2fue` is py-torch installed by spec `py-torch@master %gcc@8.5.0 cuda_arch=80 ^cuda@11.4.0 ^nccl@2.11.4-1 ^cudnn@8.2.2.26-11.4-linux-x64`

### Information on your system

* **Spack:** 0.16.2
* **Python:** 3.8.6
* **Platform:** linux-ubuntu18.04-zen2

### Additional information

Since I found the src repo of "py-torchvision" has renamed its main branch from `master` to `main`.
And spack still clone its source from "master" branch.
So I think this bug just needs a little modification on `package.py`.
@adamjstewart 

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [ ] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-torchvision/package.py b/var/spack/repos/builtin/packages/py-torchvision/package.py
--- a/var/spack/repos/builtin/packages/py-torchvision/package.py
+++ b/var/spack/repos/builtin/packages/py-torchvision/package.py
@@ -14,7 +14,8 @@ class PyTorchvision(PythonPackage):
 
     maintainers = ['adamjstewart']
 
-    version('master', branch='master')
+    version('main', branch='main')
+    version('master', branch='main', deprecated=True)
     version('0.10.0', sha256='82bb2c2b03d8a65f4ea74bb0ee5566b0876a1992aceefb1e11475c7b5d2e857b')
     version('0.9.1', sha256='79964773729880e0eee0e6af13f336041121d4cc8491a3e2c0e5f184cac8a718')
     version('0.9.0', sha256='9351ed92aded632f8c7f59dfadac13c191a834babe682f5785ea47e6fcf6b472')


Test patch:
Repository: spack/spack

Issue:
amdgpu_target_sram_ecc no longer used in rocfft
The `amdgpu_target_sram_ecc` variant has no effect in newer versions of `rocfft`, we should probably add conflicts for all values other than `none` for the versions where it doesn't apply.



Discussion:
the AMDGPU_TARGETS_SRAM_ECC is removed from the 4.1.0 onwards ..i looked at the cmakelists.txt for rocfft for rocm-4.1.0 and i see it is removed. 
in that case, l propose to do the following change in the recipe. - Line 65-66 ,
 if tgt_sram[0] != 'none' and if spec.satisfies('@3.9.0,4.0.0'):' :
            args.append(self.define('AMDGPU_TARGETS_SRAM_ECC', ";".join(tgt_sram)))


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/rocfft/package.py b/var/spack/repos/builtin/packages/rocfft/package.py
--- a/var/spack/repos/builtin/packages/rocfft/package.py
+++ b/var/spack/repos/builtin/packages/rocfft/package.py
@@ -62,7 +62,7 @@ def cmake_args(self):
         # From version 3.9 and above we have AMDGPU_TARGETS_SRAM_ECC
         tgt_sram = self.spec.variants['amdgpu_target_sram_ecc'].value
 
-        if tgt_sram[0] != 'none' and '@3.9.0:' in self.spec:
+        if tgt_sram[0] != 'none' and self.spec.satisfies('@3.9.0:4.0.0'):
             args.append(self.define('AMDGPU_TARGETS_SRAM_ECC', ";".join(tgt_sram)))
 
         # See https://github.com/ROCmSoftwarePlatform/rocFFT/issues/322


Test patch:
Repository: spack/spack

Issue:
Spack replaces symlinked spack.yaml with a copy
### Steps to reproduce

For development, I need to frequently update the definition of environment (i.e. `spack.yaml`). I keep it in git repo, and symlink it from there to `var/spack/environments/<name>`. However, each time I concretize the environment, the symlink is replaced with a copy of file.

Simple reproducer:
1. Create some environment:
```
$ spack env create test
$ spack -e test add pythia8
```

2. Replace `spack.yaml` with a symlink
```
$ mv var/spack/environments/test/spack.yaml ~
$ ln -s ~/spack.yaml var/spack/environments/test/spack.yaml
$ file var/spack/environments/test/spack.yaml
var/spack/environments/test/spack.yaml: symbolic link to /home/razumov/spack.yaml
```

3. Concretize the environment - the symlink is replaced with a copy:
```
$ spack -e test concretize
$ file var/spack/environments/test/spack.yaml
var/spack/environments/test/spack.yaml: ASCII text
```

### Error message

_No response_

### Information on your system

The behavior is platform-independent, obviously

* **Spack:** 0.16.3-4386-71378bcf39
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.10-skylake
* **Concretizer:** clingo


### General information

- [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/environment.py b/lib/spack/spack/environment.py
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -1944,7 +1944,7 @@ def _update_and_write_manifest(self, raw_yaml_dict, yaml_dict):
         written = os.path.exists(self.manifest_path)
         if changed or not written:
             self.raw_yaml = copy.deepcopy(self.yaml)
-            with fs.write_tmp_and_move(self.manifest_path) as f:
+            with fs.write_tmp_and_move(os.path.realpath(self.manifest_path)) as f:
                 _write_yaml(self.yaml, f)
 
     def __enter__(self):


Test patch:
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -248,6 +248,25 @@ def test_env_install_same_spec_twice(install_mockery, mock_fetch):
         assert 'already installed' in out
 
 
+def test_env_definition_symlink(install_mockery, mock_fetch, tmpdir):
+    filepath = str(tmpdir.join('spack.yaml'))
+    filepath_mid = str(tmpdir.join('spack_mid.yaml'))
+
+    env('create', 'test')
+    e = ev.read('test')
+    e.add('mpileaks')
+
+    os.rename(e.manifest_path, filepath)
+    os.symlink(filepath, filepath_mid)
+    os.symlink(filepath_mid, e.manifest_path)
+
+    e.concretize()
+    e.write()
+
+    assert os.path.islink(e.manifest_path)
+    assert os.path.islink(filepath_mid)
+
+
 def test_env_install_two_specs_same_dep(
         install_mockery, mock_fetch, tmpdir, capsys):
     """Test installation of two packages that share a dependency with no