From ce8727cece0c25374b5629a928b0e8a1806e17d5 Mon Sep 17 00:00:00 2001 From: Alex Richert <82525672+AlexanderRichert-NOAA@users.noreply.github.com> Date: Sat, 21 Jan 2023 15:43:20 -0800 Subject: 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 --- lib/spack/spack/cmd/external.py | 9 +++++++++ lib/spack/spack/test/cmd/external.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'lib') 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 @@ -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)) 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, -- cgit v1.2.3-60-g2f50