diff options
author | vvolkl <valentin.volkl@cern.ch> | 2020-12-07 16:29:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 09:29:10 -0600 |
commit | ed258ca9e9d4f88ed36cd87b21ae24091f516fc7 (patch) | |
tree | 51b02d40c55a99f0d452e9e1c69037f8c3b3ca20 /lib | |
parent | b4ed4fb226f3a43ba2b021ffea2308d864f19866 (diff) | |
download | spack-ed258ca9e9d4f88ed36cd87b21ae24091f516fc7.tar.gz spack-ed258ca9e9d4f88ed36cd87b21ae24091f516fc7.tar.bz2 spack-ed258ca9e9d4f88ed36cd87b21ae24091f516fc7.tar.xz spack-ed258ca9e9d4f88ed36cd87b21ae24091f516fc7.zip |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/versions.py | 52 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/versions.py | 25 |
2 files changed, 61 insertions, 16 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.""" |