From e5c7ade601809857bc167180599dd9a40f9f1ac4 2006-01-28 20:08:02 From: vivainio Date: 2006-01-28 20:08:02 Subject: [PATCH] -Expose IPApi is _ip in user namespace. -Replace ipmagic with _ip.magic for all interactive execution; therefore, there should be no user_ns['ipmagic'] references in IPython core anymore. - "_ip.options().autoedit_syntax = 2" -> no prompting, just edit --- diff --git a/IPython/Extensions/ext_rescapture.py b/IPython/Extensions/ext_rescapture.py index adfe353..71aa3d5 100644 --- a/IPython/Extensions/ext_rescapture.py +++ b/IPython/Extensions/ext_rescapture.py @@ -26,7 +26,7 @@ def hnd_magic(line,mo): var = mo.group('varname') cmd = mo.group('cmd') expr = make_quoted_expr(cmd) - return itpl('$var = ipmagic($expr)') + return itpl('$var = _ip.magic($expr)') def hnd_syscmd(line,mo): """ Handle a = !ls """ @@ -36,7 +36,7 @@ def hnd_syscmd(line,mo): var = mo.group('varname') cmd = mo.group('cmd') expr = make_quoted_expr(itpl("sc -l =$cmd")) - return itpl('$var = ipmagic($expr)') + return itpl('$var = _ip.magic($expr)') def install_re_handler(pat, hnd): ip.meta().re_prefilters.append((re.compile(pat), hnd)) diff --git a/IPython/Magic.py b/IPython/Magic.py index 03730e6..6c8db93 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 1094 2006-01-28 00:47:41Z vivainio $""" +$Id: Magic.py 1096 2006-01-28 20:08:02Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -506,7 +506,7 @@ Currently the magic system has the following functions:\n""" like magics or aliases are turned into function calls, for example). With this option, you'll see the unfiltered history instead of the filtered version: '%cd /' will be seen as '%cd /' - instead of 'ipmagic("%cd /")'. + instead of '_ip.magic("%cd /")'. """ shell = self.shell @@ -573,7 +573,7 @@ Currently the magic system has the following functions:\n""" for n in range(len(self.shell.input_hist)-2,0,-1): input = self.shell.input_hist[n] # skip plain 'r' lines so we don't recurse to infinity - if input != 'ipmagic("r")\n' and \ + if input != '_ip.magic("r")\n' and \ (input.startswith(start) or input.startswith(start_magic)): #print 'match',`input` # dbg print 'Executing:',input, @@ -1150,11 +1150,10 @@ Currently the magic system has the following functions:\n""" If you really need to assign this value via an explicit function call, you can always tap directly into the true name of the magic function - by using the ipmagic function (which IPython automatically adds to the - builtins):\\ - In [3]: stats = ipmagic('prun','-r print 4') + by using the _ip.magic function:\\ + In [3]: stats = _ip.magic('prun','-r print 4') - You can type ipmagic? for more details on ipmagic. + You can type _ip.magic? for more details. -s : sort profile by given key. You can provide more than one key by using the option several times: '-s key1 -s key2 -s key3...'. The diff --git a/IPython/iplib.py b/IPython/iplib.py index 7cafaa0..85902db 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 1093 2006-01-28 00:18:49Z vivainio $ +$Id: iplib.py 1096 2006-01-28 20:08:02Z vivainio $ """ #***************************************************************************** @@ -680,12 +680,15 @@ class InteractiveShell(object,Magic): Some parts of ipython operate via builtins injected here, which hold a reference to IPython itself.""" + # TODO: deprecate all except _ip; 'jobs' should be installed + # by an extension and the rest are under _ip builtins_new = dict(__IPYTHON__ = self, - ip_set_hook = self.set_hook, + ip_set_hook = self.set_hook, jobs = self.jobs, - ipmagic = self.ipmagic, - ipalias = self.ipalias, + ipmagic = self.ipmagic, + ipalias = self.ipalias, ipsystem = self.ipsystem, + _ip = self.api ) for biname,bival in builtins_new.items(): try: @@ -1240,8 +1243,9 @@ want to merge them back into the new files.""" % locals() return False try: - if not ask_yes_no('Return to editor to correct syntax error? ' - '[Y/n] ','y'): + if (self.rc.autoedit_syntax != 2 and + not ask_yes_no('Return to editor to correct syntax error? ' + '[Y/n] ','y')): return False except EOFError: return False @@ -2013,7 +2017,7 @@ want to merge them back into the new files.""" % locals() """Execute magic functions.""" - cmd = '%sipmagic(%s)' % (pre,make_quoted_expr(iFun + " " + theRest)) + cmd = '%s_ip.magic(%s)' % (pre,make_quoted_expr(iFun + " " + theRest)) self.log(cmd,continue_prompt) #print 'in handle_magic, cmd=<%s>' % cmd # dbg return cmd diff --git a/doc/ChangeLog b/doc/ChangeLog index a938a1c..02db879 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,15 @@ 2006-01-27 Ville Vainio + * iplib.py: Expose ipapi as _ip in builtin namespace. + Makes ipmagic (-> _ip.magic), ipsystem (-> _ip.system) + and ip_set_hook (-> _ip.set_hook) redundant. % and ! + syntax now produce _ip.* variant of the commands. + + * "_ip.options().autoedit_syntax = 2" automatically throws + user to editor for syntax error correction without prompting. + +2006-01-27 Ville Vainio + * ipmaker.py: Give "realistic" sys.argv for scripts (without 'ipython' at argv[0]) executed through command line. NOTE: this DEPRECATES calling ipython with multiple scripts diff --git a/doc/update_manual.py b/doc/update_manual.py index 5a58814..2ab5e64 100644 --- a/doc/update_manual.py +++ b/doc/update_manual.py @@ -11,7 +11,7 @@ import sys,IPython,re fil=open("magic.tex","w") oldout=sys.stdout sys.stdout=fil -ipmagic("magic -latex") +_ip.magic("magic -latex") sys.stdout=oldout fil.close()