Repository: spack/spack

Issue:
`spack python` doesn't support readline
When I run `python`, I get readline support, which enables me to do things like use the arrow keys to go left/right or cycle forward/backward through my history, just as you would expect from your terminal shell.

When I run `spack python`, I don't seem to get this support, and the arrow keys are converted to meta characters:
```
$ spack python
Spack version 0.10.0
Python 2.7.12, Darwin x86_64
>>> print('hello world')^[[D^[[A^[[B^[[C
  File "<console>", line 1
    print('hello world')
                        ^
SyntaxError: invalid syntax
```
Any idea why?


Discussion:
That's strange... `readline` is included as a non-optional dependency.  And autotools generally automagically picks up things like that if they are provided.  I suppose the next step is looking at the build log?
Just to clarify, this isn't a Spack-built Python. This is my system Python. I'm running the `spack python` command.

Resolving patch:
diff --git a/lib/spack/spack/cmd/python.py b/lib/spack/spack/cmd/python.py
--- a/lib/spack/spack/cmd/python.py
+++ b/lib/spack/spack/cmd/python.py
@@ -62,6 +62,9 @@ def python(parser, args):
         with open(python_args[0]) as file:
             console.runsource(file.read(), python_args[0], 'exec')
     else:
+        # Provides readline support, allowing user to use arrow keys
+        console.push('import readline')
+
         console.interact("Spack version %s\nPython %s, %s %s"""
                          % (spack.spack_version, platform.python_version(),
                             platform.system(), platform.machine()))


Test patch:
diff --git a/lib/spack/spack/test/cmd/python.py b/lib/spack/spack/test/cmd/python.py
new file mode 100644
--- /dev/null
+++ b/lib/spack/spack/test/cmd/python.py
@@ -0,0 +1,43 @@
+##############################################################################
+# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/llnl/spack
+# Please also see the LICENSE file for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License (as
+# published by the Free Software Foundation) version 2.1, February 1999.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
+# conditions of the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+import argparse
+import pytest
+
+from spack.cmd.python import *
+
+
+@pytest.fixture(scope='module')
+def parser():
+    """Returns the parser for the ``python`` command"""
+    parser = argparse.ArgumentParser()
+    setup_parser(parser)
+    return parser
+
+
+def test_python(parser):
+    args = parser.parse_args([
+        '-c', 'import spack; print(spack.spack_version)'
+    ])
+    python(parser, args)