Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge ../2to3-raw

Conflicts:
	IPython/utils/rlineimpl.py
  • Loading branch information...
commit 340fc1e6824a59dfc1f80f45db0e419e42ac7cc8 2 parents e9fdf21 + 23c405b
Thomas Kluyver takluyver authored
Showing with 24 additions and 7 deletions.
  1. +24 −7 IPython/utils/rlineimpl.py
31 IPython/utils/rlineimpl.py
View
@@ -9,6 +9,7 @@
boolean and _outputfile variable used in IPython.utils.
"""
+import os
import re
import sys
import time
@@ -44,7 +45,7 @@ def add_history(line):
try:
_outputfile=_rl.GetOutputFile()
except AttributeError:
- print("Failed GetOutputFile")
+ warnings.warn("Failed GetOutputFile")
have_readline = False
# Test to see if libedit is being used instead of GNU readline.
@@ -56,21 +57,36 @@ def add_history(line):
# seems to make this better behaved in environments such as PyQt and gdb
dt = 1e-3
while dt < 1:
- p = Popen(['otool', '-L', _rl.__file__], stdout=PIPE, stderr=PIPE)
- otool, err = p.communicate()
+ try:
+ p = Popen(['otool', '-L', _rl.__file__], stdout=PIPE, stderr=PIPE)
+ except OSError:
+ try:
+ # otool not available (no XCode), use lsof instead.
+ # This *could* have a false positive
+ # if another package that uses libedit explicitly
+ # has been imported prior to this test.
+ p = Popen(['lsof', '-p', str(os.getpid())], stdout=PIPE, stderr=PIPE)
+ except OSError:
+ # This is highly unlikely, but let's be sure
+ # we don't crash IPython just because we can't find lsof
+ p = out = err = None
+ warnings.warn("libedit detection failed")
+ break
+
+ out,err = p.communicate()
if p.returncode == 4:
# EINTR
time.sleep(dt)
dt *= 2
continue
- elif p.returncode:
- warnings.warn("libedit detection failed: {0}".format(err))
+ elif p is None or p.returncode:
+ warnings.warn("libedit detection failed: %s"%err)
break
else:
break
- if p.returncode == 0 and re.search(br'/libedit[\.\d+]*\.dylib\s', otool):
+ if p is not None and p.returncode == 0 and re.search(br'/libedit[\.\d+]*\.dylib\s', out):
# we are bound to libedit - new in Leopard
_rl.parse_and_bind("bind ^I rl_complete")
warnings.warn("Leopard libedit detected - readline will not be well behaved "
@@ -79,7 +95,8 @@ def add_history(line):
"which is easy_installable with: 'easy_install readline'",
RuntimeWarning)
uses_libedit = True
-
+ # cleanup names
+ del dt,p,out,err
# the clear_history() function was only introduced in Python 2.4 and is
# actually optional in the readline API, so we must explicitly check for its
Please sign in to comment.
Something went wrong with that request. Please try again.