spack versions: only list safe versions (#10004)
* spack versions: only list safe versions * Add unit tests for spack versions -s
This commit is contained in:
parent
450b0e3059
commit
72a41a4918
3 changed files with 28 additions and 11 deletions
|
@ -9,6 +9,7 @@
|
|||
import llnl.util.tty as tty
|
||||
|
||||
import spack.repo
|
||||
import sys
|
||||
|
||||
description = "list available versions of a package"
|
||||
section = "packaging"
|
||||
|
@ -18,32 +19,42 @@
|
|||
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)
|
||||
|
||||
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))
|
||||
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)
|
||||
|
||||
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 sys.stdout.isatty():
|
||||
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.')
|
||||
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:
|
||||
print(' Found no unchecksummed versions for {0}'.format(pkg.name))
|
||||
tty.warn('Found no unchecksummed versions for {0}'.format(
|
||||
pkg.name))
|
||||
else:
|
||||
colify(sorted(remote_versions, reverse=True), indent=2)
|
||||
|
|
|
@ -10,6 +10,12 @@
|
|||
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."""
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue