summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/cmd/versions.py52
-rw-r--r--lib/spack/spack/test/cmd/versions.py25
-rwxr-xr-xshare/spack/spack-completion.bash2
-rw-r--r--var/spack/repos/builtin.mock/packages/brillig/package.py17
4 files changed, 79 insertions, 17 deletions
diff --git a/lib/spack/spack/cmd/versions.py b/lib/spack/spack/cmd/versions.py
index 366307f0b2..cdded15007 100644
--- a/lib/spack/spack/cmd/versions.py
+++ b/lib/spack/spack/cmd/versions.py
@@ -12,6 +12,7 @@ import llnl.util.tty as tty
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 @@ level = "long"
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 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():
- 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)
+ tty.msg('Safe versions (already checksummed):')
- if args.safe_only:
- return
+ 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 sys.stdout.isatty():
- tty.msg('Remote versions (not yet checksummed):')
+ 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():
diff --git a/lib/spack/spack/test/cmd/versions.py b/lib/spack/spack/test/cmd/versions.py
index 1e2bcbedb3..fb1cd5d31b 100644
--- a/lib/spack/spack/test/cmd/versions.py
+++ b/lib/spack/spack/test/cmd/versions.py
@@ -10,10 +10,18 @@ from spack.main import SpackCommand
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
@@ -24,6 +32,21 @@ def test_remote_versions():
@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."""
diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash
index 7697cacdc3..1761fcb60d 100755
--- a/share/spack/spack-completion.bash
+++ b/share/spack/spack-completion.bash
@@ -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
diff --git a/var/spack/repos/builtin.mock/packages/brillig/package.py b/var/spack/repos/builtin.mock/packages/brillig/package.py
new file mode 100644
index 0000000000..497e23d795
--- /dev/null
+++ b/var/spack/repos/builtin.mock/packages/brillig/package.py
@@ -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')