spack list: add --tag flag (#32016)

* modified list.py and added functionality for --tag

* Removed long and very long, shifted rest of code above return statement

* removed results variable

* added import statement at top

* added the line accidentally deleted

* added line accidentally deleted

* changed p.name to p, added line inside if statement

* line order switched

* [@spackbot] updating style on behalf of sparkyniner

* ran update completion command

* add tests

* Update lib/spack/spack/test/cmd/list.py

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>

* [@spackbot] updating style on behalf of sparkyniner

* changed argument to mock_packages and moved code under filter by tag

* removed bad rebase code and added additional test

* [@spackbot] updating style on behalf of sparkyniner

* added line removed earlier

* added line removed earlier

* replaced function

* added more recommended changes

Co-authored-by: sairaj <sairaj@sairajs-MacBook-Pro.local>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
This commit is contained in:
sparkyniner 2022-08-21 03:39:44 +05:30 committed by GitHub
parent 8d02e2cc52
commit 21e6679056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -16,6 +16,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.tty.colify import colify from llnl.util.tty.colify import colify
import spack.cmd.common.arguments as arguments
import spack.dependency import spack.dependency
import spack.repo import spack.repo
from spack.version import VersionList from spack.version import VersionList
@ -72,6 +73,7 @@ def setup_parser(subparser):
default=False, default=False,
help="include virtual packages in list", help="include virtual packages in list",
) )
arguments.add_common_arguments(subparser, ["tags"])
def filter_by_name(pkgs, args): def filter_by_name(pkgs, args):
@ -306,6 +308,11 @@ def list(parser, args):
# Filter the set appropriately # Filter the set appropriately
sorted_packages = filter_by_name(pkgs, args) sorted_packages = filter_by_name(pkgs, args)
# If tags have been specified on the command line, filter by tags
if args.tags:
packages_with_tags = spack.repo.path.packages_with_tags(*args.tags)
sorted_packages = [p for p in sorted_packages if p in packages_with_tags]
if args.update: if args.update:
# change output stream if user asked for update # change output stream if user asked for update
if os.path.exists(args.update): if os.path.exists(args.update):

View File

@ -84,3 +84,17 @@ def test_list_update(tmpdir, mock_packages):
assert update_file.exists() assert update_file.exists()
with update_file.open() as f: with update_file.open() as f:
assert f.read() == "empty\n" assert f.read() == "empty\n"
def test_list_tags(mock_packages):
output = list("--tag", "tag1")
assert "mpich" in output
assert "mpich2" in output
output = list("--tag", "tag2")
assert "mpich\n" in output
assert "mpich2" not in output
output = list("--tag", "tag3")
assert "mpich\n" not in output
assert "mpich2" in output

View File

@ -1209,7 +1209,7 @@ _spack_license_update_copyright_year() {
_spack_list() { _spack_list() {
if $list_options if $list_options
then then
SPACK_COMPREPLY="-h --help -d --search-description --format --update -v --virtuals" SPACK_COMPREPLY="-h --help -d --search-description --format --update -v --virtuals -t --tag"
else else
_all_packages _all_packages
fi fi