[Pythonmac-SIG] [IPython-dev] readline support for OS X Leopard

Boyd Waters bwaters at nrao.edu
Wed Oct 31 16:47:05 CET 2007


This "which python" is an important point, but it is NOT causing my  
segfault.

I'm using Apple's Python. I'm certain. For IPython.

If you add this code to iplib.py then you are able to determine if you  
are bound to libedit.

have_libedit - False
if sys.platform == 'darwin' and have_readline:
     import commands
     (status, result) = commands.getstatusoutput( "otool -L %s | grep  
libedit" % _rl.__file__ )
     if status == 0 and len(result) > 0:
         # we are bound to libedit - new in Leopard
         # _rl.parse_and_bind("bind ^I complete")
         print "Leopard libedit detected."
         have_libedit = True


And that's what I see on the output when I start up ipython:

$ ipython
Leopard libedit detected.
Python 2.5.1 (r251:54863, Oct  5 2007, 21:08:09)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.2.svn.r2841 -- An enhanced Interactive Python.



The problem is to pass the "complete" method correctly to libedit.


In iplib.py, line 1342:

             # Configure readline according to user's prefs
             for rlcommand in self.rc.readline_parse_and_bind:
                 if rlcommand.startswith("tab"):
                     pass
                     if readline.have_libedit:
                         rlcommand = "bind ^I complete"
                 print rlcommand
                 readline.parse_and_bind(rlcommand)




The FIRST time I launch IPython after making this change, I get an  
"Invalid command" error from readline:

$ ipython
Leopard libedit detected.
bind ^I complete
bind: Invalid command `complete'.
"\C-l": possible-completions
set show-all-if-ambiguous on
"\C-o": tab-insert
"\M-i": "    "
"\M-o": "\d\d\d\d"
"\M-I": "\d\d\d\d"
"\C-r": reverse-search-history
"\C-s": forward-search-history
"\C-p": history-search-backward
"\C-n": history-search-forward
"\e[A": history-search-backward
"\e[B": history-search-forward
"\C-k": kill-line
"\C-u": unix-line-discard
Python 2.5.1 (r251:54863, Oct  5 2007, 21:08:09)



And the modules are compiled as a side-effect.


AFTER the modules are compiled, I simply get a segfault:

In [1]: ^D
Do you really want to exit ([y]/n)?
galatea:~ bwaters$ ipython
Leopard libedit detected.
bind ^I complete
Segmentation fault




SO:

1) How do I form the bind commands for libedit? "EditLine" syntax
2) The segfault is a bug, methinks. I posted it as such.





On Oct 31, 2007, at 9:28 AM, Brian Granger wrote:

> Can you do look at the output of:
>
> head `which ipython`
>
> This will tell you which python your ipython (the ipython that is
> first in your path if there are multiple) is using.
>
> Brian
>
>
> On 10/31/07, Boyd Waters <bwaters at nrao.edu> wrote:
>>
>>
>>
>>
>> On Oct 31, 2007, at 3:27 AM, Hans Meine wrote:
>>
>> BUT from inside *ipython* I get a segmentation fault.
>>
>>
>> Again - are you sure that both use the same python version?
>>
>> Thanks, good suggestion, but in this case I'm pretty sure.
>>
>> I uninstalled all MacPorts pythons before running this test.
>> This is basically a clean install of Leopard.
>>
>>
>> $ python
>> Python 2.5.1 (r251:54863, Oct  5 2007, 21:08:09)
>> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
>> Type "help", "copyright", "credits" or "license" for more  
>> information.
>>>>> import os
>>>>> import readline
>>>>> import rlcompleter
>>>>> print os.system("otool -L %s" % readline.__file__)
>> /System/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
>> python2.5/lib-dynload/readline.so:
>> /usr/lib/libedit.2.dylib (compatibility version 2.0.0, current  
>> version
>> 2.9.0)
>> /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current  
>> version
>> 5.4.0)
>> /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current  
>> version
>> 1.0.0)
>> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current  
>> version
>> 111.0.0)
>> 0
>>>>> readline.parse_and_bind ("bind ^I rl_complete")
>>>>> readline.[TAB KEY PRESSED]readline.__class__
>> readline.__class__
>> readline.__class__
>> readline.__delattr__                 readline.__delattr__
>>              readline.__dict__
>> ...
>>
>>>>> ^D
>>
>>
>>
>> $ ipython
>> In [1]: import os
>>
>> In [2]: import readline
>>
>> In [3]: import rlcompleter
>>
>> In [4]: print os.system("otool -L %s" % readline.__file__)
>> /Library/Python/2.5/site-packages/IPython/rlineimpl.pyc:
>> is not an object file
>> 0
>>
>>
>> Hmm.
>>
>>
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://lists.ipython.scipy.org/mailman/listinfo/ipython-dev
>>
>>



More information about the Pythonmac-SIG mailing list