diff options
author | Adam J. Stewart <ajstewart426@gmail.com> | 2019-01-10 02:32:47 -0600 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2019-01-10 00:32:47 -0800 |
commit | 72a41a49181e2625d27218ecf16f0881a17cb45f (patch) | |
tree | 9e3e89222840095bc9778b8439ae4b169c607db8 | |
parent | 450b0e30599a05e13aa9070221d7bcab052eee30 (diff) | |
download | spack-72a41a49181e2625d27218ecf16f0881a17cb45f.tar.gz spack-72a41a49181e2625d27218ecf16f0881a17cb45f.tar.bz2 spack-72a41a49181e2625d27218ecf16f0881a17cb45f.tar.xz spack-72a41a49181e2625d27218ecf16f0881a17cb45f.zip |
spack versions: only list safe versions (#10004)
* spack versions: only list safe versions
* Add unit tests for spack versions -s
-rw-r--r-- | lib/spack/spack/cmd/versions.py | 31 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/versions.py | 6 | ||||
-rwxr-xr-x | share/spack/spack-completion.bash | 2 |
3 files changed, 28 insertions, 11 deletions
diff --git a/lib/spack/spack/cmd/versions.py b/lib/spack/spack/cmd/versions.py index c4b5958250..b264c1aaf0 100644 --- a/lib/spack/spack/cmd/versions.py +++ b/lib/spack/spack/cmd/versions.py @@ -9,6 +9,7 @@ from llnl.util.tty.colify import colify import llnl.util.tty as tty import spack.repo +import sys description = "list available versions of a package" section = "packaging" @@ -18,32 +19,42 @@ level = "long" def setup_parser(subparser): subparser.add_argument('package', metavar='PACKAGE', help='package to list versions for') + subparser.add_argument('-s', '--safe-only', action='store_true', + help='only list safe versions of the package') def versions(parser, args): pkg = spack.repo.get(args.package) - tty.msg('Safe versions (already checksummed):') + if sys.stdout.isatty(): + tty.msg('Safe versions (already checksummed):') safe_versions = pkg.versions if not safe_versions: - print(' Found no versions for {0}'.format(pkg.name)) - tty.debug('Manually add versions to the package.') + if sys.stdout.isatty(): + tty.warn('Found no versions for {0}'.format(pkg.name)) + tty.debug('Manually add versions to the package.') else: colify(sorted(safe_versions, reverse=True), indent=2) - tty.msg('Remote versions (not yet checksummed):') + if args.safe_only: + return + + if sys.stdout.isatty(): + tty.msg('Remote versions (not yet checksummed):') fetched_versions = pkg.fetch_remote_versions() remote_versions = set(fetched_versions).difference(safe_versions) if not remote_versions: - if not fetched_versions: - print(' Found no versions for {0}'.format(pkg.name)) - tty.debug('Check the list_url and list_depth attributes of the ' - 'package to help Spack find versions.') - else: - print(' Found no unchecksummed versions for {0}'.format(pkg.name)) + if sys.stdout.isatty(): + if not fetched_versions: + tty.warn('Found no versions for {0}'.format(pkg.name)) + tty.debug('Check the list_url and list_depth attributes of ' + 'the package to help Spack find versions.') + else: + tty.warn('Found no unchecksummed versions for {0}'.format( + pkg.name)) else: colify(sorted(remote_versions, reverse=True), indent=2) diff --git a/lib/spack/spack/test/cmd/versions.py b/lib/spack/spack/test/cmd/versions.py index 5d6574dae4..07761be1d4 100644 --- a/lib/spack/spack/test/cmd/versions.py +++ b/lib/spack/spack/test/cmd/versions.py @@ -10,6 +10,12 @@ from spack.main import SpackCommand versions = SpackCommand('versions') +def test_safe_versions(): + """Only test the safe versions of a package.""" + + versions('--safe-only', 'zlib') + + @pytest.mark.network def test_remote_versions(): """Test a package for which remote versions should be available.""" diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash index c465bd6bb6..c4113ab0da 100755 --- a/share/spack/spack-completion.bash +++ b/share/spack/spack-completion.bash @@ -1181,7 +1181,7 @@ function _spack_use { function _spack_versions { if $list_options then - compgen -W "-h --help" -- "$cur" + compgen -W "-h --help -s --safe-only" -- "$cur" else compgen -W "$(_all_packages)" -- "$cur" fi |