On 5/10/07, William Stein <[EMAIL PROTECTED]> wrote:

> I just did a fresh build of sage-2.5 on one of my 64-bit linux boxes,
> and clear_history is definitely *not* in Python 2.5.1's build of
> readline on this system.   The main reason we upgraded to
> Python 2.5.1 is to fix some very nasty *Python* bugs in the readline
> module, so it is entirely possible that removing this function
> did in fact occur with Python 2.5.1, especially since the readline
> included in SAGE is totally standard and hasn't changed in a
> long time.

I just looked at the source for Python 2.5.1, and this is the relevant part:

#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER

/* Exported function to clear the current history */

static PyObject *
py_clear_history(PyObject *self, PyObject *noarg)
{
        clear_history();
        Py_INCREF(Py_None);
        return Py_None;
}

PyDoc_STRVAR(doc_clear_history,
"clear_history() -> None\n\
Clear the current readline history.");
#endif

So I suspect that somehow, in the SAGE build environment, this
particular symbol is not being declared and the clear_history()
function isn't getting compiled.

I just downloaded and built a fresh 2.5.1 on my ubuntu feisty (32-bit) box:

Python 2.5.1 (r251:54863, May 10 2007, 18:03:14)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Loading hist!
>>> import readline
>>> readline.__file__
'/scratch/local/home/fperez/tmp/local2/lib/python2.5/lib-dynload/readline.so'
>>> readline.clear_history
<built-in function clear_history>
>>> dir(readline)
['__doc__', '__file__', '__name__', 'add_history', 'clear_history',
'get_begidx', 'get_completer', 'get_completer_delims',
'get_current_history_length', 'get_endidx', 'get_history_item',
'get_history_length', 'get_line_buffer', 'insert_text',
'parse_and_bind', 'read_history_file', 'read_init_file', 'redisplay',
'remove_history_item', 'replace_history_item', 'set_completer',
'set_completer_delims', 'set_history_length', 'set_pre_input_hook',
'set_startup_hook', 'write_history_file']

so it's there.

I don't know why, but it seems the SAGE build is slightly different
and this particular function ends up missing.

> Observations:
>  (1) As far as I can tell, if one just comments out line 1257
> from SAGE_ROOT/local/lib/python2.5/site-packages/IPython/iplib.py
> then everything works fine:
>
>         if self.has_readline:
>             #self.readline.clear_history()
>             self.readline.read_history_file(self.shell.histfile)
>
> When would this not work?

When you switch in and out of other readline-using subsystems, such as
the interactive debugger, the histories get mangled.  This ensures a
proper restore.

> (2) Why do you have to do clear_history()?  Are you sure that 
> read_history_file
> doesn't clear out the history?  The Python docstring is not clear on this 
> point:
>
> read_history_file([filename]) -> Non
>     Load a readline history file.
>     The default filename is ~/.history.

I think the read... only appends.  The danger is then that the history
grows very rapidly (each load can be thousands of lines), so over the
span of a long session, you can potentially accumulate a huge history
with multiple copies of the same thing piling atop one another.

I think the right fix is to figure out why SAGE is building readline
with that missing function.  But in the meantime, I'd suggest you
patch your local ipython with the above hack.  The consequences are
not likely to be really serious for anyone in practice, and that gives
you a working solution until you figure out what is going on.

Even better, to avoid having to patch ipython, you can do this
*BEFORE* you actually do the 'import IPython' part of the startup:

import readline
try:
  readline.clear_history
except AttributeError:
  def clear_history(): pass
  readline.clear_history = clear_history

in your SAGE startup script.  This way, by the time IPython sees the
readline module in the running process, it's been "fixed".  And when
you figure out your build problem, you can remove this little hack and
be done.  I think it's better than having to carry patched copies of
third-party stuff, and it also means that any other code calling this
routine won't break either.  Right now IPython is breaking, but
anything else you use that calls clear_history() would also break.

cheers,

f

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to