spack external find: change default behavior (#29031)

See https://github.com/spack/spack/issues/25353#issuecomment-1041868116

This commit changes the default behavior of
```
$ spack external find
```
from searching all the possible packages Spack knows about to
search only for the ones tagged as being a "build-tool".

It also introduces a `--all` option to restore the old behavior.
This commit is contained in:
Massimiliano Culpo
2022-02-18 19:51:01 +01:00
committed by GitHub
parent 2ed52d32c7
commit 7fd94fc4bc
23 changed files with 63 additions and 8 deletions

View File

@@ -39,8 +39,17 @@ def setup_parser(subparser):
'--scope', choices=scopes, metavar=scopes_metavar,
default=spack.config.default_modify_scope('packages'),
help="configuration scope to modify")
find_parser.add_argument(
'--all', action='store_true',
help="search for all packages that Spack knows about"
)
spack.cmd.common.arguments.add_common_arguments(find_parser, ['tags'])
find_parser.add_argument('packages', nargs=argparse.REMAINDER)
find_parser.epilog = (
'The search is by default on packages tagged with the "build-tools" or '
'"core-packages" tags. Use the --all option to search for every possible '
'package Spack knows how to find.'
)
sp.add_parser(
'list', help='list detectable packages, by repository and name'
@@ -48,6 +57,14 @@ def setup_parser(subparser):
def external_find(args):
# If the user didn't specify anything, search for build tools by default
if not args.tags and not args.all and not args.packages:
args.tags = ['core-packages', 'build-tools']
# If the user specified both --all and --tag, then --all has precedence
if args.all and args.tags:
args.tags = []
# Construct the list of possible packages to be detected
packages_to_check = []
@@ -64,9 +81,10 @@ def external_find(args):
# Since tags are cached it's much faster to construct what we need
# to search directly, rather than filtering after the fact
packages_to_check = [
spack.repo.get(pkg) for pkg in
spack.repo.path.packages_with_tags(*args.tags)
spack.repo.get(pkg) for tag in args.tags for pkg in
spack.repo.path.packages_with_tags(tag)
]
packages_to_check = list(set(packages_to_check))
# If the list of packages is empty, search for every possible package
if not args.tags and not packages_to_check:

View File

@@ -124,7 +124,7 @@ def test_find_external_cmd_not_buildable(
def test_find_external_cmd_full_repo(
mutable_config, working_env, mock_executable, mutable_mock_repo):
"""Test invoking 'spack external find' with no additional arguments, which
"""Test invoking 'spack external find --all' with no additional arguments
iterates through each package in the repository.
"""
@@ -134,7 +134,7 @@ def test_find_external_cmd_full_repo(
prefix = os.path.dirname(os.path.dirname(exe_path1))
os.environ['PATH'] = ':'.join([os.path.dirname(exe_path1)])
external('find')
external('find', '--all')
pkgs_cfg = spack.config.get('packages')
pkg_cfg = pkgs_cfg['find-externals1']