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