diff --git a/IPython/Magic.py b/IPython/Magic.py index 55869da..be1d546 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 2221 2007-04-06 02:58:37Z fperez $""" +$Id: Magic.py 2225 2007-04-08 02:48:16Z jdh2358 $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -1673,8 +1673,7 @@ Currently the magic system has the following functions:\n""" sys.argv = save_argv if restore_main: sys.modules['__main__'] = restore_main - if self.shell.has_readline: - self.shell.readline.read_history_file(self.shell.histfile) + self.shell.reloadhist() return stats diff --git a/IPython/PyColorize.py b/IPython/PyColorize.py index 4aa6a69..05d155c 100755 --- a/IPython/PyColorize.py +++ b/IPython/PyColorize.py @@ -28,7 +28,7 @@ scan Python source code and re-emit it with no changes to its original formatting (which is the hard part). - $Id: PyColorize.py 2205 2007-04-04 06:04:01Z fperez $""" + $Id: PyColorize.py 2225 2007-04-08 02:48:16Z jdh2358 $""" __all__ = ['ANSICodeColors','Parser'] @@ -131,7 +131,7 @@ class Parser: out should be a file-type object. Optionally, out can be given as the string 'str' and the parser will automatically return the output in a string.""" - + string_output = 0 if out == 'str' or self.out == 'str': out_old = self.out @@ -155,10 +155,11 @@ class Parser: # Remove trailing whitespace and normalize tabs self.raw = raw.expandtabs().rstrip() + # store line offsets in self.lines self.lines = [0, 0] pos = 0 - raw_find = raw.find + raw_find = self.raw.find lines_append = self.lines.append while 1: pos = raw_find('\n', pos) + 1 diff --git a/IPython/iplib.py b/IPython/iplib.py index a00897f..71d9b64 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 2221 2007-04-06 02:58:37Z fperez $ +$Id: iplib.py 2225 2007-04-08 02:48:16Z jdh2358 $ """ #***************************************************************************** @@ -355,6 +355,11 @@ class InteractiveShell(object,Magic): # dict of output history self.output_hist = {} + # Get system encoding at startup time. Certain terminals (like Emacs + # under Win32 have it set to None, and we need to have a known valid + # encoding to use in the raw_input() method + self.stdin_encoding = sys.stdin.encoding or 'ascii' + # dict of things NOT to alias (keywords, builtins and some magics) no_alias = {} no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias'] @@ -410,7 +415,8 @@ class InteractiveShell(object,Magic): # Set all default hooks, defined in the IPython.hooks module. hooks = IPython.hooks for hook_name in hooks.__all__: - # default hooks have priority 100, i.e. low; user hooks should have 0-100 priority + # default hooks have priority 100, i.e. low; user hooks should have + # 0-100 priority self.set_hook(hook_name,getattr(hooks,hook_name), 100) #print "bound hook",hook_name @@ -495,7 +501,6 @@ class InteractiveShell(object,Magic): r'(\S*\s*)' r'(\(?.*$)') - # A simpler regexp used as a fallback if the above doesn't work. This # one is more conservative in how it partitions the input. This code # can probably be cleaned up to do everything with just one regexp, but @@ -1245,6 +1250,13 @@ want to merge them back into the new files.""" % locals() print 'Unable to save IPython command history to file: ' + \ `self.histfile` + def reloadhist(self): + """Reload the input history from disk file.""" + + if self.has_readline: + self.readline.clear_history() + self.readline.read_history_file(self.shell.histfile) + def history_saving_wrapper(self, func): """ Wrap func for readline history saving @@ -1988,7 +2000,7 @@ want to merge them back into the new files.""" % locals() self.set_completer() try: - line = raw_input_original(prompt).decode(sys.stdin.encoding) + line = raw_input_original(prompt).decode(self.stdin_encoding) except ValueError: warn("\n********\nYou or a %run:ed script called sys.stdin.close()" " or sys.stdout.close()!\nExiting IPython!") diff --git a/doc/ChangeLog b/doc/ChangeLog index d504bc8..834a758 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,15 @@ +2007-04-07 Fernando Perez + + * Tag 0.8.0 for release. + + * IPython/iplib.py (reloadhist): add API function to cleanly + reload the readline history, which was growing inappropriately on + every %run call. + + * win32_manual_post_install.py (run): apply last part of Nicolas + Pernetty's patch (I'd accidentally applied it in a different + directory and this particular file didn't get patched). + 2007-04-05 Fernando Perez * IPython/Shell.py (MAIN_THREAD_ID): get rid of my stupid hack to diff --git a/doc/manual_base.lyx b/doc/manual_base.lyx index 60536ca..2e61f42 100644 --- a/doc/manual_base.lyx +++ b/doc/manual_base.lyx @@ -4430,28 +4430,47 @@ In [6]: cd ipython # automagic can work again \begin_layout Standard You can define your own magic functions to extend the system. - The following is a snippet of code which shows how to do it. - It is provided as file + The following example defines a new magic command, \family typewriter -example-magic.py +%impall \family default - in the examples directory: +: \end_layout -\begin_layout Standard -\begin_inset ERT -status open +\begin_layout LyX-Code +import IPython.ipapi +\end_layout -\begin_layout Standard +\begin_layout LyX-Code +ip = IPython.ipapi.get() +\end_layout +\begin_layout LyX-Code -\backslash -codelist{examples/example-magic.py} \end_layout -\end_inset +\begin_layout LyX-Code +def doimp(self, arg): +\end_layout +\begin_layout LyX-Code + ip = self.api +\end_layout +\begin_layout LyX-Code + ip.ex("import %s; reload(%s); from %s import *" % ( +\end_layout + +\begin_layout LyX-Code + arg,arg,arg) +\end_layout + +\begin_layout LyX-Code + ) +\end_layout + +\begin_layout LyX-Code +ip.expose_magic('impall', doimp) \end_layout \begin_layout Standard diff --git a/setup.py b/setup.py index 7123628..979c759 100755 --- a/setup.py +++ b/setup.py @@ -55,7 +55,6 @@ if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'): ['doc/manual.lyx', 'doc/magic.tex', 'doc/examples/example-gnuplot.py', - 'doc/examples/example-magic.py', 'doc/examples/example-embed.py', 'doc/examples/example-embed-short.py', 'IPython/UserConfig/ipythonrc', diff --git a/win32_manual_post_install.py b/win32_manual_post_install.py index 29dfcc4..3149015 100644 --- a/win32_manual_post_install.py +++ b/win32_manual_post_install.py @@ -94,6 +94,11 @@ def run(wait=0): sys.prefix + r'\Scripts\ipython" %*') fic.close() + # Create .bat file in \\Scripts + fic = open(sys.prefix + '\\Scripts\\ipython.bat','w') + fic.write('"' + sys.prefix + '\\python.exe' + '" -i ' + '"' + sys.prefix + '\\Scripts\ipython" %*') + fic.close() + # Create shortcuts in Programs\IPython: if not os.path.isdir(ip_prog_dir): os.mkdir(ip_prog_dir)