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:
parent
b4ed4fb226
commit
ed258ca9e9
4 changed files with 80 additions and 18 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
import spack.cmd.common.arguments as arguments
|
||||
import spack.repo
|
||||
from spack.version import VersionList, ver
|
||||
|
||||
description = "list available versions of a package"
|
||||
section = "packaging"
|
||||
|
@ -19,8 +20,17 @@
|
|||
|
||||
|
||||
def setup_parser(subparser):
|
||||
subparser.add_argument('-s', '--safe-only', action='store_true',
|
||||
help='only list safe versions of the package')
|
||||
output = subparser.add_mutually_exclusive_group()
|
||||
output.add_argument('-s', '--safe', action='store_true',
|
||||
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(
|
||||
'-c', '--concurrency', default=32, type=int,
|
||||
help='number of concurrent requests'
|
||||
|
@ -31,26 +41,38 @@ def setup_parser(subparser):
|
|||
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:
|
||||
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
|
||||
tty.warn('"--safe-only" is deprecated. Use "--safe" instead.')
|
||||
args.safe = args.safe_only
|
||||
|
||||
if sys.stdout.isatty():
|
||||
tty.msg('Remote versions (not yet checksummed):')
|
||||
if not (args.remote or args.new):
|
||||
if sys.stdout.isatty():
|
||||
tty.msg('Safe versions (already checksummed):')
|
||||
|
||||
if not safe_versions:
|
||||
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:
|
||||
return
|
||||
|
||||
fetched_versions = pkg.fetch_remote_versions(args.concurrency)
|
||||
remote_versions = set(fetched_versions).difference(safe_versions)
|
||||
|
||||
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():
|
||||
tty.msg('Remote versions (not yet checksummed):')
|
||||
remote_versions = set(fetched_versions).difference(safe_versions)
|
||||
|
||||
if not remote_versions:
|
||||
if sys.stdout.isatty():
|
||||
|
|
|
@ -10,10 +10,18 @@
|
|||
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():
|
||||
"""Only test the safe versions of a package."""
|
||||
|
||||
versions('--safe-only', 'zlib')
|
||||
versions('--safe', 'zlib')
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
|
@ -23,6 +31,21 @@ def test_remote_versions():
|
|||
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
|
||||
def test_no_versions():
|
||||
"""Test a package for which no remote versions are available."""
|
||||
|
|
|
@ -1649,7 +1649,7 @@ _spack_verify() {
|
|||
_spack_versions() {
|
||||
if $list_options
|
||||
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
|
||||
_all_packages
|
||||
fi
|
||||
|
|
17
var/spack/repos/builtin.mock/packages/brillig/package.py
Normal file
17
var/spack/repos/builtin.mock/packages/brillig/package.py
Normal 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')
|
Loading…
Reference in a new issue