From 9902cb2c6447e58ef12438ac711addc192b8f1f5 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Wed, 21 Mar 2018 14:41:30 -0400 Subject: 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. --- cmd2.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'cmd2.py') diff --git a/cmd2.py b/cmd2.py index 525c0dac..8f137aaf 100755 --- a/cmd2.py +++ b/cmd2.py @@ -88,13 +88,17 @@ try: except ImportError: ipython_available = False -# Try to import readline, but allow failure for convenience in Windows unit testing -# Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows +# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit) try: - # noinspection PyUnresolvedReferences - import readline + import gnureadline as readline except ImportError: - pass + # Try to import readline, but allow failure for convenience in Windows unit testing + # Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows + try: + # noinspection PyUnresolvedReferences + import readline + except ImportError: + pass # BrokenPipeError and FileNotFoundError exist only in Python 3. Use IOError for Python 2. if six.PY3: -- cgit v1.2.1 From 7b22a8754badd99c625cd9d97b2d6d7b48ecda69 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Wed, 21 Mar 2018 14:45:54 -0400 Subject: Fixed bug where readline got imported separately later --- cmd2.py | 1 - 1 file changed, 1 deletion(-) (limited to 'cmd2.py') diff --git a/cmd2.py b/cmd2.py index 8f137aaf..f54691fb 100755 --- a/cmd2.py +++ b/cmd2.py @@ -1381,7 +1381,6 @@ class Cmd(cmd.Cmd): :param state: int - non-negative integer """ if state == 0: - import readline origline = readline.get_line_buffer() line = origline.lstrip() stripped = len(origline) - len(line) -- cgit v1.2.1