Repository: spack/spack

Issue:
spack create downloads all versions
Beginning with commit 08f449ae9a4b18e5a8c1056278b6e925d1760678, PR #14311, the `spack create` command no longer prompts for the number of versions to use. Instead, it proceeds to download and checksum everything that it finds.

On an older version of spack:
```console
$ spack create -n mumax -t generic https://github.com/mumax/3/archive/v3.9.3.tar.gz
==> Using specified package name: 'mumax'
==> Found 11 versions of mumax:
  
  3.9.3_linux_cuda7.5  https://github.com/mumax/3/releases/download/v3.9.3/mumax3.9.3_linux_cuda7.5.tar.gz
  3.9.3                https://github.com/mumax/3/archive/v3.9.3.tar.gz
  3.9.2                https://github.com/mumax/3/archive/v3.9.2.tar.gz
  3.9.1c               https://github.com/mumax/3/releases/download/v3.9.1/mumax3.9.1c_linux.tar.gz
  3.9.1                https://github.com/mumax/3/archive/v3.9.1.tar.gz
  3.9c                 https://github.com/mumax/3/releases/download/v3.9c/mumax3.9c_linux.tar.gz
  3.8beta1             https://github.com/mumax/3/archive/v3.8beta1.tar.gz
  3.8                  https://github.com/mumax/3/archive/v3.8.tar.gz
  3.7beta2             https://github.com/mumax/3/archive/v3.7beta2.tar.gz
  ...
  3.7                  https://github.com/mumax/3/archive/v3.7.tar.gz

==> How many would you like to checksum? (default is 1, q to abort) 
```

With the latest develop:
```console
$ spack create -n mumax -t generic https://github.com/mumax/3/archive/v3.9.3.tar.gz
==> Using specified package name: 'mumax'
==> Found 11 versions of mumax:
  
  3.9.3_linux_cuda7.5  https://github.com/mumax/3/releases/download/v3.9.3/mumax3.9.3_linux_cuda7.5.tar.gz
  3.9.3                https://github.com/mumax/3/archive/v3.9.3.tar.gz
  3.9.2                https://github.com/mumax/3/archive/v3.9.2.tar.gz
  3.9.1c               https://github.com/mumax/3/releases/download/v3.9.1/mumax3.9.1c_linux.tar.gz
  3.9.1                https://github.com/mumax/3/archive/v3.9.1.tar.gz
  3.9c                 https://github.com/mumax/3/releases/download/v3.9c/mumax3.9c_linux.tar.gz
  3.8beta1             https://github.com/mumax/3/archive/v3.8beta1.tar.gz
  3.8                  https://github.com/mumax/3/archive/v3.8.tar.gz
  3.7beta2             https://github.com/mumax/3/archive/v3.7beta2.tar.gz
  ...
  3.7                  https://github.com/mumax/3/archive/v3.7.tar.gz

==> Downloading...
==> Fetching https://github.com/mumax/3/releases/download/v3.9.3/mumax3.9.3_linux_cuda7.5.tar.gz
######################################################################## 100.0%
==> Fetching https://github.com/mumax/3/archive/v3.9.3.tar.gz
######################################################################## 100.0%
==> Fetching https://github.com/mumax/3/archive/v3.9.2.tar.gz
######################################################################## 100.0%
==> Fetching https://github.com/mumax/3/releases/download/v3.9.1/mumax3.9.1c_linux.tar.gz
^C
==> Error: Keyboard interrupt.
```



Discussion:
This might be specific to github downloads.

Resolving patch:
diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py
--- a/lib/spack/spack/cmd/checksum.py
+++ b/lib/spack/spack/cmd/checksum.py
@@ -65,7 +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),
+        batch=(args.batch or len(args.versions) > 0 or len(url_dict) == 1),
         fetch_options=pkg.fetch_options)
 
     print()
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py
--- a/lib/spack/spack/cmd/create.py
+++ b/lib/spack/spack/cmd/create.py
@@ -445,6 +445,9 @@ def setup_parser(subparser):
     subparser.add_argument(
         '--skip-editor', action='store_true',
         help="skip the edit session for the package (e.g., automation)")
+    subparser.add_argument(
+        '-b', '--batch', action='store_true',
+        help="don't ask which versions to checksum")
 
 
 class BuildSystemGuesser:
@@ -511,7 +514,7 @@ def __call__(self, stage, url):
         # Determine the build system based on the files contained
         # in the archive.
         for pattern, bs in clues:
-            if any(re.search(pattern, l) for l in lines):
+            if any(re.search(pattern, line) for line in lines):
                 self.build_system = bs
                 break
 
@@ -629,7 +632,8 @@ def get_versions(args, name):
 
         versions = spack.stage.get_checksums_for_versions(
             url_dict, name, first_stage_function=guesser,
-            keep_stage=args.keep_stage, batch=True)
+            keep_stage=args.keep_stage,
+            batch=(args.batch or len(url_dict) == 1))
     else:
         versions = unhashed_versions
 


Test patch: