##// END OF EJS Templates
Fix readline detection bug in OSX....
Fernando Perez -
Show More
@@ -1,55 +1,67 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """ Imports and provides the 'correct' version of readline for the platform.
2 """ Imports and provides the 'correct' version of readline for the platform.
3
3
4 Readline is used throughout IPython as 'import IPython.rlineimpl as readline'.
4 Readline is used throughout IPython as 'import IPython.rlineimpl as readline'.
5
5
6 In addition to normal readline stuff, this module provides have_readline
6 In addition to normal readline stuff, this module provides have_readline
7 boolean and _outputfile variable used in genutils.
7 boolean and _outputfile variable used in genutils.
8 """
8 """
9
9
10 import sys
10 import sys
11
11
12 try:
12 try:
13 from readline import *
13 from readline import *
14 import readline as _rl
14 import readline as _rl
15 have_readline = True
15 have_readline = True
16 except ImportError:
16 except ImportError:
17 try:
17 try:
18 from pyreadline import *
18 from pyreadline import *
19 import pyreadline as _rl
19 import pyreadline as _rl
20 have_readline = True
20 have_readline = True
21 except ImportError:
21 except ImportError:
22 have_readline = False
22 have_readline = False
23
23
24 if sys.platform == 'win32' and have_readline:
24 if sys.platform == 'win32' and have_readline:
25 try:
25 try:
26 _outputfile=_rl.GetOutputFile()
26 _outputfile=_rl.GetOutputFile()
27 except AttributeError:
27 except AttributeError:
28 print "Failed GetOutputFile"
28 print "Failed GetOutputFile"
29 have_readline = False
29 have_readline = False
30
30
31 # Test to see if libedit is being used instead of GNU readline.
31 # Test to see if libedit is being used instead of GNU readline.
32 # Thanks to Boyd Waters for this patch.
32 # Thanks to Boyd Waters for this patch.
33 uses_libedit = False
33 uses_libedit = False
34 if sys.platform == 'darwin' and have_readline:
34 if sys.platform == 'darwin' and have_readline:
35 import commands
35 import commands
36 # Boyd's patch had a 'while True' here, I'm always a little worried about
37 # infinite loops with such code, so for now I'm taking a more conservative
38 # approach. See https://bugs.launchpad.net/ipython/+bug/411599.
39 for i in range(10):
40 try:
36 (status, result) = commands.getstatusoutput( "otool -L %s | grep libedit" % _rl.__file__ )
41 (status, result) = commands.getstatusoutput( "otool -L %s | grep libedit" % _rl.__file__ )
42 break
43 except IOError, (errno, strerror):
44 if errno == 4:
45 continue
46 else
47 break
48
37 if status == 0 and len(result) > 0:
49 if status == 0 and len(result) > 0:
38 # we are bound to libedit - new in Leopard
50 # we are bound to libedit - new in Leopard
39 _rl.parse_and_bind("bind ^I rl_complete")
51 _rl.parse_and_bind("bind ^I rl_complete")
40 print "Leopard libedit detected."
52 print "Leopard libedit detected."
41 uses_libedit = True
53 uses_libedit = True
42
54
43
55
44 # the clear_history() function was only introduced in Python 2.4 and is
56 # the clear_history() function was only introduced in Python 2.4 and is
45 # actually optional in the readline API, so we must explicitly check for its
57 # actually optional in the readline API, so we must explicitly check for its
46 # existence. Some known platforms actually don't have it. This thread:
58 # existence. Some known platforms actually don't have it. This thread:
47 # http://mail.python.org/pipermail/python-dev/2003-August/037845.html
59 # http://mail.python.org/pipermail/python-dev/2003-August/037845.html
48 # has the original discussion.
60 # has the original discussion.
49
61
50 if have_readline:
62 if have_readline:
51 try:
63 try:
52 _rl.clear_history
64 _rl.clear_history
53 except AttributeError:
65 except AttributeError:
54 def clear_history(): pass
66 def clear_history(): pass
55 _rl.clear_history = clear_history
67 _rl.clear_history = clear_history
General Comments 0
You need to be logged in to leave comments. Login now