##// END OF EJS Templates
Adding nbconvert subcommand.
Brian E. Granger -
Show More
@@ -1,395 +1,400 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-2011 The IPython Development Team
16 # Copyright (C) 2008-2011 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, ConfigFileNotFound
33 Config, PyFileConfigLoader, ConfigFileNotFound
34 )
34 )
35 from IPython.config.application import boolean_flag, catch_config_error
35 from IPython.config.application import boolean_flag, catch_config_error
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.completer import IPCompleter
38 from IPython.core.completer import IPCompleter
39 from IPython.core.crashhandler import CrashHandler
39 from IPython.core.crashhandler import CrashHandler
40 from IPython.core.formatters import PlainTextFormatter
40 from IPython.core.formatters import PlainTextFormatter
41 from IPython.core.history import HistoryManager
41 from IPython.core.history import HistoryManager
42 from IPython.core.prompts import PromptManager
42 from IPython.core.prompts import PromptManager
43 from IPython.core.application import (
43 from IPython.core.application import (
44 ProfileDir, BaseIPythonApplication, base_flags, base_aliases
44 ProfileDir, BaseIPythonApplication, base_flags, base_aliases
45 )
45 )
46 from IPython.core.magics import ScriptMagics
46 from IPython.core.magics import ScriptMagics
47 from IPython.core.shellapp import (
47 from IPython.core.shellapp import (
48 InteractiveShellApp, shell_flags, shell_aliases
48 InteractiveShellApp, shell_flags, shell_aliases
49 )
49 )
50 from IPython.terminal.interactiveshell import TerminalInteractiveShell
50 from IPython.terminal.interactiveshell import TerminalInteractiveShell
51 from IPython.utils import warn
51 from IPython.utils import warn
52 from IPython.utils.path import get_ipython_dir, check_for_old_config
52 from IPython.utils.path import get_ipython_dir, check_for_old_config
53 from IPython.utils.traitlets import (
53 from IPython.utils.traitlets import (
54 Bool, List, Dict, CaselessStrEnum
54 Bool, List, Dict, CaselessStrEnum
55 )
55 )
56
56
57 #-----------------------------------------------------------------------------
57 #-----------------------------------------------------------------------------
58 # Globals, utilities and helpers
58 # Globals, utilities and helpers
59 #-----------------------------------------------------------------------------
59 #-----------------------------------------------------------------------------
60
60
61 #: The default config file name for this application.
61 #: The default config file name for this application.
62 default_config_file_name = u'ipython_config.py'
62 default_config_file_name = u'ipython_config.py'
63
63
64 _examples = """
64 _examples = """
65 ipython --pylab # start in pylab mode
65 ipython --pylab # start in pylab mode
66 ipython --pylab=qt # start in pylab mode with the qt4 backend
66 ipython --pylab=qt # start in pylab mode with the qt4 backend
67 ipython --log-level=DEBUG # set logging to DEBUG
67 ipython --log-level=DEBUG # set logging to DEBUG
68 ipython --profile=foo # start with profile foo
68 ipython --profile=foo # start with profile foo
69
69
70 ipython qtconsole # start the qtconsole GUI application
70 ipython qtconsole # start the qtconsole GUI application
71 ipython help qtconsole # show the help for the qtconsole subcmd
71 ipython help qtconsole # show the help for the qtconsole subcmd
72
72
73 ipython console # start the terminal-based console application
73 ipython console # start the terminal-based console application
74 ipython help console # show the help for the console subcmd
74 ipython help console # show the help for the console subcmd
75
75
76 ipython notebook # start the IPython notebook
76 ipython notebook # start the IPython notebook
77 ipython help notebook # show the help for the notebook subcmd
77 ipython help notebook # show the help for the notebook subcmd
78
78
79 ipython profile create foo # create profile foo w/ default config files
79 ipython profile create foo # create profile foo w/ default config files
80 ipython help profile # show the help for the profile subcmd
80 ipython help profile # show the help for the profile subcmd
81
81
82 ipython locate # print the path to the IPython directory
82 ipython locate # print the path to the IPython directory
83 ipython locate profile foo # print the path to the directory for profile `foo`
83 ipython locate profile foo # print the path to the directory for profile `foo`
84
85 ipython nbconvert # convert notebooks to/from other formats
84 """
86 """
85
87
86 #-----------------------------------------------------------------------------
88 #-----------------------------------------------------------------------------
87 # Crash handler for this application
89 # Crash handler for this application
88 #-----------------------------------------------------------------------------
90 #-----------------------------------------------------------------------------
89
91
90 class IPAppCrashHandler(CrashHandler):
92 class IPAppCrashHandler(CrashHandler):
91 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
93 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
92
94
93 def __init__(self, app):
95 def __init__(self, app):
94 contact_name = release.author
96 contact_name = release.author
95 contact_email = release.author_email
97 contact_email = release.author_email
96 bug_tracker = 'https://github.com/ipython/ipython/issues'
98 bug_tracker = 'https://github.com/ipython/ipython/issues'
97 super(IPAppCrashHandler,self).__init__(
99 super(IPAppCrashHandler,self).__init__(
98 app, contact_name, contact_email, bug_tracker
100 app, contact_name, contact_email, bug_tracker
99 )
101 )
100
102
101 def make_report(self,traceback):
103 def make_report(self,traceback):
102 """Return a string containing a crash report."""
104 """Return a string containing a crash report."""
103
105
104 sec_sep = self.section_sep
106 sec_sep = self.section_sep
105 # Start with parent report
107 # Start with parent report
106 report = [super(IPAppCrashHandler, self).make_report(traceback)]
108 report = [super(IPAppCrashHandler, self).make_report(traceback)]
107 # Add interactive-specific info we may have
109 # Add interactive-specific info we may have
108 rpt_add = report.append
110 rpt_add = report.append
109 try:
111 try:
110 rpt_add(sec_sep+"History of session input:")
112 rpt_add(sec_sep+"History of session input:")
111 for line in self.app.shell.user_ns['_ih']:
113 for line in self.app.shell.user_ns['_ih']:
112 rpt_add(line)
114 rpt_add(line)
113 rpt_add('\n*** Last line of input (may not be in above history):\n')
115 rpt_add('\n*** Last line of input (may not be in above history):\n')
114 rpt_add(self.app.shell._last_input_line+'\n')
116 rpt_add(self.app.shell._last_input_line+'\n')
115 except:
117 except:
116 pass
118 pass
117
119
118 return ''.join(report)
120 return ''.join(report)
119
121
120 #-----------------------------------------------------------------------------
122 #-----------------------------------------------------------------------------
121 # Aliases and Flags
123 # Aliases and Flags
122 #-----------------------------------------------------------------------------
124 #-----------------------------------------------------------------------------
123 flags = dict(base_flags)
125 flags = dict(base_flags)
124 flags.update(shell_flags)
126 flags.update(shell_flags)
125 frontend_flags = {}
127 frontend_flags = {}
126 addflag = lambda *args: frontend_flags.update(boolean_flag(*args))
128 addflag = lambda *args: frontend_flags.update(boolean_flag(*args))
127 addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax',
129 addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax',
128 'Turn on auto editing of files with syntax errors.',
130 'Turn on auto editing of files with syntax errors.',
129 'Turn off auto editing of files with syntax errors.'
131 'Turn off auto editing of files with syntax errors.'
130 )
132 )
131 addflag('banner', 'TerminalIPythonApp.display_banner',
133 addflag('banner', 'TerminalIPythonApp.display_banner',
132 "Display a banner upon starting IPython.",
134 "Display a banner upon starting IPython.",
133 "Don't display a banner upon starting IPython."
135 "Don't display a banner upon starting IPython."
134 )
136 )
135 addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit',
137 addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit',
136 """Set to confirm when you try to exit IPython with an EOF (Control-D
138 """Set to confirm when you try to exit IPython with an EOF (Control-D
137 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
139 in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
138 you can force a direct exit without any confirmation.""",
140 you can force a direct exit without any confirmation.""",
139 "Don't prompt the user when exiting."
141 "Don't prompt the user when exiting."
140 )
142 )
141 addflag('term-title', 'TerminalInteractiveShell.term_title',
143 addflag('term-title', 'TerminalInteractiveShell.term_title',
142 "Enable auto setting the terminal title.",
144 "Enable auto setting the terminal title.",
143 "Disable auto setting the terminal title."
145 "Disable auto setting the terminal title."
144 )
146 )
145 classic_config = Config()
147 classic_config = Config()
146 classic_config.InteractiveShell.cache_size = 0
148 classic_config.InteractiveShell.cache_size = 0
147 classic_config.PlainTextFormatter.pprint = False
149 classic_config.PlainTextFormatter.pprint = False
148 classic_config.PromptManager.in_template = '>>> '
150 classic_config.PromptManager.in_template = '>>> '
149 classic_config.PromptManager.in2_template = '... '
151 classic_config.PromptManager.in2_template = '... '
150 classic_config.PromptManager.out_template = ''
152 classic_config.PromptManager.out_template = ''
151 classic_config.InteractiveShell.separate_in = ''
153 classic_config.InteractiveShell.separate_in = ''
152 classic_config.InteractiveShell.separate_out = ''
154 classic_config.InteractiveShell.separate_out = ''
153 classic_config.InteractiveShell.separate_out2 = ''
155 classic_config.InteractiveShell.separate_out2 = ''
154 classic_config.InteractiveShell.colors = 'NoColor'
156 classic_config.InteractiveShell.colors = 'NoColor'
155 classic_config.InteractiveShell.xmode = 'Plain'
157 classic_config.InteractiveShell.xmode = 'Plain'
156
158
157 frontend_flags['classic']=(
159 frontend_flags['classic']=(
158 classic_config,
160 classic_config,
159 "Gives IPython a similar feel to the classic Python prompt."
161 "Gives IPython a similar feel to the classic Python prompt."
160 )
162 )
161 # # log doesn't make so much sense this way anymore
163 # # log doesn't make so much sense this way anymore
162 # paa('--log','-l',
164 # paa('--log','-l',
163 # action='store_true', dest='InteractiveShell.logstart',
165 # action='store_true', dest='InteractiveShell.logstart',
164 # help="Start logging to the default log file (./ipython_log.py).")
166 # help="Start logging to the default log file (./ipython_log.py).")
165 #
167 #
166 # # quick is harder to implement
168 # # quick is harder to implement
167 frontend_flags['quick']=(
169 frontend_flags['quick']=(
168 {'TerminalIPythonApp' : {'quick' : True}},
170 {'TerminalIPythonApp' : {'quick' : True}},
169 "Enable quick startup with no config files."
171 "Enable quick startup with no config files."
170 )
172 )
171
173
172 frontend_flags['i'] = (
174 frontend_flags['i'] = (
173 {'TerminalIPythonApp' : {'force_interact' : True}},
175 {'TerminalIPythonApp' : {'force_interact' : True}},
174 """If running code from the command line, become interactive afterwards.
176 """If running code from the command line, become interactive afterwards.
175 Note: can also be given simply as '-i.'"""
177 Note: can also be given simply as '-i.'"""
176 )
178 )
177 flags.update(frontend_flags)
179 flags.update(frontend_flags)
178
180
179 aliases = dict(base_aliases)
181 aliases = dict(base_aliases)
180 aliases.update(shell_aliases)
182 aliases.update(shell_aliases)
181
183
182 #-----------------------------------------------------------------------------
184 #-----------------------------------------------------------------------------
183 # Main classes and functions
185 # Main classes and functions
184 #-----------------------------------------------------------------------------
186 #-----------------------------------------------------------------------------
185
187
186
188
187 class LocateIPythonApp(BaseIPythonApplication):
189 class LocateIPythonApp(BaseIPythonApplication):
188 description = """print the path to the IPython dir"""
190 description = """print the path to the IPython dir"""
189 subcommands = Dict(dict(
191 subcommands = Dict(dict(
190 profile=('IPython.core.profileapp.ProfileLocate',
192 profile=('IPython.core.profileapp.ProfileLocate',
191 "print the path to an IPython profile directory",
193 "print the path to an IPython profile directory",
192 ),
194 ),
193 ))
195 ))
194 def start(self):
196 def start(self):
195 if self.subapp is not None:
197 if self.subapp is not None:
196 return self.subapp.start()
198 return self.subapp.start()
197 else:
199 else:
198 print self.ipython_dir
200 print self.ipython_dir
199
201
200
202
201 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
203 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
202 name = u'ipython'
204 name = u'ipython'
203 description = usage.cl_usage
205 description = usage.cl_usage
204 default_config_file_name = default_config_file_name
206 default_config_file_name = default_config_file_name
205 crash_handler_class = IPAppCrashHandler
207 crash_handler_class = IPAppCrashHandler
206 examples = _examples
208 examples = _examples
207
209
208 flags = Dict(flags)
210 flags = Dict(flags)
209 aliases = Dict(aliases)
211 aliases = Dict(aliases)
210 classes = List()
212 classes = List()
211 def _classes_default(self):
213 def _classes_default(self):
212 """This has to be in a method, for TerminalIPythonApp to be available."""
214 """This has to be in a method, for TerminalIPythonApp to be available."""
213 return [
215 return [
214 InteractiveShellApp, # ShellApp comes before TerminalApp, because
216 InteractiveShellApp, # ShellApp comes before TerminalApp, because
215 self.__class__, # it will also affect subclasses (e.g. QtConsole)
217 self.__class__, # it will also affect subclasses (e.g. QtConsole)
216 TerminalInteractiveShell,
218 TerminalInteractiveShell,
217 PromptManager,
219 PromptManager,
218 HistoryManager,
220 HistoryManager,
219 ProfileDir,
221 ProfileDir,
220 PlainTextFormatter,
222 PlainTextFormatter,
221 IPCompleter,
223 IPCompleter,
222 ScriptMagics,
224 ScriptMagics,
223 ]
225 ]
224
226
225 subcommands = Dict(dict(
227 subcommands = Dict(dict(
226 qtconsole=('IPython.qt.console.qtconsoleapp.IPythonQtConsoleApp',
228 qtconsole=('IPython.qt.console.qtconsoleapp.IPythonQtConsoleApp',
227 """Launch the IPython Qt Console."""
229 """Launch the IPython Qt Console."""
228 ),
230 ),
229 notebook=('IPython.html.notebookapp.NotebookApp',
231 notebook=('IPython.html.notebookapp.NotebookApp',
230 """Launch the IPython HTML Notebook Server."""
232 """Launch the IPython HTML Notebook Server."""
231 ),
233 ),
232 profile = ("IPython.core.profileapp.ProfileApp",
234 profile = ("IPython.core.profileapp.ProfileApp",
233 "Create and manage IPython profiles."
235 "Create and manage IPython profiles."
234 ),
236 ),
235 kernel = ("IPython.kernel.zmq.kernelapp.IPKernelApp",
237 kernel = ("IPython.kernel.zmq.kernelapp.IPKernelApp",
236 "Start a kernel without an attached frontend."
238 "Start a kernel without an attached frontend."
237 ),
239 ),
238 console=('IPython.terminal.console.app.ZMQTerminalIPythonApp',
240 console=('IPython.terminal.console.app.ZMQTerminalIPythonApp',
239 """Launch the IPython terminal-based Console."""
241 """Launch the IPython terminal-based Console."""
240 ),
242 ),
241 locate=('IPython.terminal.ipapp.LocateIPythonApp',
243 locate=('IPython.terminal.ipapp.LocateIPythonApp',
242 LocateIPythonApp.description
244 LocateIPythonApp.description
243 ),
245 ),
244 history=('IPython.core.historyapp.HistoryApp',
246 history=('IPython.core.historyapp.HistoryApp',
245 "Manage the IPython history database."
247 "Manage the IPython history database."
246 ),
248 ),
249 nbconvert=('IPython.nbconvert.nbconvertapp.NbConvertApp',
250 "Convert notebooks to/from other formats."
251 ),
247 ))
252 ))
248
253
249 # *do* autocreate requested profile, but don't create the config file.
254 # *do* autocreate requested profile, but don't create the config file.
250 auto_create=Bool(True)
255 auto_create=Bool(True)
251 # configurables
256 # configurables
252 ignore_old_config=Bool(False, config=True,
257 ignore_old_config=Bool(False, config=True,
253 help="Suppress warning messages about legacy config files"
258 help="Suppress warning messages about legacy config files"
254 )
259 )
255 quick = Bool(False, config=True,
260 quick = Bool(False, config=True,
256 help="""Start IPython quickly by skipping the loading of config files."""
261 help="""Start IPython quickly by skipping the loading of config files."""
257 )
262 )
258 def _quick_changed(self, name, old, new):
263 def _quick_changed(self, name, old, new):
259 if new:
264 if new:
260 self.load_config_file = lambda *a, **kw: None
265 self.load_config_file = lambda *a, **kw: None
261 self.ignore_old_config=True
266 self.ignore_old_config=True
262
267
263 display_banner = Bool(True, config=True,
268 display_banner = Bool(True, config=True,
264 help="Whether to display a banner upon starting IPython."
269 help="Whether to display a banner upon starting IPython."
265 )
270 )
266
271
267 # if there is code of files to run from the cmd line, don't interact
272 # if there is code of files to run from the cmd line, don't interact
268 # unless the --i flag (App.force_interact) is true.
273 # unless the --i flag (App.force_interact) is true.
269 force_interact = Bool(False, config=True,
274 force_interact = Bool(False, config=True,
270 help="""If a command or file is given via the command-line,
275 help="""If a command or file is given via the command-line,
271 e.g. 'ipython foo.py"""
276 e.g. 'ipython foo.py"""
272 )
277 )
273 def _force_interact_changed(self, name, old, new):
278 def _force_interact_changed(self, name, old, new):
274 if new:
279 if new:
275 self.interact = True
280 self.interact = True
276
281
277 def _file_to_run_changed(self, name, old, new):
282 def _file_to_run_changed(self, name, old, new):
278 if new:
283 if new:
279 self.something_to_run = True
284 self.something_to_run = True
280 if new and not self.force_interact:
285 if new and not self.force_interact:
281 self.interact = False
286 self.interact = False
282 _code_to_run_changed = _file_to_run_changed
287 _code_to_run_changed = _file_to_run_changed
283 _module_to_run_changed = _file_to_run_changed
288 _module_to_run_changed = _file_to_run_changed
284
289
285 # internal, not-configurable
290 # internal, not-configurable
286 interact=Bool(True)
291 interact=Bool(True)
287 something_to_run=Bool(False)
292 something_to_run=Bool(False)
288
293
289 def parse_command_line(self, argv=None):
294 def parse_command_line(self, argv=None):
290 """override to allow old '-pylab' flag with deprecation warning"""
295 """override to allow old '-pylab' flag with deprecation warning"""
291
296
292 argv = sys.argv[1:] if argv is None else argv
297 argv = sys.argv[1:] if argv is None else argv
293
298
294 if '-pylab' in argv:
299 if '-pylab' in argv:
295 # deprecated `-pylab` given,
300 # deprecated `-pylab` given,
296 # warn and transform into current syntax
301 # warn and transform into current syntax
297 argv = argv[:] # copy, don't clobber
302 argv = argv[:] # copy, don't clobber
298 idx = argv.index('-pylab')
303 idx = argv.index('-pylab')
299 warn.warn("`-pylab` flag has been deprecated.\n"
304 warn.warn("`-pylab` flag has been deprecated.\n"
300 " Use `--pylab` instead, or `--pylab=foo` to specify a backend.")
305 " Use `--pylab` instead, or `--pylab=foo` to specify a backend.")
301 sub = '--pylab'
306 sub = '--pylab'
302 if len(argv) > idx+1:
307 if len(argv) > idx+1:
303 # check for gui arg, as in '-pylab qt'
308 # check for gui arg, as in '-pylab qt'
304 gui = argv[idx+1]
309 gui = argv[idx+1]
305 if gui in ('wx', 'qt', 'qt4', 'gtk', 'auto'):
310 if gui in ('wx', 'qt', 'qt4', 'gtk', 'auto'):
306 sub = '--pylab='+gui
311 sub = '--pylab='+gui
307 argv.pop(idx+1)
312 argv.pop(idx+1)
308 argv[idx] = sub
313 argv[idx] = sub
309
314
310 return super(TerminalIPythonApp, self).parse_command_line(argv)
315 return super(TerminalIPythonApp, self).parse_command_line(argv)
311
316
312 @catch_config_error
317 @catch_config_error
313 def initialize(self, argv=None):
318 def initialize(self, argv=None):
314 """Do actions after construct, but before starting the app."""
319 """Do actions after construct, but before starting the app."""
315 super(TerminalIPythonApp, self).initialize(argv)
320 super(TerminalIPythonApp, self).initialize(argv)
316 if self.subapp is not None:
321 if self.subapp is not None:
317 # don't bother initializing further, starting subapp
322 # don't bother initializing further, starting subapp
318 return
323 return
319 if not self.ignore_old_config:
324 if not self.ignore_old_config:
320 check_for_old_config(self.ipython_dir)
325 check_for_old_config(self.ipython_dir)
321 # print self.extra_args
326 # print self.extra_args
322 if self.extra_args and not self.something_to_run:
327 if self.extra_args and not self.something_to_run:
323 self.file_to_run = self.extra_args[0]
328 self.file_to_run = self.extra_args[0]
324 self.init_path()
329 self.init_path()
325 # create the shell
330 # create the shell
326 self.init_shell()
331 self.init_shell()
327 # and draw the banner
332 # and draw the banner
328 self.init_banner()
333 self.init_banner()
329 # Now a variety of things that happen after the banner is printed.
334 # Now a variety of things that happen after the banner is printed.
330 self.init_gui_pylab()
335 self.init_gui_pylab()
331 self.init_extensions()
336 self.init_extensions()
332 self.init_code()
337 self.init_code()
333
338
334 def init_shell(self):
339 def init_shell(self):
335 """initialize the InteractiveShell instance"""
340 """initialize the InteractiveShell instance"""
336 # Create an InteractiveShell instance.
341 # Create an InteractiveShell instance.
337 # shell.display_banner should always be False for the terminal
342 # shell.display_banner should always be False for the terminal
338 # based app, because we call shell.show_banner() by hand below
343 # based app, because we call shell.show_banner() by hand below
339 # so the banner shows *before* all extension loading stuff.
344 # so the banner shows *before* all extension loading stuff.
340 self.shell = TerminalInteractiveShell.instance(config=self.config,
345 self.shell = TerminalInteractiveShell.instance(config=self.config,
341 display_banner=False, profile_dir=self.profile_dir,
346 display_banner=False, profile_dir=self.profile_dir,
342 ipython_dir=self.ipython_dir)
347 ipython_dir=self.ipython_dir)
343 self.shell.configurables.append(self)
348 self.shell.configurables.append(self)
344
349
345 def init_banner(self):
350 def init_banner(self):
346 """optionally display the banner"""
351 """optionally display the banner"""
347 if self.display_banner and self.interact:
352 if self.display_banner and self.interact:
348 self.shell.show_banner()
353 self.shell.show_banner()
349 # Make sure there is a space below the banner.
354 # Make sure there is a space below the banner.
350 if self.log_level <= logging.INFO: print
355 if self.log_level <= logging.INFO: print
351
356
352 def _pylab_changed(self, name, old, new):
357 def _pylab_changed(self, name, old, new):
353 """Replace --pylab='inline' with --pylab='auto'"""
358 """Replace --pylab='inline' with --pylab='auto'"""
354 if new == 'inline':
359 if new == 'inline':
355 warn.warn("'inline' not available as pylab backend, "
360 warn.warn("'inline' not available as pylab backend, "
356 "using 'auto' instead.")
361 "using 'auto' instead.")
357 self.pylab = 'auto'
362 self.pylab = 'auto'
358
363
359 def start(self):
364 def start(self):
360 if self.subapp is not None:
365 if self.subapp is not None:
361 return self.subapp.start()
366 return self.subapp.start()
362 # perform any prexec steps:
367 # perform any prexec steps:
363 if self.interact:
368 if self.interact:
364 self.log.debug("Starting IPython's mainloop...")
369 self.log.debug("Starting IPython's mainloop...")
365 self.shell.mainloop()
370 self.shell.mainloop()
366 else:
371 else:
367 self.log.debug("IPython not interactive...")
372 self.log.debug("IPython not interactive...")
368
373
369
374
370 def load_default_config(ipython_dir=None):
375 def load_default_config(ipython_dir=None):
371 """Load the default config file from the default ipython_dir.
376 """Load the default config file from the default ipython_dir.
372
377
373 This is useful for embedded shells.
378 This is useful for embedded shells.
374 """
379 """
375 if ipython_dir is None:
380 if ipython_dir is None:
376 ipython_dir = get_ipython_dir()
381 ipython_dir = get_ipython_dir()
377 profile_dir = os.path.join(ipython_dir, 'profile_default')
382 profile_dir = os.path.join(ipython_dir, 'profile_default')
378 cl = PyFileConfigLoader(default_config_file_name, profile_dir)
383 cl = PyFileConfigLoader(default_config_file_name, profile_dir)
379 try:
384 try:
380 config = cl.load_config()
385 config = cl.load_config()
381 except ConfigFileNotFound:
386 except ConfigFileNotFound:
382 # no config found
387 # no config found
383 config = Config()
388 config = Config()
384 return config
389 return config
385
390
386
391
387 def launch_new_instance():
392 def launch_new_instance():
388 """Create and run a full blown IPython instance"""
393 """Create and run a full blown IPython instance"""
389 app = TerminalIPythonApp.instance()
394 app = TerminalIPythonApp.instance()
390 app.initialize()
395 app.initialize()
391 app.start()
396 app.start()
392
397
393
398
394 if __name__ == '__main__':
399 if __name__ == '__main__':
395 launch_new_instance()
400 launch_new_instance()
General Comments 0
You need to be logged in to leave comments. Login now