my .ipython/ipy_user_conf.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
""" User configuration file for IPython
 
This is a more flexible and safe way to configure ipython than *rc files
(ipythonrc, ipythonrc-pysh etc.)
 
This file is always imported on ipython startup. You can import the
ipython extensions you need here (see IPython/Extensions directory).
 
Feel free to edit this file to customize your ipython experience.
 
Note that as such this file does nothing, for backwards compatibility.
Consult e.g. file 'ipy_profile_sh.py' for an example of the things 
you can do here.
 
See http://ipython.scipy.org/moin/IpythonExtensionApi for detailed
description on what you could do here.
"""
 
# Most of your config files and extensions will probably start with this import
 
import IPython.ipapi
ip = IPython.ipapi.get()
 
# You probably want to uncomment this if you did %upgrade -nolegacy
# import ipy_defaults    
 
import os   
 
def main():   
 
    # uncomment if you want to get ipython -p sh behaviour
    # without having to use command line switches  
    # import ipy_profile_sh
 
    # Configure your favourite editor?
    # Good idea e.g. for %edit os.path.isfile
 
    #import ipy_editors
 
    # Choose one of these:
 
    #ipy_editors.scite()
    #ipy_editors.scite('c:/opt/scite/scite.exe')
    #ipy_editors.komodo()
    #ipy_editors.idle()
    # ... or many others, try 'ipy_editors??' after import to see them
 
    # Or roll your own:
    #ipy_editors.install_editor("c:/opt/jed +$line $file")
 
 
    o = ip.options
    # An example on how to set options
    o.autocall = 0
    o.system_verbose = 0
    # when encountering syntax error, ask if editor should be sent there
    o.autoedit_syntax = 1
    # do not import all the pylab stuff
    o.pylab_import_all = 0
 
    #import_all("os sys")
    #execf('~/_ipython/ns.py')
 
 
    # -- prompt
    # A different, more compact set of prompts from the default ones, that
    # always show your current location in the filesystem:
 
    #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
    #o.prompt_in2 = r'.\D: '
    #o.prompt_out = r'[\#] '
 
    # Try one of these color settings if you can't read the text easily
    # autoexec is a list of IPython commands to execute on startup
    o.autoexec.append('%colors LightBG')
    #o.autoexec.append('%colors NoColor')
    #o.autoexec.append('%colors Linux')
 
    # for sane integer division that converts to float (1/2 == 0.5)
    #o.autoexec.append('from __future__ import division')
 
    # For %tasks and %kill
    #import jobctrl 
 
    # For autoreloading of modules (%autoreload, %aimport)    
    #import ipy_autoreload
 
    # For winpdb support (%wdb)
    #import ipy_winpdb
 
    # For bzr completer, requires bzrlib (the python installation of bzr)
    #ip.load('ipy_bzr')
 
    # Tab completer that is not quite so picky (i.e. 
    # "foo".<TAB> and str(2).<TAB> will work). Complete 
    # at your own risk!
    import ipy_greedycompleter
 
    # If you are on Linux, you may be annoyed by
    # "Display all N possibilities? (y or n)" on tab completion,
    # as well as the paging through "more". Uncomment the following
    # lines to disable that behaviour
    #import readline
    #readline.parse_and_bind('set completion-query-items 1000')
    #readline.parse_and_bind('set page-completions no')
 
    # to see my modules when starting ipython not from a bash
    import sys
    sys.path.append('/home/buschi/lib/python2.6/site-packages')
    # for gvim as editor,  http://ipython.scipy.org/moin/Cookbook/IPythonGVim
    ipython_pid = os.getpid()
    import ipy_vimserver
    ipy_vimserver.setup("ipython_session_"+str(ipython_pid))
    #ipy_vimserver.setup("ipython")
    # http://projects.scipy.org/ipython/ipython/wiki/CookBook
    import ipythonhooks
    #ip_set_hook('fix_error_editor',ipythonhooks.fix_error_editor,str_key=str(ipython_pid))
    ip_set_hook('fix_error_editor',ipythonhooks.fix_error_editor)
 
    if os.getenv("IPYFILE") != '':
        o.autoexec.append('vim '+os.getenv("IPYFILE"))
 
# some config helper functions you can use 
def import_all(modules):
    """ Usage: import_all("os sys") """ 
    for m in modules.split():
        ip.ex("from %s import *" % m)
 
def execf(fname):
    """ Execute a file in user namespace """
    ip.ex('execfile("%s")' % os.path.expanduser(fname))
 
main()

Leave a Reply