Show More
@@ -1,14 +1,28 b'' | |||
|
1 | 1 | ''' IPython customization API |
|
2 | 2 | |
|
3 | Your one-stop module for configuring ipython | |
|
3 | Your one-stop module for configuring & extending ipython | |
|
4 | 4 | |
|
5 | This is experimental, use at your own risk. | |
|
5 | The API will probably break when ipython 1.0 is released, but so | |
|
6 | will the other configuration method (rc files). | |
|
6 | 7 | |
|
7 | 8 | All names prefixed by underscores are for internal use, not part |
|
8 | 9 | of the public api. |
|
9 | 10 | |
|
10 | No formal doc yet, here's an example that you can just put | |
|
11 | to a module and import from ipython. | |
|
11 | Below is an example that you can just put to a module and import from ipython. | |
|
12 | ||
|
13 | A good practice is to install the config script below as e.g. | |
|
14 | ||
|
15 | ~/.ipython/my_private_conf.py | |
|
16 | ||
|
17 | And do | |
|
18 | ||
|
19 | import_mod my_private_conf | |
|
20 | ||
|
21 | in ~/.ipython/ipythonrc | |
|
22 | ||
|
23 | That way the module is imported at startup and you can have all your | |
|
24 | personal configuration (as opposed to boilerplate ipythonrc-PROFILENAME | |
|
25 | stuff) in there. | |
|
12 | 26 | |
|
13 | 27 | ----------------------------------------------- |
|
14 | 28 | import IPython.ipapi as ip |
@@ -38,13 +52,14 b' def jed_editor(self,filename, linenum=None):' | |||
|
38 | 52 | print "exiting jed" |
|
39 | 53 | |
|
40 | 54 | ip.set_hook('editor',jed_editor) |
|
55 | ||
|
56 | o = ip.options() | |
|
57 | o.autocall = 2 # FULL autocall mode | |
|
58 | ||
|
41 | 59 | print "done!" |
|
42 | 60 | |
|
43 | 61 | ''' |
|
44 | 62 | |
|
45 | ||
|
46 | ||
|
47 | ||
|
48 | 63 | def _init_with_shell(ip): |
|
49 | 64 | global magic |
|
50 | 65 | magic = ip.ipmagic |
@@ -52,9 +67,14 b' def _init_with_shell(ip):' | |||
|
52 | 67 | system = ip.ipsystem |
|
53 | 68 | global set_hook |
|
54 | 69 | set_hook = ip.set_hook |
|
70 | ||
|
55 | 71 | global __IP |
|
56 | 72 | __IP = ip |
|
57 | 73 | |
|
74 | def options(): | |
|
75 | """ All configurable variables """ | |
|
76 | return __IP.rc | |
|
77 | ||
|
58 | 78 | def user_ns(): |
|
59 | 79 | return __IP.user_ns |
|
60 | 80 | |
@@ -72,7 +92,43 b' def expose_magic(magicname, func):' | |||
|
72 | 92 | from IPython import Magic |
|
73 | 93 | |
|
74 | 94 | setattr(Magic.Magic, "magic_" + magicname, func) |
|
95 | ||
|
96 | class asmagic: | |
|
97 | """ Decorator for exposing magics in a friendly 2.4 decorator form | |
|
98 | ||
|
99 | @ip.asmagic("foo") | |
|
100 | def f(self,arg): | |
|
101 | pring "arg given:",arg | |
|
102 | ||
|
103 | After this, %foo is a magic function. | |
|
104 | """ | |
|
105 | ||
|
106 | def __init__(self,magicname): | |
|
107 | self.name = magicname | |
|
108 | ||
|
109 | def __call__(self,f): | |
|
110 | expose_magic(self.name, f) | |
|
111 | return f | |
|
112 | ||
|
113 | class ashook: | |
|
114 | """ Decorator for exposing magics in a friendly 2.4 decorator form | |
|
115 | ||
|
116 | @ip.ashook("editor") | |
|
117 | def jed_editor(self,filename, linenum=None): | |
|
118 | import os | |
|
119 | if linenum is None: linenum = 0 | |
|
120 | os.system('jed +%d %s' % (linenum, filename)) | |
|
121 | ||
|
122 | """ | |
|
75 | 123 | |
|
124 | def __init__(self,name): | |
|
125 | self.name = name | |
|
126 | ||
|
127 | def __call__(self,f): | |
|
128 | set_hook(self.name, f) | |
|
129 | return f | |
|
130 | ||
|
131 | ||
|
76 | 132 | def ex(cmd): |
|
77 | 133 | """ Execute a normal python statement """ |
|
78 | 134 | exec cmd in user_ns() No newline at end of file |
@@ -6,7 +6,7 b' 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 101 |
|
|
9 | $Id: iplib.py 1017 2006-01-14 09:46:45Z vivainio $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
@@ -192,7 +192,7 b' class InteractiveShell(object,Magic):' | |||
|
192 | 192 | custom_exceptions=((),None),embedded=False): |
|
193 | 193 | |
|
194 | 194 | # first thing: introduce ourselves to IPython.ipapi which is uncallable |
|
195 |
# before it knows an InteractiveShell object. |
|
|
195 | # before it knows an InteractiveShell object. | |
|
196 | 196 | IPython.ipapi._init_with_shell(self) |
|
197 | 197 | |
|
198 | 198 | # some minimal strict typechecks. For some core data structures, I |
@@ -6,7 +6,7 b' Requires Python 2.1 or better.' | |||
|
6 | 6 | |
|
7 | 7 | This file contains the main make_IPython() starter function. |
|
8 | 8 | |
|
9 |
$Id: ipmaker.py 10 |
|
|
9 | $Id: ipmaker.py 1017 2006-01-14 09:46:45Z vivainio $""" | |
|
10 | 10 | |
|
11 | 11 | #***************************************************************************** |
|
12 | 12 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
@@ -415,6 +415,7 b" object? -> Details about 'object'. ?object also works, ?? prints more." | |||
|
415 | 415 | warn('Profile configuration file %s not found. Ignoring request.' |
|
416 | 416 | % (opts_all.profile) ) |
|
417 | 417 | |
|
418 | ||
|
418 | 419 | # load the config file |
|
419 | 420 | rcfiledata = None |
|
420 | 421 | if opts_all.quick: |
@@ -553,7 +554,7 b" object? -> Details about 'object'. ?object also works, ?? prints more." | |||
|
553 | 554 | #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who |
|
554 | 555 | |
|
555 | 556 | # Now run through the different sections of the users's config |
|
556 | if IP_rc.debug: | |
|
557 | if IP_rc.debug: | |
|
557 | 558 | print 'Trying to execute the following configuration structure:' |
|
558 | 559 | print '(Things listed first are deeper in the inclusion tree and get' |
|
559 | 560 | print 'loaded first).\n' |
@@ -1,3 +1,10 b'' | |||
|
1 | 2006-01-14 Ville Vainio <vivainio@gmail.com> | |
|
2 | ||
|
3 | * IPython/ipapi.py (ashook, asmagic, options): Added convenience | |
|
4 | ipapi decorators for python 2.4 users, options() provides access to rc | |
|
5 | data. | |
|
6 | ||
|
7 | ||
|
1 | 8 | 2006-01-13 Ville Vainio <vivainio@gmail.com> |
|
2 | 9 | |
|
3 | 10 | * IPython/platutils*.py: platform specific utility functions, |
General Comments 0
You need to be logged in to leave comments.
Login now