##// END OF EJS Templates
Added ipapi, the extension api for ipython....
vivainio -
Show More
@@ -0,0 +1,78 b''
1 ''' IPython customization API
2
3 Your one-stop module for configuring ipython
4
5 This is experimental, use at your own risk.
6
7 All names prefixed by underscores are for internal use, not part
8 of the public api.
9
10 No formal doc yet, here's an example that you can just put
11 to a module and import from ipython.
12
13 -----------------------------------------------
14 import IPython.ipapi as ip
15
16 def ankka_f(self, arg):
17 print "Ankka",self,"says uppercase:",arg.upper()
18
19 ip.expose_magic("ankka",ankka_f)
20
21 ip.magic('alias sayhi echo "Testing, hi ok"')
22 ip.magic('alias helloworld echo "Hello world"')
23 ip.system('pwd')
24
25 ip.ex('import re')
26 ip.ex("""
27 def funcci(a,b):
28 print a+b
29 print funcci(3,4)
30 """)
31 ip.ex("funcci(348,9)")
32
33 def jed_editor(self,filename, linenum=None):
34 print "Calling my own editor, jed ... via hook!"
35 import os
36 if linenum is None: linenum = 0
37 os.system('jed +%d %s' % (linenum, filename))
38 print "exiting jed"
39
40 ip.set_hook('editor',jed_editor)
41 print "done!"
42
43 '''
44
45
46
47
48 def _init_with_shell(ip):
49 global magic
50 magic = ip.ipmagic
51 global system
52 system = ip.ipsystem
53 global set_hook
54 set_hook = ip.set_hook
55 global __IP
56 __IP = ip
57
58 def user_ns():
59 return __IP.user_ns
60
61 def expose_magic(magicname, func):
62 ''' Expose own function as magic function for ipython
63
64 def foo_impl(self,parameter_s=''):
65 """My very own magic!. (Use docstrings, IPython reads them)."""
66 print 'Magic function. Passed parameter is between < >: <'+parameter_s+'>'
67 print 'The self object is:',self
68
69 ipapi.expose_magic("foo",foo_impl)
70 '''
71
72 from IPython import Magic
73
74 setattr(Magic.Magic, "magic_" + magicname, func)
75
76 def ex(cmd):
77 """ Execute a normal python statement """
78 exec cmd in user_ns() No newline at end of file
@@ -6,7 +6,7 b' Uses syntax highlighting for presenting the various information elements.'
6 6 Similar in spirit to the inspect module, but all calls take a name argument to
7 7 reference the name under which an object is being read.
8 8
9 $Id: OInspect.py 958 2005-12-27 23:17:51Z fperez $
9 $Id: OInspect.py 1016 2006-01-14 00:54:23Z vivainio $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -268,6 +268,8 b' class Inspector:'
268 268 ds = "Alias to the system command:\n %s" % obj[1]
269 269 else:
270 270 ds = getdoc(obj)
271 if ds is None:
272 ds = '<no docstring>'
271 273 if formatter is not None:
272 274 ds = formatter(ds)
273 275
@@ -27,7 +27,7 b' IPython tries to:'
27 27
28 28 IPython requires Python 2.2 or newer.
29 29
30 $Id: __init__.py 1014 2006-01-13 19:16:41Z vivainio $"""
30 $Id: __init__.py 1016 2006-01-14 00:54:23Z vivainio $"""
31 31
32 32 #*****************************************************************************
33 33 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -44,7 +44,8 b" if sys.version[0:3] < '2.3':"
44 44 # Define what gets imported with a 'from IPython import *'
45 45 __all__ = ['deep_reload','genutils','ipstruct','ultraTB','DPyGetOpt',
46 46 'Itpl','hooks','ConfigLoader','OutputTrap','Release','Shell',
47 'platutils','platutils_win32','platutils_posix','platutils_dummy']
47 'platutils','platutils_win32','platutils_posix','platutils_dummy',
48 'ipapi']
48 49
49 50 # Load __all__ in IPython namespace so that a simple 'import IPython' gives
50 51 # access to them via IPython.<name>
@@ -2,11 +2,11 b''
2 2 """
3 3 IPython -- An enhanced Interactive Python
4 4
5 Requires Python 2.1 or newer.
5 Requires Python 2.3 or newer.
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 1015 2006-01-13 22:47:06Z vivainio $
9 $Id: iplib.py 1016 2006-01-14 00:54:23Z vivainio $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -74,6 +74,7 b' from IPython.ipstruct import Struct'
74 74 from IPython.background_jobs import BackgroundJobManager
75 75 from IPython.usage import cmd_line_usage,interactive_usage
76 76 from IPython.genutils import *
77 import IPython.ipapi
77 78
78 79 # Globals
79 80
@@ -190,6 +191,10 b' class InteractiveShell(object,Magic):'
190 191 user_ns = None,user_global_ns=None,banner2='',
191 192 custom_exceptions=((),None),embedded=False):
192 193
194 # first thing: introduce ourselves to IPython.ipapi which is uncallable
195 # before it knows an InteractiveShell object. Uninitialized state is ok
196 IPython.ipapi._init_with_shell(self)
197
193 198 # some minimal strict typechecks. For some core data structures, I
194 199 # want actual basic python types, not just anything that looks like
195 200 # one. This is especially true for namespaces.
@@ -821,8 +826,8 b' class InteractiveShell(object,Magic):'
821 826
822 827 args = arg_s.split(' ',1)
823 828 magic_name = args[0]
824 if magic_name.startswith(self.ESC_MAGIC):
825 magic_name = magic_name[1:]
829 magic_name = magic_name.lstrip(self.ESC_MAGIC)
830
826 831 try:
827 832 magic_args = args[1]
828 833 except IndexError:
@@ -1,16 +1,20 b''
1 1 2006-01-13 Ville Vainio <vivainio@gmail.com>
2 2
3 3 * IPython/platutils*.py: platform specific utility functions,
4 so far only set_term_title is implemented (change terminal
5 label in windowing systems). %cd now changes the title to
6 current dir.
4 so far only set_term_title is implemented (change terminal
5 label in windowing systems). %cd now changes the title to
6 current dir.
7 7
8 * IPython/Release.py: Added myself to "authors" list,
8 * IPython/Release.py: Added myself to "authors" list,
9 9 had to create new files.
10 10
11 11 * IPython/iplib.py (handle_shell_escape): fixed logical flaw in
12 12 shell escape; not a known bug but had potential to be one in the
13 13 future.
14
15 * IPython/ipapi.py (added),OInspect.py,iplib.py: "Public"
16 extension API for IPython! See the module for usage example. Fix
17 OInspect for docstring-less magic functions.
14 18
15 19
16 20 2006-01-13 Fernando Perez <Fernando.Perez@colorado.edu>
General Comments 0
You need to be logged in to leave comments. Login now