##// END OF EJS Templates
Cleanup -pylab handling with faster logic.
Fernando Perez -
Show More
@@ -1,378 +1,375 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 """
3 """
4 The :class:`~IPython.core.application.Application` object for the command
4 The :class:`~IPython.core.application.Application` object for the command
5 line :command:`ipython` program.
5 line :command:`ipython` program.
6
6
7 Authors
7 Authors
8 -------
8 -------
9
9
10 * Brian Granger
10 * Brian Granger
11 * Fernando Perez
11 * Fernando Perez
12 * Min Ragan-Kelley
12 * Min Ragan-Kelley
13 """
13 """
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Copyright (C) 2008-2010 The IPython Development Team
16 # Copyright (C) 2008-2010 The IPython Development Team
17 #
17 #
18 # Distributed under the terms of the BSD License. The full license is in
18 # Distributed under the terms of the BSD License. The full license is in
19 # the file COPYING, distributed as part of this software.
19 # the file COPYING, distributed as part of this software.
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Imports
23 # Imports
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25
25
26 from __future__ import absolute_import
26 from __future__ import absolute_import
27
27
28 import logging
28 import logging
29 import os
29 import os
30 import sys
30 import sys
31
31
32 from IPython.config.loader import (
32 from IPython.config.loader import (
33 Config, PyFileConfigLoader
33 Config, PyFileConfigLoader
34 )
34 )
35 from IPython.config.application import boolean_flag
35 from IPython.config.application import boolean_flag
36 from IPython.core import release
36 from IPython.core import release
37 from IPython.core import usage
37 from IPython.core import usage
38 from IPython.core.crashhandler import CrashHandler
38 from IPython.core.crashhandler import CrashHandler
39 from IPython.core.formatters import PlainTextFormatter
39 from IPython.core.formatters import PlainTextFormatter
40 from IPython.core.application import (
40 from IPython.core.application import (
41 ProfileDir, BaseIPythonApplication, base_flags, base_aliases
41 ProfileDir, BaseIPythonApplication, base_flags, base_aliases
42 )
42 )
43 from IPython.core.shellapp import (
43 from IPython.core.shellapp import (
44 InteractiveShellApp, shell_flags, shell_aliases
44 InteractiveShellApp, shell_flags, shell_aliases
45 )
45 )
46 from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
46 from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
47 from IPython.lib import inputhook
47 from IPython.lib import inputhook
48 from IPython.utils import warn
48 from IPython.utils import warn
49 from IPython.utils.path import get_ipython_dir, check_for_old_config
49 from IPython.utils.path import get_ipython_dir, check_for_old_config
50 from IPython.utils.traitlets import (
50 from IPython.utils.traitlets import (
51 Bool, Dict, CaselessStrEnum
51 Bool, Dict, CaselessStrEnum
52 )
52 )
53
53
54 #-----------------------------------------------------------------------------
54 #-----------------------------------------------------------------------------
55 # Globals, utilities and helpers
55 # Globals, utilities and helpers
56 #-----------------------------------------------------------------------------
56 #-----------------------------------------------------------------------------
57
57
58 #: The default config file name for this application.
58 #: The default config file name for this application.
59 default_config_file_name = u'ipython_config.py'
59 default_config_file_name = u'ipython_config.py'
60
60
61 _examples = """
61 _examples = """
62 ipython --pylab # start in pylab mode
62 ipython --pylab # start in pylab mode
63 ipython --pylab=qt # start in pylab mode with the qt4 backend
63 ipython --pylab=qt # start in pylab mode with the qt4 backend
64 ipython --log-level=DEBUG # set logging to DEBUG
64 ipython --log-level=DEBUG # set logging to DEBUG
65 ipython --profile=foo # start with profile foo
65 ipython --profile=foo # start with profile foo
66
66
67 ipython qtconsole # start the qtconsole GUI application
67 ipython qtconsole # start the qtconsole GUI application
68 ipython qtconsole -h # show the help string for the qtconsole subcmd
68 ipython qtconsole -h # show the help string for the qtconsole subcmd
69
69
70 ipython profile create foo # create profile foo w/ default config files
70 ipython profile create foo # create profile foo w/ default config files
71 ipython profile -h # show the help string for the profile subcmd
71 ipython profile -h # show the help string for the profile subcmd
72 """
72 """
73
73
74 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
75 # Crash handler for this application
75 # Crash handler for this application
76 #-----------------------------------------------------------------------------
76 #-----------------------------------------------------------------------------
77
77
78 class IPAppCrashHandler(CrashHandler):
78 class IPAppCrashHandler(CrashHandler):
79 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
79 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
80
80
81 def __init__(self, app):
81 def __init__(self, app):
82 contact_name = release.authors['Fernando'][0]
82 contact_name = release.authors['Fernando'][0]
83 contact_email = release.authors['Fernando'][1]
83 contact_email = release.authors['Fernando'][1]
84 bug_tracker = 'http://github.com/ipython/ipython/issues'
84 bug_tracker = 'http://github.com/ipython/ipython/issues'
85 super(IPAppCrashHandler,self).__init__(
85 super(IPAppCrashHandler,self).__init__(
86 app, contact_name, contact_email, bug_tracker
86 app, contact_name, contact_email, bug_tracker
87 )
87 )
88
88
89 def make_report(self,traceback):
89 def make_report(self,traceback):
90 """Return a string containing a crash report."""
90 """Return a string containing a crash report."""
91
91
92 sec_sep = self.section_sep
92 sec_sep = self.section_sep
93 # Start with parent report
93 # Start with parent report
94 report = [super(IPAppCrashHandler, self).make_report(traceback)]
94 report = [super(IPAppCrashHandler, self).make_report(traceback)]
95 # Add interactive-specific info we may have
95 # Add interactive-specific info we may have
96 rpt_add = report.append
96 rpt_add = report.append
97 try:
97 try:
98 rpt_add(sec_sep+"History of session input:")
98 rpt_add(sec_sep+"History of session input:")
99 for line in self.app.shell.user_ns['_ih']:
99 for line in self.app.shell.user_ns['_ih']:
100 rpt_add(line)
100 rpt_add(line)
101 rpt_add('\n*** Last line of input (may not be in above history):\n')
101 rpt_add('\n*** Last line of input (may not be in above history):\n')
102 rpt_add(self.app.shell._last_input_line+'\n')
102 rpt_add(self.app.shell._last_input_line+'\n')
103 except:
103 except:
104 pass
104 pass
105
105
106 return ''.join(report)
106 return ''.join(report)
107
107
108 #-----------------------------------------------------------------------------
108 #-----------------------------------------------------------------------------
109 # Aliases and Flags
109 # Aliases and Flags
110 #-----------------------------------------------------------------------------
110 #-----------------------------------------------------------------------------
111 flags = dict(base_flags)
111 flags = dict(base_flags)
112 flags.update(shell_flags)
112 flags.update(shell_flags)
113 addflag = lambda *args: flags.update(boolean_flag(*args))
113 addflag = lambda *args: flags.update(boolean_flag(*args))
114 addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax',
114 addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax',
115 'Turn on auto editing of files with syntax errors.',
115 'Turn on auto editing of files with syntax errors.',
116 'Turn off auto editing of files with syntax errors.'
116 'Turn off auto editing of files with syntax errors.'
117 )
117 )
118 addflag('banner', 'TerminalIPythonApp.display_banner',
118 addflag('banner', 'TerminalIPythonApp.display_banner',
119 "Display a banner upon starting IPython.",
119 "Display a banner upon starting IPython.",
120 "Don't display a banner upon starting IPython."
120 "Don't display a banner upon starting IPython."
121 )
121 )
122 addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit',
122 addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit',
123 """Set to confirm when you try to exit IPython with an EOF (Control-D
123 """Set to confirm when you try to exit IPython with an EOF (Control-D
124 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
124 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
125 you can force a direct exit without any confirmation.""",
125 you can force a direct exit without any confirmation.""",
126 "Don't prompt the user when exiting."
126 "Don't prompt the user when exiting."
127 )
127 )
128 addflag('term-title', 'TerminalInteractiveShell.term_title',
128 addflag('term-title', 'TerminalInteractiveShell.term_title',
129 "Enable auto setting the terminal title.",
129 "Enable auto setting the terminal title.",
130 "Disable auto setting the terminal title."
130 "Disable auto setting the terminal title."
131 )
131 )
132 classic_config = Config()
132 classic_config = Config()
133 classic_config.InteractiveShell.cache_size = 0
133 classic_config.InteractiveShell.cache_size = 0
134 classic_config.PlainTextFormatter.pprint = False
134 classic_config.PlainTextFormatter.pprint = False
135 classic_config.InteractiveShell.prompt_in1 = '>>> '
135 classic_config.InteractiveShell.prompt_in1 = '>>> '
136 classic_config.InteractiveShell.prompt_in2 = '... '
136 classic_config.InteractiveShell.prompt_in2 = '... '
137 classic_config.InteractiveShell.prompt_out = ''
137 classic_config.InteractiveShell.prompt_out = ''
138 classic_config.InteractiveShell.separate_in = ''
138 classic_config.InteractiveShell.separate_in = ''
139 classic_config.InteractiveShell.separate_out = ''
139 classic_config.InteractiveShell.separate_out = ''
140 classic_config.InteractiveShell.separate_out2 = ''
140 classic_config.InteractiveShell.separate_out2 = ''
141 classic_config.InteractiveShell.colors = 'NoColor'
141 classic_config.InteractiveShell.colors = 'NoColor'
142 classic_config.InteractiveShell.xmode = 'Plain'
142 classic_config.InteractiveShell.xmode = 'Plain'
143
143
144 flags['classic']=(
144 flags['classic']=(
145 classic_config,
145 classic_config,
146 "Gives IPython a similar feel to the classic Python prompt."
146 "Gives IPython a similar feel to the classic Python prompt."
147 )
147 )
148 # # log doesn't make so much sense this way anymore
148 # # log doesn't make so much sense this way anymore
149 # paa('--log','-l',
149 # paa('--log','-l',
150 # action='store_true', dest='InteractiveShell.logstart',
150 # action='store_true', dest='InteractiveShell.logstart',
151 # help="Start logging to the default log file (./ipython_log.py).")
151 # help="Start logging to the default log file (./ipython_log.py).")
152 #
152 #
153 # # quick is harder to implement
153 # # quick is harder to implement
154 flags['quick']=(
154 flags['quick']=(
155 {'TerminalIPythonApp' : {'quick' : True}},
155 {'TerminalIPythonApp' : {'quick' : True}},
156 "Enable quick startup with no config files."
156 "Enable quick startup with no config files."
157 )
157 )
158
158
159 flags['i'] = (
159 flags['i'] = (
160 {'TerminalIPythonApp' : {'force_interact' : True}},
160 {'TerminalIPythonApp' : {'force_interact' : True}},
161 """also works as '-i'
161 """If running code from the command line, become interactive afterwards.
162 If running code from the command line, become interactive afterwards."""
162 Note: can also be given simply as '-i.'"""
163 )
163 )
164 flags['pylab'] = (
164 flags['pylab'] = (
165 {'TerminalIPythonApp' : {'pylab' : 'auto'}},
165 {'TerminalIPythonApp' : {'pylab' : 'auto'}},
166 """Pre-load matplotlib and numpy for interactive use with
166 """Pre-load matplotlib and numpy for interactive use with
167 the default matplotlib backend."""
167 the default matplotlib backend."""
168 )
168 )
169
169
170 aliases = dict(base_aliases)
170 aliases = dict(base_aliases)
171 aliases.update(shell_aliases)
171 aliases.update(shell_aliases)
172
172
173 # it's possible we don't want short aliases for *all* of these:
173 # it's possible we don't want short aliases for *all* of these:
174 aliases.update(dict(
174 aliases.update(dict(
175 gui='TerminalIPythonApp.gui',
175 gui='TerminalIPythonApp.gui',
176 pylab='TerminalIPythonApp.pylab',
176 pylab='TerminalIPythonApp.pylab',
177 ))
177 ))
178
178
179 #-----------------------------------------------------------------------------
179 #-----------------------------------------------------------------------------
180 # Main classes and functions
180 # Main classes and functions
181 #-----------------------------------------------------------------------------
181 #-----------------------------------------------------------------------------
182
182
183
184 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
183 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
185 name = u'ipython'
184 name = u'ipython'
186 description = usage.cl_usage
185 description = usage.cl_usage
187 default_config_file_name = default_config_file_name
186 default_config_file_name = default_config_file_name
188 crash_handler_class = IPAppCrashHandler
187 crash_handler_class = IPAppCrashHandler
189 examples = _examples
188 examples = _examples
190
189
191 flags = Dict(flags)
190 flags = Dict(flags)
192 aliases = Dict(aliases)
191 aliases = Dict(aliases)
193 classes = [InteractiveShellApp, TerminalInteractiveShell, ProfileDir, PlainTextFormatter]
192 classes = [InteractiveShellApp, TerminalInteractiveShell, ProfileDir,
193 PlainTextFormatter]
194 subcommands = Dict(dict(
194 subcommands = Dict(dict(
195 qtconsole=('IPython.frontend.qt.console.qtconsoleapp.IPythonQtConsoleApp',
195 qtconsole=('IPython.frontend.qt.console.qtconsoleapp.IPythonQtConsoleApp',
196 """Launch the IPython Qt Console."""
196 """Launch the IPython Qt Console."""
197 ),
197 ),
198 profile = ("IPython.core.profileapp.ProfileApp",
198 profile = ("IPython.core.profileapp.ProfileApp",
199 "Create and manage IPython profiles.")
199 "Create and manage IPython profiles.")
200 ))
200 ))
201
201
202 # *do* autocreate requested profile, but don't create the config file.
202 # *do* autocreate requested profile, but don't create the config file.
203 auto_create=Bool(True)
203 auto_create=Bool(True)
204 # configurables
204 # configurables
205 ignore_old_config=Bool(False, config=True,
205 ignore_old_config=Bool(False, config=True,
206 help="Suppress warning messages about legacy config files"
206 help="Suppress warning messages about legacy config files"
207 )
207 )
208 quick = Bool(False, config=True,
208 quick = Bool(False, config=True,
209 help="""Start IPython quickly by skipping the loading of config files."""
209 help="""Start IPython quickly by skipping the loading of config files."""
210 )
210 )
211 def _quick_changed(self, name, old, new):
211 def _quick_changed(self, name, old, new):
212 if new:
212 if new:
213 self.load_config_file = lambda *a, **kw: None
213 self.load_config_file = lambda *a, **kw: None
214 self.ignore_old_config=True
214 self.ignore_old_config=True
215
215
216 gui = CaselessStrEnum(('qt','wx','gtk'), config=True,
216 gui = CaselessStrEnum(('qt','wx','gtk'), config=True,
217 help="Enable GUI event loop integration ('qt', 'wx', 'gtk')."
217 help="Enable GUI event loop integration ('qt', 'wx', 'gtk')."
218 )
218 )
219 pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'auto'],
219 pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'auto'],
220 config=True,
220 config=True,
221 help="""Pre-load matplotlib and numpy for interactive use,
221 help="""Pre-load matplotlib and numpy for interactive use,
222 selecting a particular matplotlib backend and loop integration.
222 selecting a particular matplotlib backend and loop integration.
223 """
223 """
224 )
224 )
225 display_banner = Bool(True, config=True,
225 display_banner = Bool(True, config=True,
226 help="Whether to display a banner upon starting IPython."
226 help="Whether to display a banner upon starting IPython."
227 )
227 )
228
228
229 # if there is code of files to run from the cmd line, don't interact
229 # if there is code of files to run from the cmd line, don't interact
230 # unless the --i flag (App.force_interact) is true.
230 # unless the --i flag (App.force_interact) is true.
231 force_interact = Bool(False, config=True,
231 force_interact = Bool(False, config=True,
232 help="""If a command or file is given via the command-line,
232 help="""If a command or file is given via the command-line,
233 e.g. 'ipython foo.py"""
233 e.g. 'ipython foo.py"""
234 )
234 )
235 def _force_interact_changed(self, name, old, new):
235 def _force_interact_changed(self, name, old, new):
236 if new:
236 if new:
237 self.interact = True
237 self.interact = True
238
238
239 def _file_to_run_changed(self, name, old, new):
239 def _file_to_run_changed(self, name, old, new):
240 if new and not self.force_interact:
240 if new and not self.force_interact:
241 self.interact = False
241 self.interact = False
242 _code_to_run_changed = _file_to_run_changed
242 _code_to_run_changed = _file_to_run_changed
243
243
244 # internal, not-configurable
244 # internal, not-configurable
245 interact=Bool(True)
245 interact=Bool(True)
246
246
247
247
248 def parse_command_line(self, argv=None):
248 def parse_command_line(self, argv=None):
249 """override to allow old '-pylab' flag with deprecation warning"""
249 """override to allow old '-pylab' flag with deprecation warning"""
250
250 argv = sys.argv[1:] if argv is None else argv
251 argv = sys.argv[1:] if argv is None else argv
251
252
252 try:
253 if '-pylab' in argv:
253 idx = argv.index('-pylab')
254 except ValueError:
255 # `-pylab` not given, proceed as normal
256 pass
257 else:
258 # deprecated `-pylab` given,
254 # deprecated `-pylab` given,
259 # warn and transform into current syntax
255 # warn and transform into current syntax
260 argv = list(argv) # copy, don't clobber
256 argv = argv[:] # copy, don't clobber
257 idx = argv.index('-pylab')
261 warn.warn("`-pylab` flag has been deprecated.\n"
258 warn.warn("`-pylab` flag has been deprecated.\n"
262 " Use `--pylab` instead, or `--pylab=foo` to specify a backend.")
259 " Use `--pylab` instead, or `--pylab=foo` to specify a backend.")
263 sub = '--pylab'
260 sub = '--pylab'
264 if len(argv) > idx+1:
261 if len(argv) > idx+1:
265 # check for gui arg, as in '-pylab qt'
262 # check for gui arg, as in '-pylab qt'
266 gui = argv[idx+1]
263 gui = argv[idx+1]
267 if gui in ('wx', 'qt', 'qt4', 'gtk', 'auto'):
264 if gui in ('wx', 'qt', 'qt4', 'gtk', 'auto'):
268 sub = '--pylab='+gui
265 sub = '--pylab='+gui
269 argv.pop(idx+1)
266 argv.pop(idx+1)
270 argv[idx] = sub
267 argv[idx] = sub
271
268
272 return super(TerminalIPythonApp, self).parse_command_line(argv)
269 return super(TerminalIPythonApp, self).parse_command_line(argv)
273
270
274 def initialize(self, argv=None):
271 def initialize(self, argv=None):
275 """Do actions after construct, but before starting the app."""
272 """Do actions after construct, but before starting the app."""
276 super(TerminalIPythonApp, self).initialize(argv)
273 super(TerminalIPythonApp, self).initialize(argv)
277 if self.subapp is not None:
274 if self.subapp is not None:
278 # don't bother initializing further, starting subapp
275 # don't bother initializing further, starting subapp
279 return
276 return
280 if not self.ignore_old_config:
277 if not self.ignore_old_config:
281 check_for_old_config(self.ipython_dir)
278 check_for_old_config(self.ipython_dir)
282 # print self.extra_args
279 # print self.extra_args
283 if self.extra_args:
280 if self.extra_args:
284 self.file_to_run = self.extra_args[0]
281 self.file_to_run = self.extra_args[0]
285 # create the shell
282 # create the shell
286 self.init_shell()
283 self.init_shell()
287 # and draw the banner
284 # and draw the banner
288 self.init_banner()
285 self.init_banner()
289 # Now a variety of things that happen after the banner is printed.
286 # Now a variety of things that happen after the banner is printed.
290 self.init_gui_pylab()
287 self.init_gui_pylab()
291 self.init_extensions()
288 self.init_extensions()
292 self.init_code()
289 self.init_code()
293
290
294 def init_shell(self):
291 def init_shell(self):
295 """initialize the InteractiveShell instance"""
292 """initialize the InteractiveShell instance"""
296 # I am a little hesitant to put these into InteractiveShell itself.
293 # I am a little hesitant to put these into InteractiveShell itself.
297 # But that might be the place for them
294 # But that might be the place for them
298 sys.path.insert(0, '')
295 sys.path.insert(0, '')
299
296
300 # Create an InteractiveShell instance.
297 # Create an InteractiveShell instance.
301 # shell.display_banner should always be False for the terminal
298 # shell.display_banner should always be False for the terminal
302 # based app, because we call shell.show_banner() by hand below
299 # based app, because we call shell.show_banner() by hand below
303 # so the banner shows *before* all extension loading stuff.
300 # so the banner shows *before* all extension loading stuff.
304 self.shell = TerminalInteractiveShell.instance(config=self.config,
301 self.shell = TerminalInteractiveShell.instance(config=self.config,
305 display_banner=False, profile_dir=self.profile_dir,
302 display_banner=False, profile_dir=self.profile_dir,
306 ipython_dir=self.ipython_dir)
303 ipython_dir=self.ipython_dir)
307
304
308 def init_banner(self):
305 def init_banner(self):
309 """optionally display the banner"""
306 """optionally display the banner"""
310 if self.display_banner and self.interact:
307 if self.display_banner and self.interact:
311 self.shell.show_banner()
308 self.shell.show_banner()
312 # Make sure there is a space below the banner.
309 # Make sure there is a space below the banner.
313 if self.log_level <= logging.INFO: print
310 if self.log_level <= logging.INFO: print
314
311
315
312
316 def init_gui_pylab(self):
313 def init_gui_pylab(self):
317 """Enable GUI event loop integration, taking pylab into account."""
314 """Enable GUI event loop integration, taking pylab into account."""
318 gui = self.gui
315 gui = self.gui
319
316
320 # Using `pylab` will also require gui activation, though which toolkit
317 # Using `pylab` will also require gui activation, though which toolkit
321 # to use may be chosen automatically based on mpl configuration.
318 # to use may be chosen automatically based on mpl configuration.
322 if self.pylab:
319 if self.pylab:
323 activate = self.shell.enable_pylab
320 activate = self.shell.enable_pylab
324 if self.pylab == 'auto':
321 if self.pylab == 'auto':
325 gui = None
322 gui = None
326 else:
323 else:
327 gui = self.pylab
324 gui = self.pylab
328 else:
325 else:
329 # Enable only GUI integration, no pylab
326 # Enable only GUI integration, no pylab
330 activate = inputhook.enable_gui
327 activate = inputhook.enable_gui
331
328
332 if gui or self.pylab:
329 if gui or self.pylab:
333 try:
330 try:
334 self.log.info("Enabling GUI event loop integration, "
331 self.log.info("Enabling GUI event loop integration, "
335 "toolkit=%s, pylab=%s" % (gui, self.pylab) )
332 "toolkit=%s, pylab=%s" % (gui, self.pylab) )
336 activate(gui)
333 activate(gui)
337 except:
334 except:
338 self.log.warn("Error in enabling GUI event loop integration:")
335 self.log.warn("Error in enabling GUI event loop integration:")
339 self.shell.showtraceback()
336 self.shell.showtraceback()
340
337
341 def start(self):
338 def start(self):
342 if self.subapp is not None:
339 if self.subapp is not None:
343 return self.subapp.start()
340 return self.subapp.start()
344 # perform any prexec steps:
341 # perform any prexec steps:
345 if self.interact:
342 if self.interact:
346 self.log.debug("Starting IPython's mainloop...")
343 self.log.debug("Starting IPython's mainloop...")
347 self.shell.mainloop()
344 self.shell.mainloop()
348 else:
345 else:
349 self.log.debug("IPython not interactive...")
346 self.log.debug("IPython not interactive...")
350
347
351
348
352 def load_default_config(ipython_dir=None):
349 def load_default_config(ipython_dir=None):
353 """Load the default config file from the default ipython_dir.
350 """Load the default config file from the default ipython_dir.
354
351
355 This is useful for embedded shells.
352 This is useful for embedded shells.
356 """
353 """
357 if ipython_dir is None:
354 if ipython_dir is None:
358 ipython_dir = get_ipython_dir()
355 ipython_dir = get_ipython_dir()
359 profile_dir = os.path.join(ipython_dir, 'profile_default')
356 profile_dir = os.path.join(ipython_dir, 'profile_default')
360 cl = PyFileConfigLoader(default_config_file_name, profile_dir)
357 cl = PyFileConfigLoader(default_config_file_name, profile_dir)
361 try:
358 try:
362 config = cl.load_config()
359 config = cl.load_config()
363 except IOError:
360 except IOError:
364 # no config found
361 # no config found
365 config = Config()
362 config = Config()
366 return config
363 return config
367
364
368
365
369 def launch_new_instance():
366 def launch_new_instance():
370 """Create and run a full blown IPython instance"""
367 """Create and run a full blown IPython instance"""
371 app = TerminalIPythonApp.instance()
368 app = TerminalIPythonApp.instance()
372 app.initialize()
369 app.initialize()
373 app.start()
370 app.start()
374
371
375
372
376 if __name__ == '__main__':
373 if __name__ == '__main__':
377 launch_new_instance()
374 launch_new_instance()
378
375
General Comments 0
You need to be logged in to leave comments. Login now