From a0d46304481adc7ff70c80ff17802a02a7b55f06 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 9 May 2022 21:57:58 -0700 Subject: 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. --- lib/spack/spack/repo.py | 14 +++++++++++--- 1 file 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): -- cgit v1.2.3-70-g09d2