diff options
author | Todd Gamblin <gamblin2@llnl.gov> | 2022-05-09 21:57:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-10 04:57:58 +0000 |
commit | a0d46304481adc7ff70c80ff17802a02a7b55f06 (patch) | |
tree | 83671e5391d5f82a832e55600c90540aed2ebb5a /lib | |
parent | 7f1659786b32dd492b062347c6ca1538a8c71495 (diff) | |
download | spack-a0d46304481adc7ff70c80ff17802a02a7b55f06.tar.gz spack-a0d46304481adc7ff70c80ff17802a02a7b55f06.tar.bz2 spack-a0d46304481adc7ff70c80ff17802a02a7b55f06.tar.xz spack-a0d46304481adc7ff70c80ff17802a02a7b55f06.zip |
bugfix: `spack pkg list` should be more picky about what's a package (#30577)
`spack pkg list` tests were broken by #29593 for cases when your `builtin.mock` repo
still has stale backup files (or, really, stale directories) sitting around. This
happens if you switch branches a lot. In this case, things like this were causing
erroneous packages in the mock listing:
```
var/spack/repos/builtin.mock/packages/
foo/
package.py~
```
- [x] make `list_packages` consider only directories with one-deep `package.py` files.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/repo.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index 0a18079574..50f0b8a9fb 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -355,9 +355,17 @@ def list_packages(rev): ref = rev.replace('...', '') rev = git('merge-base', ref, 'HEAD', output=str).strip() - output = git('ls-tree', '--name-only', rev, output=str) - return sorted(line for line in output.split('\n') - if line and not line.startswith('.')) + output = git('ls-tree', '-r', '--name-only', rev, output=str) + + # recursively list the packages directory + package_paths = [ + line.split(os.sep) for line in output.split("\n") if line.endswith("package.py") + ] + + # take the directory names with one-level-deep package files + package_names = sorted(set([line[0] for line in package_paths if len(line) == 2])) + + return package_names def diff_packages(rev1, rev2): |