summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoriarspider <iarspider@gmail.com>2020-05-08 01:34:36 +0200
committerGitHub <noreply@github.com>2020-05-07 18:34:36 -0500
commit08f449ae9a4b18e5a8c1056278b6e925d1760678 (patch)
treeced96817d2c8537f5f23b11ce3865c9e3463d293 /lib
parentbff5708a4f9496487bb443acdbe0e387122c892e (diff)
downloadspack-08f449ae9a4b18e5a8c1056278b6e925d1760678.tar.gz
spack-08f449ae9a4b18e5a8c1056278b6e925d1760678.tar.bz2
spack-08f449ae9a4b18e5a8c1056278b6e925d1760678.tar.xz
spack-08f449ae9a4b18e5a8c1056278b6e925d1760678.zip
"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>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/checksum.py9
-rw-r--r--lib/spack/spack/cmd/create.py2
-rw-r--r--lib/spack/spack/stage.py11
3 files changed, 18 insertions, 4 deletions
diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py
index eaeaf5337f..97e7833af0 100644
--- a/lib/spack/spack/cmd/checksum.py
+++ b/lib/spack/spack/cmd/checksum.py
@@ -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()
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py
index 304b531b49..7d12dc98a7 100644
--- a/lib/spack/spack/cmd/create.py
+++ b/lib/spack/spack/cmd/create.py
@@ -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
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index 54d370a50d..5cac9e32a1 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -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,8 +790,11 @@ def get_checksums_for_versions(
for v in sorted_versions]))
print()
- archives_to_fetch = tty.get_number(
- "How many would you like to checksum?", default=1, abort='q')
+ 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')
if not archives_to_fetch:
tty.die("Aborted.")