##// END OF EJS Templates
fallback on lsof if otool not found in libedit detection...
MinRK -
Show More
@@ -9,6 +9,7 b' In addition to normal readline stuff, this module provides have_readline'
9 boolean and _outputfile variable used in IPython.utils.
9 boolean and _outputfile variable used in IPython.utils.
10 """
10 """
11
11
12 import os
12 import re
13 import re
13 import sys
14 import sys
14 import time
15 import time
@@ -56,21 +57,36 b" if sys.platform == 'darwin' and have_readline:"
56 # seems to make this better behaved in environments such as PyQt and gdb
57 # seems to make this better behaved in environments such as PyQt and gdb
57 dt = 1e-3
58 dt = 1e-3
58 while dt < 1:
59 while dt < 1:
59 p = Popen(['otool', '-L', _rl.__file__], stdout=PIPE, stderr=PIPE)
60 try:
60 otool,err = p.communicate()
61 p = Popen(['otool', '-L', _rl.__file__], stdout=PIPE, stderr=PIPE)
62 except OSError:
63 try:
64 # otool not available (no XCode), use lsof instead.
65 # This *could* have a false positive
66 # if another package that uses libedit explicitly
67 # has been imported prior to this test.
68 p = Popen(['lsof', '-p', str(os.getpid())], stdout=PIPE, stderr=PIPE)
69 except OSError:
70 # This is highly unlikely, but let's be sure
71 # we don't crash IPython just because we can't find lsof
72 p = out = err = None
73 warnings.warn("libedit detection failed")
74 break
75
76 out,err = p.communicate()
61
77
62 if p.returncode == 4:
78 if p.returncode == 4:
63 # EINTR
79 # EINTR
64 time.sleep(dt)
80 time.sleep(dt)
65 dt *= 2
81 dt *= 2
66 continue
82 continue
67 elif p.returncode:
83 elif p is None or p.returncode:
68 warnings.warn("libedit detection failed: %s"%err)
84 warnings.warn("libedit detection failed: %s"%err)
69 break
85 break
70 else:
86 else:
71 break
87 break
72
88
73 if p.returncode == 0 and re.search(r'/libedit[\.\d+]*\.dylib\s', otool):
89 if p is not None and p.returncode == 0 and re.search(r'/libedit[\.\d+]*\.dylib\s', out):
74 # we are bound to libedit - new in Leopard
90 # we are bound to libedit - new in Leopard
75 _rl.parse_and_bind("bind ^I rl_complete")
91 _rl.parse_and_bind("bind ^I rl_complete")
76 warnings.warn("Leopard libedit detected - readline will not be well behaved "
92 warnings.warn("Leopard libedit detected - readline will not be well behaved "
@@ -79,7 +95,8 b" if sys.platform == 'darwin' and have_readline:"
79 "which is easy_installable with: 'easy_install readline'",
95 "which is easy_installable with: 'easy_install readline'",
80 RuntimeWarning)
96 RuntimeWarning)
81 uses_libedit = True
97 uses_libedit = True
82
98 # cleanup names
99 del dt,p,out,err
83
100
84 # the clear_history() function was only introduced in Python 2.4 and is
101 # the clear_history() function was only introduced in Python 2.4 and is
85 # actually optional in the readline API, so we must explicitly check for its
102 # actually optional in the readline API, so we must explicitly check for its
General Comments 0
You need to be logged in to leave comments. Login now