~ubuntu-branches/debian/sid/spyder/sid

« back to all changes in this revision

Viewing changes to spyderlib/widgets/externalshell/start_ipython_kernel.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2013-09-06 21:24:11 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20130906212411-ecn5dbxdnjl99ohd
Tags: 2.2.4+dfsg-1
* Imported Upstream version 2.2.4+dfsg
* relax ipython dependency now that spyder support 0.13 and 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import os.path as osp
12
12
 
13
13
 
14
 
def sympy_config(version):
 
14
def sympy_config():
15
15
    """Sympy configuration"""
16
 
    
17
 
    lines = """
 
16
    from spyderlib.utils.programs import is_module_installed
 
17
    
 
18
    lines_new = """
 
19
from sympy.interactive import init_session
 
20
init_session()
 
21
"""
 
22
    
 
23
    lines_old = """
18
24
from __future__ import division
19
25
from sympy import *
20
26
x, y, z, t = symbols('x y z t')
22
28
f, g, h = symbols('f g h', cls=Function)
23
29
"""
24
30
    
25
 
    if version >= '0.7.2':
 
31
    if is_module_installed('sympy', '>=0.7.3'):
 
32
        extension = None
 
33
        return lines_new, extension
 
34
    elif is_module_installed('sympy', '=0.7.2'):
26
35
        extension = 'sympy.interactive.ipythonprinting'
27
 
    else:
 
36
        return lines_old, extension
 
37
    elif is_module_installed('sympy', '>=0.7.0;<0.7.2'):
28
38
        extension = 'sympyprinting'
29
 
    
30
 
    return lines, extension
 
39
        return lines_old, extension
 
40
    else:
 
41
        return None, None
31
42
 
32
43
 
33
44
def kernel_config():
35
46
    from IPython.config.loader import Config, load_pyconfig_files
36
47
    from IPython.core.application import get_ipython_dir
37
48
    from spyderlib.config import CONF
 
49
    from spyderlib.utils.programs import is_module_installed
38
50
    
39
51
    # ---- IPython config ----
40
52
    try:
52
64
    # http://code.google.com/p/spyderlib/issues/detail?id=1052
53
65
    spy_cfg.InteractiveShell.xmode = 'Plain'
54
66
    
55
 
    # Pylab activation option
 
67
    # Pylab configuration
 
68
    mpl_installed = is_module_installed('matplotlib')
56
69
    pylab_o = CONF.get('ipython_console', 'pylab')
57
70
    
58
 
    # Automatically load Pylab and Numpy
59
 
    autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload')
60
 
    spy_cfg.IPKernelApp.pylab_import_all = pylab_o and autoload_pylab_o
61
 
    
62
 
    # Pylab backend configuration
63
 
    if pylab_o:
 
71
    if mpl_installed and pylab_o:
64
72
        backend_o = CONF.get('ipython_console', 'pylab/backend', 0)
65
73
        backends = {0: 'inline', 1: 'auto', 2: 'qt', 3: 'osx', 4: 'gtk',
66
74
                    5: 'wx', 6: 'tk'}
67
75
        spy_cfg.IPKernelApp.pylab = backends[backend_o]
68
76
        
 
77
        # Automatically load Pylab and Numpy
 
78
        autoload_pylab_o = CONF.get('ipython_console', 'pylab/autoload')
 
79
        spy_cfg.IPKernelApp.pylab_import_all = autoload_pylab_o
 
80
        
69
81
        # Inline backend configuration
70
82
        if backends[backend_o] == 'inline':
71
83
           # Figure format
112
124
    # Sympy loading
113
125
    sympy_o = CONF.get('ipython_console', 'symbolic_math')
114
126
    if sympy_o:
115
 
        try:
116
 
            from sympy import __version__ as version
117
 
            lines, extension = sympy_config(version)
 
127
        lines, extension = sympy_config()
 
128
        if lines is not None:
118
129
            if run_lines_o:
119
130
                spy_cfg.IPKernelApp.exec_lines.append(lines)
120
131
            else:
121
132
                spy_cfg.IPKernelApp.exec_lines = [lines]
122
 
            spy_cfg.IPKernelApp.extra_extension = extension
123
 
            spy_cfg.LaTeXTool.backends = ['dvipng', 'matplotlib']
124
 
        except ImportError:
125
 
            pass
 
133
            if extension:
 
134
                spy_cfg.IPKernelApp.extra_extension = extension
 
135
                spy_cfg.LaTeXTool.backends = ['dvipng', 'matplotlib']
126
136
    
127
137
    # Merge IPython and Spyder configs. Spyder prefs will have prevalence
128
138
    # over IPython ones
133
143
def set_edit_magic(shell):
134
144
    """Use %edit to open files in Spyder"""
135
145
    from spyderlib.utils import programs
 
146
    from spyderlib.baseconfig import IPYTHON_QT_MODULE, SUPPORTED_IPYTHON
136
147
    
137
 
    if programs.is_module_installed('IPython.frontend.qt', '>=0.13'):
 
148
    if programs.is_module_installed(IPYTHON_QT_MODULE, SUPPORTED_IPYTHON):
138
149
        # For some users, trying to replace %edit with open_in_spyder could
139
150
        # give a crash when starting a kernel. I've seen it after updating
140
151
        # from 2.1
165
176
 
166
177
# Fire up the kernel instance.
167
178
try:
168
 
    from IPython.zmq.ipkernel import IPKernelApp  # 0.13
 
179
    from IPython.kernel.zmq.kernelapp import IPKernelApp  # 1.0
169
180
except ImportError:
170
 
    from IPython.kernel.zmq.kernelapp import IPKernelApp  # 0.14
171
 
 
 
181
    from IPython.zmq.ipkernel import IPKernelApp  # 0.13  (analysis:ignore)
 
182
    
172
183
ipk_temp = IPKernelApp.instance()
173
184
ipk_temp.config = kernel_config()
174
185
ipk_temp.initialize()