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 llnl.util.tty as tty
|
||||||
|
|
||||||
import spack.repo
|
import spack.repo
|
||||||
|
import sys
|
||||||
|
|
||||||
description = "list available versions of a package"
|
description = "list available versions of a package"
|
||||||
section = "packaging"
|
section = "packaging"
|
||||||
|
@ -18,32 +19,42 @@
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('package', metavar='PACKAGE',
|
subparser.add_argument('package', metavar='PACKAGE',
|
||||||
help='package to list versions for')
|
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):
|
def versions(parser, args):
|
||||||
pkg = spack.repo.get(args.package)
|
pkg = spack.repo.get(args.package)
|
||||||
|
|
||||||
|
if sys.stdout.isatty():
|
||||||
tty.msg('Safe versions (already checksummed):')
|
tty.msg('Safe versions (already checksummed):')
|
||||||
|
|
||||||
safe_versions = pkg.versions
|
safe_versions = pkg.versions
|
||||||
|
|
||||||
if not safe_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.')
|
tty.debug('Manually add versions to the package.')
|
||||||
else:
|
else:
|
||||||
colify(sorted(safe_versions, reverse=True), indent=2)
|
colify(sorted(safe_versions, reverse=True), indent=2)
|
||||||
|
|
||||||
|
if args.safe_only:
|
||||||
|
return
|
||||||
|
|
||||||
|
if sys.stdout.isatty():
|
||||||
tty.msg('Remote versions (not yet checksummed):')
|
tty.msg('Remote versions (not yet checksummed):')
|
||||||
|
|
||||||
fetched_versions = pkg.fetch_remote_versions()
|
fetched_versions = pkg.fetch_remote_versions()
|
||||||
remote_versions = set(fetched_versions).difference(safe_versions)
|
remote_versions = set(fetched_versions).difference(safe_versions)
|
||||||
|
|
||||||
if not remote_versions:
|
if not remote_versions:
|
||||||
|
if sys.stdout.isatty():
|
||||||
if not fetched_versions:
|
if not fetched_versions:
|
||||||
print(' Found no versions for {0}'.format(pkg.name))
|
tty.warn('Found no versions for {0}'.format(pkg.name))
|
||||||
tty.debug('Check the list_url and list_depth attributes of the '
|
tty.debug('Check the list_url and list_depth attributes of '
|
||||||
'package to help Spack find versions.')
|
'the package to help Spack find versions.')
|
||||||
else:
|
else:
|
||||||
print(' Found no unchecksummed versions for {0}'.format(pkg.name))
|
tty.warn('Found no unchecksummed versions for {0}'.format(
|
||||||
|
pkg.name))
|
||||||
else:
|
else:
|
||||||
colify(sorted(remote_versions, reverse=True), indent=2)
|
colify(sorted(remote_versions, reverse=True), indent=2)
|
||||||
|
|
|
@ -10,6 +10,12 @@
|
||||||
versions = SpackCommand('versions')
|
versions = SpackCommand('versions')
|
||||||
|
|
||||||
|
|
||||||
|
def test_safe_versions():
|
||||||
|
"""Only test the safe versions of a package."""
|
||||||
|
|
||||||
|
versions('--safe-only', 'zlib')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.network
|
@pytest.mark.network
|
||||||
def test_remote_versions():
|
def test_remote_versions():
|
||||||
"""Test a package for which remote versions should be available."""
|
"""Test a package for which remote versions should be available."""
|
||||||
|
|
|
@ -1181,7 +1181,7 @@ function _spack_use {
|
||||||
function _spack_versions {
|
function _spack_versions {
|
||||||
if $list_options
|
if $list_options
|
||||||
then
|
then
|
||||||
compgen -W "-h --help" -- "$cur"
|
compgen -W "-h --help -s --safe-only" -- "$cur"
|
||||||
else
|
else
|
||||||
compgen -W "$(_all_packages)" -- "$cur"
|
compgen -W "$(_all_packages)" -- "$cur"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue