Show More
@@ -9,6 +9,7 b' In addition to normal readline stuff, this module provides have_readline' | |||
|
9 | 9 | boolean and _outputfile variable used in IPython.utils. |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | import os | |
|
12 | 13 | import re |
|
13 | 14 | import sys |
|
14 | 15 | import time |
@@ -56,21 +57,36 b" if sys.platform == 'darwin' and have_readline:" | |||
|
56 | 57 | # seems to make this better behaved in environments such as PyQt and gdb |
|
57 | 58 | dt = 1e-3 |
|
58 | 59 | while dt < 1: |
|
59 | p = Popen(['otool', '-L', _rl.__file__], stdout=PIPE, stderr=PIPE) | |
|
60 | otool,err = p.communicate() | |
|
60 | try: | |
|
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 | 78 | if p.returncode == 4: |
|
63 | 79 | # EINTR |
|
64 | 80 | time.sleep(dt) |
|
65 | 81 | dt *= 2 |
|
66 | 82 | continue |
|
67 | elif p.returncode: | |
|
83 | elif p is None or p.returncode: | |
|
68 | 84 | warnings.warn("libedit detection failed: %s"%err) |
|
69 | 85 | break |
|
70 | 86 | else: |
|
71 | 87 | break |
|
72 | 88 | |
|
73 |
if p.returncode == 0 and re.search(r'/libedit[\.\d+]*\.dylib\s', ot |
|
|
89 | if p is not None and p.returncode == 0 and re.search(r'/libedit[\.\d+]*\.dylib\s', out): | |
|
74 | 90 | # we are bound to libedit - new in Leopard |
|
75 | 91 | _rl.parse_and_bind("bind ^I rl_complete") |
|
76 | 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 | 95 | "which is easy_installable with: 'easy_install readline'", |
|
80 | 96 | RuntimeWarning) |
|
81 | 97 | uses_libedit = True |
|
82 | ||
|
98 | # cleanup names | |
|
99 | del dt,p,out,err | |
|
83 | 100 | |
|
84 | 101 | # the clear_history() function was only introduced in Python 2.4 and is |
|
85 | 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