prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  spack extensions behavior when no extendable package is specified
  If you run `spack extensions` with no extendable package, it prints an error message telling you that a package spec is required. It would be nice if Spack also printed a list of installed extendable packages to choose from.
  
  
  </issue>
  <code>
  [start of lib/spack/spack/cmd/extensions.py]
  1 # Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
  2 # Spack Project Developers. See the top-level COPYRIGHT file for details.
  3 #
  4 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
  5 
  6 import argparse
  7 
  8 import llnl.util.tty as tty
  9 from llnl.util.tty.colify import colify
  10 
  11 import spack.environment as ev
  12 import spack.cmd as cmd
  13 import spack.cmd.common.arguments as arguments
  14 import spack.repo
  15 import spack.store
  16 from spack.filesystem_view import YamlFilesystemView
  17 
  18 description = "list extensions for package"
  19 section = "extensions"
  20 level = "long"
  21 
  22 
  23 def setup_parser(subparser):
  24     arguments.add_common_arguments(subparser, ['long', 'very_long'])
  25     subparser.add_argument('-d', '--deps', action='store_true',
  26                            help='output dependencies along with found specs')
  27 
  28     subparser.add_argument('-p', '--paths', action='store_true',
  29                            help='show paths to package install directories')
  30     subparser.add_argument(
  31         '-s', '--show', action='store', default='all',
  32         choices=("packages", "installed", "activated", "all"),
  33         help="show only part of output")
  34     subparser.add_argument(
  35         '-v', '--view', metavar='VIEW', type=str,
  36         help="the view to operate on")
  37 
  38     subparser.add_argument(
  39         'spec', nargs=argparse.REMAINDER,
  40         help='spec of package to list extensions for', metavar='extendable')
  41 
  42 
  43 def extensions(parser, args):
  44     if not args.spec:
  45         tty.die("extensions requires a package spec.")
  46 
  47     # Checks
  48     spec = cmd.parse_specs(args.spec)
  49     if len(spec) > 1:
  50         tty.die("Can only list extensions for one package.")
  51 
  52     if not spec[0].package.extendable:
  53         tty.die("%s is not an extendable package." % spec[0].name)
  54 
  55     env = ev.get_env(args, 'extensions')
  56     spec = cmd.disambiguate_spec(spec[0], env)
  57 
  58     if not spec.package.extendable:
  59         tty.die("%s does not have extensions." % spec.short_spec)
  60 
  61     if args.show in ("packages", "all"):
  62         # List package names of extensions
  63         extensions = spack.repo.path.extensions_for(spec)
  64         if not extensions:
  65             tty.msg("%s has no extensions." % spec.cshort_spec)
  66         else:
  67             tty.msg(spec.cshort_spec)
  68             tty.msg("%d extensions:" % len(extensions))
  69             colify(ext.name for ext in extensions)
  70 
  71     if args.view:
  72         target = args.view
  73     else:
  74         target = spec.prefix
  75 
  76     view = YamlFilesystemView(target, spack.store.layout)
  77 
  78     if args.show in ("installed", "all"):
  79         # List specs of installed extensions.
  80         installed = [
  81             s.spec for s in spack.store.db.installed_extensions_for(spec)]
  82 
  83         if args.show == "all":
  84             print
  85         if not installed:
  86             tty.msg("None installed.")
  87         else:
  88             tty.msg("%d installed:" % len(installed))
  89             cmd.display_specs(installed, args)
  90 
  91     if args.show in ("activated", "all"):
  92         # List specs of activated extensions.
  93         activated = view.extensions_layout.extension_map(spec)
  94         if args.show == "all":
  95             print
  96         if not activated:
  97             tty.msg("None activated.")
  98         else:
  99             tty.msg("%d activated:" % len(activated))
  100             cmd.display_specs(activated.values(), args)
  101
  [end of lib/spack/spack/cmd/extensions.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/lib/spack/spack/cmd/extensions.py b/lib/spack/spack/cmd/extensions.py
  --- a/lib/spack/spack/cmd/extensions.py
  +++ b/lib/spack/spack/cmd/extensions.py
  @@ -4,6 +4,7 @@
   # SPDX-License-Identifier: (Apache-2.0 OR MIT)
   
   import argparse
  +import sys
   
   import llnl.util.tty as tty
   from llnl.util.tty.colify import colify
  @@ -21,6 +22,8 @@
   
   
   def setup_parser(subparser):
  +    subparser.epilog = 'If called without argument returns ' \
  +                       'the list of all valid extendable packages'
       arguments.add_common_arguments(subparser, ['long', 'very_long'])
       subparser.add_argument('-d', '--deps', action='store_true',
                              help='output dependencies along with found specs')
  @@ -42,7 +45,19 @@
   
   def extensions(parser, args):
       if not args.spec:
  -        tty.die("extensions requires a package spec.")
  +        # If called without arguments, list all the extendable packages
  +        isatty = sys.stdout.isatty()
  +        if isatty:
  +            tty.info('Extendable packages:')
  +
  +        extendable_pkgs = []
  +        for name in spack.repo.all_package_names():
  +            pkg = spack.repo.get(name)
  +            if pkg.extendable:
  +                extendable_pkgs.append(name)
  +
  +        colify(extendable_pkgs, indent=4)
  +        return
   
       # Checks
       spec = cmd.parse_specs(args.spec)
  
verification_info: {"golden_diff": "diff --git a/lib/spack/spack/cmd/extensions.py b/lib/spack/spack/cmd/extensions.py\n--- a/lib/spack/spack/cmd/extensions.py\n+++ b/lib/spack/spack/cmd/extensions.py\n@@ -4,6 +4,7 @@\n # SPDX-License-Identifier: (Apache-2.0 OR MIT)\n \n import argparse\n+import sys\n \n import llnl.util.tty as tty\n from llnl.util.tty.colify import colify\n@@ -21,6 +22,8 @@\n \n \n def setup_parser(subparser):\n+    subparser.epilog = 'If called without argument returns ' \\\n+                       'the list of all valid extendable packages'\n     arguments.add_common_arguments(subparser, ['long', 'very_long'])\n     subparser.add_argument('-d', '--deps', action='store_true',\n                            help='output dependencies along with found specs')\n@@ -42,7 +45,19 @@\n \n def extensions(parser, args):\n     if not args.spec:\n-        tty.die(\"extensions requires a package spec.\")\n+        # If called without arguments, list all the extendable packages\n+        isatty = sys.stdout.isatty()\n+        if isatty:\n+            tty.info('Extendable packages:')\n+\n+        extendable_pkgs = []\n+        for name in spack.repo.all_package_names():\n+            pkg = spack.repo.get(name)\n+            if pkg.extendable:\n+                extendable_pkgs.append(name)\n+\n+        colify(extendable_pkgs, indent=4)\n+        return\n \n     # Checks\n     spec = cmd.parse_specs(args.spec)\n", "issue": "spack extensions behavior when no extendable package is specified\nIf you run `spack extensions` with no extendable package, it prints an error message telling you that a package spec is required. It would be nice if Spack also printed a list of installed extendable packages to choose from.\n\n", "before_files": [{"content": "# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other\n# Spack Project Developers. See the top-level COPYRIGHT file for details.\n#\n# SPDX-License-Identifier: (Apache-2.0 OR MIT)\n\nimport argparse\n\nimport llnl.util.tty as tty\nfrom llnl.util.tty.colify import colify\n\nimport spack.environment as ev\nimport spack.cmd as cmd\nimport spack.cmd.common.arguments as arguments\nimport spack.repo\nimport spack.store\nfrom spack.filesystem_view import YamlFilesystemView\n\ndescription = \"list extensions for package\"\nsection = \"extensions\"\nlevel = \"long\"\n\n\ndef setup_parser(subparser):\n    arguments.add_common_arguments(subparser, ['long', 'very_long'])\n    subparser.add_argument('-d', '--deps', action='store_true',\n                           help='output dependencies along with found specs')\n\n    subparser.add_argument('-p', '--paths', action='store_true',\n                           help='show paths to package install directories')\n    subparser.add_argument(\n        '-s', '--show', action='store', default='all',\n        choices=(\"packages\", \"installed\", \"activated\", \"all\"),\n        help=\"show only part of output\")\n    subparser.add_argument(\n        '-v', '--view', metavar='VIEW', type=str,\n        help=\"the view to operate on\")\n\n    subparser.add_argument(\n        'spec', nargs=argparse.REMAINDER,\n        help='spec of package to list extensions for', metavar='extendable')\n\n\ndef extensions(parser, args):\n    if not args.spec:\n        tty.die(\"extensions requires a package spec.\")\n\n    # Checks\n    spec = cmd.parse_specs(args.spec)\n    if len(spec) > 1:\n        tty.die(\"Can only list extensions for one package.\")\n\n    if not spec[0].package.extendable:\n        tty.die(\"%s is not an extendable package.\" % spec[0].name)\n\n    env = ev.get_env(args, 'extensions')\n    spec = cmd.disambiguate_spec(spec[0], env)\n\n    if not spec.package.extendable:\n        tty.die(\"%s does not have extensions.\" % spec.short_spec)\n\n    if args.show in (\"packages\", \"all\"):\n        # List package names of extensions\n        extensions = spack.repo.path.extensions_for(spec)\n        if not extensions:\n            tty.msg(\"%s has no extensions.\" % spec.cshort_spec)\n        else:\n            tty.msg(spec.cshort_spec)\n            tty.msg(\"%d extensions:\" % len(extensions))\n            colify(ext.name for ext in extensions)\n\n    if args.view:\n        target = args.view\n    else:\n        target = spec.prefix\n\n    view = YamlFilesystemView(target, spack.store.layout)\n\n    if args.show in (\"installed\", \"all\"):\n        # List specs of installed extensions.\n        installed = [\n            s.spec for s in spack.store.db.installed_extensions_for(spec)]\n\n        if args.show == \"all\":\n            print\n        if not installed:\n            tty.msg(\"None installed.\")\n        else:\n            tty.msg(\"%d installed:\" % len(installed))\n            cmd.display_specs(installed, args)\n\n    if args.show in (\"activated\", \"all\"):\n        # List specs of activated extensions.\n        activated = view.extensions_layout.extension_map(spec)\n        if args.show == \"all\":\n            print\n        if not activated:\n            tty.msg(\"None activated.\")\n        else:\n            tty.msg(\"%d activated:\" % len(activated))\n            cmd.display_specs(activated.values(), args)\n", "path": "lib/spack/spack/cmd/extensions.py"}]}