summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Richert <82525672+AlexanderRichert-NOAA@users.noreply.github.com>2023-01-21 15:43:20 -0800
committerGitHub <noreply@github.com>2023-01-21 15:43:20 -0800
commitce8727cece0c25374b5629a928b0e8a1806e17d5 (patch)
treebe6230dda4d465ccdd6b841c87b98460ca1deda4
parentda1165ffa32a485b85bfa3e7a1497d5134a90fd1 (diff)
downloadspack-ce8727cece0c25374b5629a928b0e8a1806e17d5.tar.gz
spack-ce8727cece0c25374b5629a928b0e8a1806e17d5.tar.bz2
spack-ce8727cece0c25374b5629a928b0e8a1806e17d5.tar.xz
spack-ce8727cece0c25374b5629a928b0e8a1806e17d5.zip
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>
-rw-r--r--lib/spack/spack/cmd/external.py9
-rw-r--r--lib/spack/spack/test/cmd/external.py15
-rwxr-xr-xshare/spack/spack-completion.bash2
3 files changed, 25 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/external.py b/lib/spack/spack/cmd/external.py
index f079933579..51e468e1bc 100644
--- a/lib/spack/spack/cmd/external.py
+++ b/lib/spack/spack/cmd/external.py
@@ -39,6 +39,11 @@ def setup_parser(subparser):
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",
default=None,
@@ -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))
diff --git a/lib/spack/spack/test/cmd/external.py b/lib/spack/spack/test/cmd/external.py
index ad9caa98fc..9f3ff2f688 100644
--- a/lib/spack/spack/test/cmd/external.py
+++ b/lib/spack/spack/test/cmd/external.py
@@ -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,
diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash
index bdfa87acd5..423e1a96c1 100755
--- a/share/spack/spack-completion.bash
+++ b/share/spack/spack-completion.bash
@@ -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