diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2024-01-04 12:35:42 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 12:35:42 -0800 |
commit | 533adaaa6d1ebea3b1e6d634d67e5185cea2fe95 (patch) | |
tree | 958201b6087e16944d17679c99ad14e571dd4608 /lib | |
parent | 3a15f57b45ec35f6d1d672cfc8b95a96a75403cd (diff) | |
download | spack-533adaaa6d1ebea3b1e6d634d67e5185cea2fe95.tar.gz spack-533adaaa6d1ebea3b1e6d634d67e5185cea2fe95.tar.bz2 spack-533adaaa6d1ebea3b1e6d634d67e5185cea2fe95.tar.xz spack-533adaaa6d1ebea3b1e6d634d67e5185cea2fe95.zip |
`spack list`: add `--namesapce` / `--repo` option (#41948)
This adds options to `spack list` that allow you to list only packages from specific
repositories/namespaces, e.g.:
```console
spack list -r builtin
```
only lists packages from the `builtin` repo, while:
```console
spack list -r myrepo -r myrepo2
```
would list packages from `myrepo` and `myrepo2`, but not from `builtin`. Note that you
can use the same argument multiple times.
You can use either `-r` / `--repo` or `-N` / `--namespace`. `-N` is there to match the
corresponding option on `spack find`.
- [x] add `-r` / `--repo` / `-N` / `--namespace` argument
- [x] add test
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/list.py | 16 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/list.py | 19 |
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 231e33dc51..eb34e38841 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -41,6 +41,16 @@ def setup_parser(subparser): help="optional case-insensitive glob patterns to filter results", ) subparser.add_argument( + "-r", + "--repo", + "-N", + "--namespace", + dest="repos", + action="append", + default=[], + help="only list packages from the specified repo/namespace", + ) + subparser.add_argument( "-d", "--search-description", action="store_true", @@ -307,7 +317,11 @@ def list(parser, args): formatter = formatters[args.format] # Retrieve the names of all the packages - pkgs = set(spack.repo.all_package_names(args.virtuals)) + repos = [spack.repo.PATH] + if args.repos: + repos = [spack.repo.PATH.get_repo(name) for name in args.repos] + pkgs = set().union(*[set(repo.all_package_names(args.virtuals)) for repo in repos]) + # Filter the set appropriately sorted_packages = filter_by_name(pkgs, args) diff --git a/lib/spack/spack/test/cmd/list.py b/lib/spack/spack/test/cmd/list.py index 848a6d20e4..a46e690cd2 100644 --- a/lib/spack/spack/test/cmd/list.py +++ b/lib/spack/spack/test/cmd/list.py @@ -3,6 +3,7 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +import os.path import sys from textwrap import dedent @@ -134,3 +135,21 @@ def test_list_count(mock_packages): assert int(output.strip()) == len( [name for name in spack.repo.all_package_names() if "py-" in name] ) + + +# def test_list_repos(mock_packages, builder_test_repository): +def test_list_repos(): + with spack.repo.use_repositories( + os.path.join(spack.paths.repos_path, "builtin.mock"), + os.path.join(spack.paths.repos_path, "builder.test"), + ): + total_pkgs = len(list().strip().split()) + + mock_pkgs = len(list("-r", "builtin.mock").strip().split()) + builder_pkgs = len(list("-r", "builder.test").strip().split()) + + assert builder_pkgs == 8 + assert total_pkgs > mock_pkgs > builder_pkgs + + both_repos = len(list("-r", "builtin.mock", "-r", "builder.test").strip().split()) + assert both_repos == total_pkgs |