Add --exclude option to 'spack external find' (#35013)

* Add --exclude option to 'spack external find' to ignore user-specified external packages
* Update bash completion arg order for external find

Co-authored-by: Todd Gamblin <tgamblin@llnl.gov>
This commit is contained in:
Alex Richert 2023-01-21 15:43:20 -08:00 committed by GitHub
parent da1165ffa3
commit ce8727cece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -38,6 +38,11 @@ def setup_parser(subparser):
default=False,
help="packages with detected externals won't be built with Spack",
)
find_parser.add_argument(
"--exclude",
action="append",
help="packages to exclude from search",
)
find_parser.add_argument(
"-p",
"--path",
@ -151,6 +156,10 @@ def external_find(args):
if not args.tags and not pkg_cls_to_check:
pkg_cls_to_check = list(spack.repo.path.all_package_classes())
# If the user specified any packages to exclude from external find, add them here
if args.exclude:
pkg_cls_to_check = [pkg for pkg in pkg_cls_to_check if pkg.name not in args.exclude]
detected_packages = spack.detection.by_executable(pkg_cls_to_check, path_hints=args.path)
detected_packages.update(spack.detection.by_library(pkg_cls_to_check, path_hints=args.path))

View File

@ -162,6 +162,21 @@ def test_find_external_cmd_full_repo(
assert {"spec": "find-externals1@1.foo", "prefix": prefix} in pkg_externals
def test_find_external_cmd_exclude(
mutable_config, working_env, mock_executable, mutable_mock_repo, _platform_executables
):
"""Test invoking 'spack external find --all --exclude', to ensure arbitary
external packages can be ignored.
"""
exe_path1 = mock_executable("find-externals1-exe", output="echo find-externals1 version 1.foo")
os.environ["PATH"] = os.pathsep.join([os.path.dirname(exe_path1)])
external("find", "--all", "--exclude=find-externals1")
pkgs_cfg = spack.config.get("packages")
assert "find-externals1" not in pkgs_cfg.keys()
def test_find_external_no_manifest(
mutable_config,
working_env,

View File

@ -1031,7 +1031,7 @@ _spack_external() {
_spack_external_find() {
if $list_options
then
SPACK_COMPREPLY="-h --help --not-buildable -p --path --scope --all -t --tag"
SPACK_COMPREPLY="-h --help --not-buildable --exclude -p --path --scope --all -t --tag"
else
_all_packages
fi