##// END OF EJS Templates
-Expose IPApi is _ip in user namespace....
vivainio -
Show More
@@ -26,7 +26,7 b' def hnd_magic(line,mo):'
26 var = mo.group('varname')
26 var = mo.group('varname')
27 cmd = mo.group('cmd')
27 cmd = mo.group('cmd')
28 expr = make_quoted_expr(cmd)
28 expr = make_quoted_expr(cmd)
29 return itpl('$var = ipmagic($expr)')
29 return itpl('$var = _ip.magic($expr)')
30
30
31 def hnd_syscmd(line,mo):
31 def hnd_syscmd(line,mo):
32 """ Handle a = !ls """
32 """ Handle a = !ls """
@@ -36,7 +36,7 b' def hnd_syscmd(line,mo):'
36 var = mo.group('varname')
36 var = mo.group('varname')
37 cmd = mo.group('cmd')
37 cmd = mo.group('cmd')
38 expr = make_quoted_expr(itpl("sc -l =$cmd"))
38 expr = make_quoted_expr(itpl("sc -l =$cmd"))
39 return itpl('$var = ipmagic($expr)')
39 return itpl('$var = _ip.magic($expr)')
40
40
41 def install_re_handler(pat, hnd):
41 def install_re_handler(pat, hnd):
42 ip.meta().re_prefilters.append((re.compile(pat), hnd))
42 ip.meta().re_prefilters.append((re.compile(pat), hnd))
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 1094 2006-01-28 00:47:41Z vivainio $"""
4 $Id: Magic.py 1096 2006-01-28 20:08:02Z vivainio $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -506,7 +506,7 b' Currently the magic system has the following functions:\\n"""'
506 like magics or aliases are turned into function calls, for
506 like magics or aliases are turned into function calls, for
507 example). With this option, you'll see the unfiltered history
507 example). With this option, you'll see the unfiltered history
508 instead of the filtered version: '%cd /' will be seen as '%cd /'
508 instead of the filtered version: '%cd /' will be seen as '%cd /'
509 instead of 'ipmagic("%cd /")'.
509 instead of '_ip.magic("%cd /")'.
510 """
510 """
511
511
512 shell = self.shell
512 shell = self.shell
@@ -573,7 +573,7 b' Currently the magic system has the following functions:\\n"""'
573 for n in range(len(self.shell.input_hist)-2,0,-1):
573 for n in range(len(self.shell.input_hist)-2,0,-1):
574 input = self.shell.input_hist[n]
574 input = self.shell.input_hist[n]
575 # skip plain 'r' lines so we don't recurse to infinity
575 # skip plain 'r' lines so we don't recurse to infinity
576 if input != 'ipmagic("r")\n' and \
576 if input != '_ip.magic("r")\n' and \
577 (input.startswith(start) or input.startswith(start_magic)):
577 (input.startswith(start) or input.startswith(start_magic)):
578 #print 'match',`input` # dbg
578 #print 'match',`input` # dbg
579 print 'Executing:',input,
579 print 'Executing:',input,
@@ -1150,11 +1150,10 b' Currently the magic system has the following functions:\\n"""'
1150
1150
1151 If you really need to assign this value via an explicit function call,
1151 If you really need to assign this value via an explicit function call,
1152 you can always tap directly into the true name of the magic function
1152 you can always tap directly into the true name of the magic function
1153 by using the ipmagic function (which IPython automatically adds to the
1153 by using the _ip.magic function:\\
1154 builtins):\\
1154 In [3]: stats = _ip.magic('prun','-r print 4')
1155 In [3]: stats = ipmagic('prun','-r print 4')
1156
1155
1157 You can type ipmagic? for more details on ipmagic.
1156 You can type _ip.magic? for more details.
1158
1157
1159 -s <key>: sort profile by given key. You can provide more than one key
1158 -s <key>: sort profile by given key. You can provide more than one key
1160 by using the option several times: '-s key1 -s key2 -s key3...'. The
1159 by using the option several times: '-s key1 -s key2 -s key3...'. The
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 1093 2006-01-28 00:18:49Z vivainio $
9 $Id: iplib.py 1096 2006-01-28 20:08:02Z vivainio $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -680,12 +680,15 b' class InteractiveShell(object,Magic):'
680 Some parts of ipython operate via builtins injected here, which hold a
680 Some parts of ipython operate via builtins injected here, which hold a
681 reference to IPython itself."""
681 reference to IPython itself."""
682
682
683 # TODO: deprecate all except _ip; 'jobs' should be installed
684 # by an extension and the rest are under _ip
683 builtins_new = dict(__IPYTHON__ = self,
685 builtins_new = dict(__IPYTHON__ = self,
684 ip_set_hook = self.set_hook,
686 ip_set_hook = self.set_hook,
685 jobs = self.jobs,
687 jobs = self.jobs,
686 ipmagic = self.ipmagic,
688 ipmagic = self.ipmagic,
687 ipalias = self.ipalias,
689 ipalias = self.ipalias,
688 ipsystem = self.ipsystem,
690 ipsystem = self.ipsystem,
691 _ip = self.api
689 )
692 )
690 for biname,bival in builtins_new.items():
693 for biname,bival in builtins_new.items():
691 try:
694 try:
@@ -1240,8 +1243,9 b' want to merge them back into the new files.""" % locals()'
1240
1243
1241 return False
1244 return False
1242 try:
1245 try:
1243 if not ask_yes_no('Return to editor to correct syntax error? '
1246 if (self.rc.autoedit_syntax != 2 and
1244 '[Y/n] ','y'):
1247 not ask_yes_no('Return to editor to correct syntax error? '
1248 '[Y/n] ','y')):
1245 return False
1249 return False
1246 except EOFError:
1250 except EOFError:
1247 return False
1251 return False
@@ -2013,7 +2017,7 b' want to merge them back into the new files.""" % locals()'
2013 """Execute magic functions."""
2017 """Execute magic functions."""
2014
2018
2015
2019
2016 cmd = '%sipmagic(%s)' % (pre,make_quoted_expr(iFun + " " + theRest))
2020 cmd = '%s_ip.magic(%s)' % (pre,make_quoted_expr(iFun + " " + theRest))
2017 self.log(cmd,continue_prompt)
2021 self.log(cmd,continue_prompt)
2018 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
2022 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
2019 return cmd
2023 return cmd
@@ -1,5 +1,15 b''
1 2006-01-27 Ville Vainio <vivainio@gmail.com>
1 2006-01-27 Ville Vainio <vivainio@gmail.com>
2
2
3 * iplib.py: Expose ipapi as _ip in builtin namespace.
4 Makes ipmagic (-> _ip.magic), ipsystem (-> _ip.system)
5 and ip_set_hook (-> _ip.set_hook) redundant. % and !
6 syntax now produce _ip.* variant of the commands.
7
8 * "_ip.options().autoedit_syntax = 2" automatically throws
9 user to editor for syntax error correction without prompting.
10
11 2006-01-27 Ville Vainio <vivainio@gmail.com>
12
3 * ipmaker.py: Give "realistic" sys.argv for scripts (without
13 * ipmaker.py: Give "realistic" sys.argv for scripts (without
4 'ipython' at argv[0]) executed through command line.
14 'ipython' at argv[0]) executed through command line.
5 NOTE: this DEPRECATES calling ipython with multiple scripts
15 NOTE: this DEPRECATES calling ipython with multiple scripts
@@ -11,7 +11,7 b' import sys,IPython,re'
11 fil=open("magic.tex","w")
11 fil=open("magic.tex","w")
12 oldout=sys.stdout
12 oldout=sys.stdout
13 sys.stdout=fil
13 sys.stdout=fil
14 ipmagic("magic -latex")
14 _ip.magic("magic -latex")
15 sys.stdout=oldout
15 sys.stdout=oldout
16 fil.close()
16 fil.close()
17
17
General Comments 0
You need to be logged in to leave comments. Login now