"spack checksum" QoL (#14311)
* Non-interactive mode for spack checksum; allow passing 'package@version' to spack checksum * Flake8 fixes * Update checksum.py Fix typo * Update spack-completion script * Automatically set non-interactive mode if more than one version passed * Update lib/spack/spack/cmd/checksum.py Co-Authored-By: Adam J. Stewart <ajstewart426@gmail.com> * Add documentation and update spack-completion * Flake8 * Rename option * Update spack-completion * Update lib/spack/spack/cmd/checksum.py Co-Authored-By: Adam J. Stewart <ajstewart426@gmail.com> * Update checksum.py * Update stage.py * Update create.py Use batch mode when adding a new package Co-authored-by: Ivan Razumov <ivan.razumov@cern.ch> Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
This commit is contained in:
		@@ -26,6 +26,9 @@ def setup_parser(subparser):
 | 
			
		||||
    subparser.add_argument(
 | 
			
		||||
        '--keep-stage', action='store_true',
 | 
			
		||||
        help="don't clean up staging area when command completes")
 | 
			
		||||
    subparser.add_argument(
 | 
			
		||||
        '-b', '--batch', action='store_true',
 | 
			
		||||
        help="don't ask which versions to checksum")
 | 
			
		||||
    arguments.add_common_arguments(subparser, ['package'])
 | 
			
		||||
    subparser.add_argument(
 | 
			
		||||
        'versions', nargs=argparse.REMAINDER,
 | 
			
		||||
@@ -33,6 +36,11 @@ def setup_parser(subparser):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def checksum(parser, args):
 | 
			
		||||
    # Did the user pass 'package@version' string?
 | 
			
		||||
    if len(args.versions) == 0 and '@' in args.package:
 | 
			
		||||
        args.versions = [args.package.split('@')[1]]
 | 
			
		||||
        args.package = args.package.split('@')[0]
 | 
			
		||||
 | 
			
		||||
    # Make sure the user provided a package and not a URL
 | 
			
		||||
    if not valid_fully_qualified_module_name(args.package):
 | 
			
		||||
        tty.die("`spack checksum` accepts package names, not URLs.")
 | 
			
		||||
@@ -57,6 +65,7 @@ def checksum(parser, args):
 | 
			
		||||
 | 
			
		||||
    version_lines = spack.stage.get_checksums_for_versions(
 | 
			
		||||
        url_dict, pkg.name, keep_stage=args.keep_stage,
 | 
			
		||||
        batch=(args.batch or len(args.versions) > 0),
 | 
			
		||||
        fetch_options=pkg.fetch_options)
 | 
			
		||||
 | 
			
		||||
    print()
 | 
			
		||||
 
 | 
			
		||||
@@ -629,7 +629,7 @@ def get_versions(args, name):
 | 
			
		||||
 | 
			
		||||
        versions = spack.stage.get_checksums_for_versions(
 | 
			
		||||
            url_dict, name, first_stage_function=guesser,
 | 
			
		||||
            keep_stage=args.keep_stage)
 | 
			
		||||
            keep_stage=args.keep_stage, batch=True)
 | 
			
		||||
    else:
 | 
			
		||||
        versions = unhashed_versions
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -753,7 +753,7 @@ def purge():
 | 
			
		||||
 | 
			
		||||
def get_checksums_for_versions(
 | 
			
		||||
        url_dict, name, first_stage_function=None, keep_stage=False,
 | 
			
		||||
        fetch_options=None):
 | 
			
		||||
        fetch_options=None, batch=False):
 | 
			
		||||
    """Fetches and checksums archives from URLs.
 | 
			
		||||
 | 
			
		||||
    This function is called by both ``spack checksum`` and ``spack
 | 
			
		||||
@@ -767,6 +767,8 @@ def get_checksums_for_versions(
 | 
			
		||||
        first_stage_function (callable): function that takes a Stage and a URL;
 | 
			
		||||
            this is run on the stage of the first URL downloaded
 | 
			
		||||
        keep_stage (bool): whether to keep staging area when command completes
 | 
			
		||||
        batch (bool): whether to ask user how many versions to fetch (false)
 | 
			
		||||
            or fetch all versions (true)
 | 
			
		||||
        fetch_options (dict): Options used for the fetcher (such as timeout
 | 
			
		||||
            or cookies)
 | 
			
		||||
 | 
			
		||||
@@ -788,6 +790,9 @@ def get_checksums_for_versions(
 | 
			
		||||
                 for v in sorted_versions]))
 | 
			
		||||
    print()
 | 
			
		||||
 | 
			
		||||
    if batch:
 | 
			
		||||
        archives_to_fetch = len(sorted_versions)
 | 
			
		||||
    else:
 | 
			
		||||
        archives_to_fetch = tty.get_number(
 | 
			
		||||
            "How many would you like to checksum?", default=1, abort='q')
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -455,7 +455,7 @@ _spack_cd() {
 | 
			
		||||
_spack_checksum() {
 | 
			
		||||
    if $list_options
 | 
			
		||||
    then
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --keep-stage"
 | 
			
		||||
        SPACK_COMPREPLY="-h --help --keep-stage -b --batch"
 | 
			
		||||
    else
 | 
			
		||||
        _all_packages
 | 
			
		||||
    fi
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user