spack versions: only list safe versions (#10004)
* spack versions: only list safe versions * Add unit tests for spack versions -s
This commit is contained in:
		
				
					committed by
					
						
						Todd Gamblin
					
				
			
			
				
	
			
			
			
						parent
						
							450b0e3059
						
					
				
				
					commit
					72a41a4918
				
			@@ -9,6 +9,7 @@
 | 
			
		||||
import llnl.util.tty as tty
 | 
			
		||||
 | 
			
		||||
import spack.repo
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
description = "list available versions of a package"
 | 
			
		||||
section = "packaging"
 | 
			
		||||
@@ -18,32 +19,42 @@
 | 
			
		||||
def setup_parser(subparser):
 | 
			
		||||
    subparser.add_argument('package', metavar='PACKAGE',
 | 
			
		||||
                           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):
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
    if not safe_versions:
 | 
			
		||||
        print('  Found no versions for {0}'.format(pkg.name))
 | 
			
		||||
        tty.debug('Manually add versions to the package.')
 | 
			
		||||
        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('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()
 | 
			
		||||
    remote_versions = set(fetched_versions).difference(safe_versions)
 | 
			
		||||
 | 
			
		||||
    if not remote_versions:
 | 
			
		||||
        if not fetched_versions:
 | 
			
		||||
            print('  Found no versions for {0}'.format(pkg.name))
 | 
			
		||||
            tty.debug('Check the list_url and list_depth attributes of the '
 | 
			
		||||
                      'package to help Spack find versions.')
 | 
			
		||||
        else:
 | 
			
		||||
            print('  Found no unchecksummed versions for {0}'.format(pkg.name))
 | 
			
		||||
        if sys.stdout.isatty():
 | 
			
		||||
            if not fetched_versions:
 | 
			
		||||
                tty.warn('Found no versions for {0}'.format(pkg.name))
 | 
			
		||||
                tty.debug('Check the list_url and list_depth attributes of '
 | 
			
		||||
                          'the package to help Spack find versions.')
 | 
			
		||||
            else:
 | 
			
		||||
                tty.warn('Found no unchecksummed versions for {0}'.format(
 | 
			
		||||
                    pkg.name))
 | 
			
		||||
    else:
 | 
			
		||||
        colify(sorted(remote_versions, reverse=True), indent=2)
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,12 @@
 | 
			
		||||
versions = SpackCommand('versions')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_safe_versions():
 | 
			
		||||
    """Only test the safe versions of a package."""
 | 
			
		||||
 | 
			
		||||
    versions('--safe-only', 'zlib')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.mark.network
 | 
			
		||||
def test_remote_versions():
 | 
			
		||||
    """Test a package for which remote versions should be available."""
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user