Skip to content

Commit 9902cb2

Browse files
committed
Added back in preference for gnureadline if it is present
Now that the crash bug in the gnureadline Python module which statically links against a compatible version of GNU Readline has been fixed for macOS, we added back in the top-level import boilerplate to prefer it if it is available. Also updated some documentation in relation to getting readline installed for macOS.
1 parent 450466e commit 9902cb2

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

cmd2.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@
8888
except ImportError:
8989
ipython_available = False
9090

91-
# Try to import readline, but allow failure for convenience in Windows unit testing
92-
# Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows
91+
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
9392
try:
94-
# noinspection PyUnresolvedReferences
95-
import readline
93+
import gnureadline as readline
9694
except ImportError:
97-
pass
95+
# Try to import readline, but allow failure for convenience in Windows unit testing
96+
# Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows
97+
try:
98+
# noinspection PyUnresolvedReferences
99+
import readline
100+
except ImportError:
101+
pass
98102

99103
# BrokenPipeError and FileNotFoundError exist only in Python 3. Use IOError for Python 2.
100104
if six.PY3:

docs/index.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ The basic use of ``cmd2`` is identical to that of cmd_.
3535

3636
The tab-completion feature provided by cmd_ relies on underlying capability provided by GNU readline or an
3737
equivalent library. Linux distros will almost always come with the required library installed.
38-
For macOS, we recommend using the `Homebrew <https://brew.sh>`_ package manager to install the ``readline`` package;
39-
alternatively for macOS the ``conda`` package manager that comes with the Anaconda Python distro can be used to
40-
install ``readline`` (preferably from conda-forge).
38+
For macOS, we recommend using the `gnureadline <https://pypi.python.org/pypi/gnureadline>`_ Python module which includes
39+
a statically linked version of GNU readline. Alternatively on macOS the ``conda`` package manager that comes
40+
with the Anaconda Python distro can be used to install ``readline`` (preferably from conda-forge) or the
41+
`Homebrew <https://brew.sh>`_ package manager can be used to to install the ``readline`` package.
4142
For Windows, we recommend installing the `pyreadline <https://pypi.python.org/pypi/pyreadline>`_ Python module.
4243

4344
Resources

docs/install.rst

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
=========================
32
Installation Instructions
43
=========================
54

@@ -138,5 +137,33 @@ Extra requirement for Python 2.7 only
138137
If you want to be able to pipe the output of commands to a shell command on Python 2.7, then you will need one
139138
additional package installed:
140139

141-
* subprocess32
140+
* subprocess32gNU
141+
142+
Extra requirement for macOS
143+
===========================
144+
macOS comes with the `libedit <http://thrysoee.dk/editline/>`_ library which is similar, but not identical, to GNU Readline.
145+
Tab-completion for ``cmd2`` applications is only tested against GNU Readline.
146+
147+
There are several ways GNU Readline can be installed within a Python environment on a Mac, detailed in the following subsections.
148+
149+
gnureadline Python module
150+
-------------------------
151+
Install the `gnureadline <https://pypi.python.org/pypi/gnureadline>`_ Python module which is statically linked against a specific compatible version of GNU Readline::
152+
153+
pip install -U gnureadline
154+
155+
readline via conda
156+
------------------
157+
Install the **readline** package using the ``conda`` package manager included with the Anaconda Python distribution::
158+
159+
conda install readline
160+
161+
readline via brew
162+
-----------------
163+
Install the **readline** package using the Homebrew package manager (compiles from source)::
164+
165+
brew install openssl
166+
brew install pyenv
167+
brew install readline
142168

169+
Then use pyenv to compile Python and link against the installed readline

0 commit comments

Comments
 (0)