Skip to content
Snippets Groups Projects
Commit 72a41a49 authored by Adam J. Stewart's avatar Adam J. Stewart Committed by Todd Gamblin
Browse files

spack versions: only list safe versions (#10004)

* spack versions: only list safe versions
* Add unit tests for spack versions -s
parent 450b0e30
Branches
Tags
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -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 @@ ...@@ -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)
tty.msg('Safe versions (already checksummed):') if sys.stdout.isatty():
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.debug('Manually add versions to the package.') tty.warn('Found no versions for {0}'.format(pkg.name))
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)
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() 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 not fetched_versions: if sys.stdout.isatty():
print(' Found no versions for {0}'.format(pkg.name)) if not fetched_versions:
tty.debug('Check the list_url and list_depth attributes of the ' tty.warn('Found no versions for {0}'.format(pkg.name))
'package to help Spack find versions.') tty.debug('Check the list_url and list_depth attributes of '
else: 'the package to help Spack find versions.')
print(' Found no unchecksummed versions for {0}'.format(pkg.name)) else:
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 @@ ...@@ -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 { ...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment