Add "spack versions --new" flag to only show new versions (#20030)

* [cmd versions] add spack versions --new flag to only fetch new versions

format

[cmd versions] rename --latest to --newest and add --remote-only

[cmd versions] add tests for --remote-only and --new

format

[cmd versions] update shell tab completion

[cmd versions] remove test for --remote-only --new which gives empty output

[cmd versions] final rename

format

* add brillig mock package

* add test for spack versions --new

* [brillig] format

* [versions] increase test coverage

* Update lib/spack/spack/cmd/versions.py

Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>

* Update lib/spack/spack/cmd/versions.py

Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>

Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
vvolkl 2020-12-07 16:29:10 +01:00 committed by GitHub
parent b4ed4fb226
commit ed258ca9e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 18 deletions

View file

@ -12,6 +12,7 @@
import spack.cmd.common.arguments as arguments import spack.cmd.common.arguments as arguments
import spack.repo import spack.repo
from spack.version import VersionList, ver
description = "list available versions of a package" description = "list available versions of a package"
section = "packaging" section = "packaging"
@ -19,8 +20,17 @@
def setup_parser(subparser): def setup_parser(subparser):
subparser.add_argument('-s', '--safe-only', action='store_true', output = subparser.add_mutually_exclusive_group()
output.add_argument('-s', '--safe', action='store_true',
help='only list safe versions of the package') help='only list safe versions of the package')
output.add_argument('--safe-only', action='store_true',
help='[deprecated] only list safe versions '
'of the package')
output.add_argument('-r', '--remote', action='store_true',
help='only list remote versions of the package')
output.add_argument('-n', '--new', action='store_true',
help='only list remote versions newer than '
'the latest checksummed version')
subparser.add_argument( subparser.add_argument(
'-c', '--concurrency', default=32, type=int, '-c', '--concurrency', default=32, type=int,
help='number of concurrent requests' help='number of concurrent requests'
@ -31,11 +41,16 @@ def setup_parser(subparser):
def versions(parser, args): def versions(parser, args):
pkg = spack.repo.get(args.package) pkg = spack.repo.get(args.package)
safe_versions = pkg.versions
if args.safe_only:
tty.warn('"--safe-only" is deprecated. Use "--safe" instead.')
args.safe = args.safe_only
if not (args.remote or args.new):
if sys.stdout.isatty(): if sys.stdout.isatty():
tty.msg('Safe versions (already checksummed):') tty.msg('Safe versions (already checksummed):')
safe_versions = pkg.versions
if not safe_versions: if not safe_versions:
if sys.stdout.isatty(): if sys.stdout.isatty():
tty.warn('Found no versions for {0}'.format(pkg.name)) tty.warn('Found no versions for {0}'.format(pkg.name))
@ -43,13 +58,20 @@ def versions(parser, args):
else: else:
colify(sorted(safe_versions, reverse=True), indent=2) colify(sorted(safe_versions, reverse=True), indent=2)
if args.safe_only: if args.safe:
return return
fetched_versions = pkg.fetch_remote_versions(args.concurrency)
if args.new:
if sys.stdout.isatty():
tty.msg('New remote versions (not yet checksummed):')
highest_safe_version = VersionList(safe_versions).highest_numeric()
remote_versions = set([ver(v) for v in set(fetched_versions)
if v > highest_safe_version])
else:
if sys.stdout.isatty(): if sys.stdout.isatty():
tty.msg('Remote versions (not yet checksummed):') tty.msg('Remote versions (not yet checksummed):')
fetched_versions = pkg.fetch_remote_versions(args.concurrency)
remote_versions = set(fetched_versions).difference(safe_versions) remote_versions = set(fetched_versions).difference(safe_versions)
if not remote_versions: if not remote_versions:

View file

@ -10,10 +10,18 @@
versions = SpackCommand('versions') versions = SpackCommand('versions')
def test_safe_only_versions():
"""Only test the safe versions of a package.
(Using the deprecated command line argument)
"""
versions('--safe-only', 'zlib')
def test_safe_versions(): def test_safe_versions():
"""Only test the safe versions of a package.""" """Only test the safe versions of a package."""
versions('--safe-only', 'zlib') versions('--safe', 'zlib')
@pytest.mark.network @pytest.mark.network
@ -23,6 +31,21 @@ def test_remote_versions():
versions('zlib') versions('zlib')
@pytest.mark.network
def test_remote_versions_only():
"""Test a package for which remote versions should be available."""
versions('--remote', 'zlib')
@pytest.mark.network
@pytest.mark.usefixtures('mock_packages')
def test_new_versions_only():
"""Test a package for which new versions should be available."""
versions('--new', 'brillig')
@pytest.mark.network @pytest.mark.network
def test_no_versions(): def test_no_versions():
"""Test a package for which no remote versions are available.""" """Test a package for which no remote versions are available."""

View file

@ -1649,7 +1649,7 @@ _spack_verify() {
_spack_versions() { _spack_versions() {
if $list_options if $list_options
then then
SPACK_COMPREPLY="-h --help -s --safe-only -c --concurrency" SPACK_COMPREPLY="-h --help -s --safe --safe-only -r --remote -n --new -c --concurrency"
else else
_all_packages _all_packages
fi fi

View file

@ -0,0 +1,17 @@
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
class Brillig(Package):
""" Mock package to test the spack versions command."""
homepage = "https://www.example.com"
url = "https://github.com/vvolkl/brillig/archive/v2.0.0.tar.gz"
version('2.0.0', sha256='d4bb8f1737d5a7c0321e1675cceccb59dbcb66a94f3a9dd66a37f58bc6df7f15')
version('1.0.0', sha256='fcef53f45e82b881af9a6f0530b2732cdaf8c5c60e49b27671594ea658bfe315')