ipapp.py
540 lines
| 20.0 KiB
| text/x-python
|
PythonLexer
Brian Granger
|
r2202 | #!/usr/bin/env python | ||
# encoding: utf-8 | ||||
""" | ||||
MinRK
|
r3963 | The :class:`~IPython.core.newapplication.Application` object for the command | ||
Brian Granger
|
r2301 | line :command:`ipython` program. | ||
Brian Granger
|
r2202 | |||
Fernando Perez
|
r2427 | Authors | ||
------- | ||||
Brian Granger
|
r2202 | |||
* Brian Granger | ||||
* Fernando Perez | ||||
MinRK
|
r3963 | * Min Ragan-Kelley | ||
Brian Granger
|
r2202 | """ | ||
#----------------------------------------------------------------------------- | ||||
Fernando Perez
|
r2427 | # Copyright (C) 2008-2010 The IPython Development Team | ||
Brian Granger
|
r2202 | # | ||
# Distributed under the terms of the BSD License. The full license is in | ||||
# the file COPYING, distributed as part of this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
Brian Granger
|
r2506 | |||
Fernando Perez
|
r2427 | from __future__ import absolute_import | ||
Brian Granger
|
r2202 | |||
Brian Granger
|
r2252 | import logging | ||
Brian Granger
|
r2203 | import os | ||
import sys | ||||
MinRK
|
r3963 | from IPython.config.loader import ( | ||
Config, PyFileConfigLoader | ||||
) | ||||
from IPython.config.application import boolean_flag | ||||
Brian Granger
|
r2506 | from IPython.core import release | ||
MinRK
|
r3963 | from IPython.core import usage | ||
Brian Granger
|
r2506 | from IPython.core.crashhandler import CrashHandler | ||
MinRK
|
r3963 | from IPython.core.formatters import PlainTextFormatter | ||
from IPython.core.newapplication import ( | ||||
ProfileDir, BaseIPythonApplication, base_flags, base_aliases | ||||
Brian Granger
|
r2245 | ) | ||
MinRK
|
r3963 | from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell | ||
Brian Granger
|
r2264 | from IPython.lib import inputhook | ||
MinRK
|
r3836 | from IPython.utils.path import filefind, get_ipython_dir, check_for_old_config | ||
MinRK
|
r3963 | from IPython.utils.traitlets import ( | ||
Bool, Unicode, Dict, Instance, List,CaselessStrEnum | ||||
) | ||||
Brian Granger
|
r2203 | |||
#----------------------------------------------------------------------------- | ||||
Fernando Perez
|
r2427 | # Globals, utilities and helpers | ||
Brian Granger
|
r2203 | #----------------------------------------------------------------------------- | ||
Brian Granger
|
r2501 | #: The default config file name for this application. | ||
Fernando Perez
|
r2427 | default_config_file_name = u'ipython_config.py' | ||
Brian Granger
|
r2203 | |||
Brian Granger
|
r2501 | |||
Brian Granger
|
r2203 | |||
Fernando Perez
|
r2427 | #----------------------------------------------------------------------------- | ||
Brian Granger
|
r2506 | # Crash handler for this application | ||
#----------------------------------------------------------------------------- | ||||
_message_template = """\ | ||||
Oops, $self.app_name crashed. We do our best to make it stable, but... | ||||
A crash report was automatically generated with the following information: | ||||
- A verbatim copy of the crash traceback. | ||||
- A copy of your input history during this session. | ||||
- Data on your current $self.app_name configuration. | ||||
It was left in the file named: | ||||
\t'$self.crash_report_fname' | ||||
If you can email this file to the developers, the information in it will help | ||||
them in understanding and correcting the problem. | ||||
You can mail it to: $self.contact_name at $self.contact_email | ||||
with the subject '$self.app_name Crash Report'. | ||||
If you want to do it now, the following command will work (under Unix): | ||||
mail -s '$self.app_name Crash Report' $self.contact_email < $self.crash_report_fname | ||||
To ensure accurate tracking of this issue, please file a report about it at: | ||||
$self.bug_tracker | ||||
""" | ||||
class IPAppCrashHandler(CrashHandler): | ||||
"""sys.excepthook for IPython itself, leaves a detailed report on disk.""" | ||||
message_template = _message_template | ||||
def __init__(self, app): | ||||
contact_name = release.authors['Fernando'][0] | ||||
contact_email = release.authors['Fernando'][1] | ||||
Fernando Perez
|
r3201 | bug_tracker = 'http://github.com/ipython/ipython/issues' | ||
Brian Granger
|
r2506 | super(IPAppCrashHandler,self).__init__( | ||
app, contact_name, contact_email, bug_tracker | ||||
) | ||||
def make_report(self,traceback): | ||||
"""Return a string containing a crash report.""" | ||||
sec_sep = self.section_sep | ||||
# Start with parent report | ||||
report = [super(IPAppCrashHandler, self).make_report(traceback)] | ||||
# Add interactive-specific info we may have | ||||
rpt_add = report.append | ||||
try: | ||||
rpt_add(sec_sep+"History of session input:") | ||||
for line in self.app.shell.user_ns['_ih']: | ||||
rpt_add(line) | ||||
rpt_add('\n*** Last line of input (may not be in above history):\n') | ||||
rpt_add(self.app.shell._last_input_line+'\n') | ||||
except: | ||||
pass | ||||
return ''.join(report) | ||||
MinRK
|
r3963 | #----------------------------------------------------------------------------- | ||
# Aliases and Flags | ||||
#----------------------------------------------------------------------------- | ||||
flags = dict(base_flags) | ||||
flags.update({ | ||||
}) | ||||
addflag = lambda *args: flags.update(boolean_flag(*args)) | ||||
addflag('autoindent', 'InteractiveShell.autoindent', | ||||
'Turn on autoindenting.', 'Turn off autoindenting.' | ||||
) | ||||
addflag('automagic', 'InteractiveShell.automagic', | ||||
"""Turn on the auto calling of magic commands. Type %%magic at the | ||||
IPython prompt for more information.""", | ||||
'Turn off the auto calling of magic commands.' | ||||
) | ||||
addflag('autoedit-syntax', 'TerminalInteractiveShell.autoedit_syntax', | ||||
'Turn on auto editing of files with syntax errors.', | ||||
'Turn off auto editing of files with syntax errors.' | ||||
) | ||||
addflag('banner', 'IPythonApp.display_banner', | ||||
"Display a banner upon starting IPython.", | ||||
"Don't display a banner upon starting IPython." | ||||
) | ||||
addflag('pdb', 'InteractiveShell.pdb', | ||||
"Enable auto calling the pdb debugger after every exception.", | ||||
"Disable auto calling the pdb debugger after every exception." | ||||
) | ||||
addflag('pprint', 'PlainTextFormatter.pprint', | ||||
"Enable auto pretty printing of results.", | ||||
"Disable auto auto pretty printing of results." | ||||
) | ||||
addflag('color-info', 'InteractiveShell.color_info', | ||||
"""IPython can display information about objects via a set of func- | ||||
tions, and optionally can use colors for this, syntax highlighting | ||||
source code and various other elements. However, because this | ||||
information is passed through a pager (like 'less') and many pagers get | ||||
confused with color codes, this option is off by default. You can test | ||||
it and turn it on permanently in your ipython_config.py file if it | ||||
works for you. Test it and turn it on permanently if it works with | ||||
your system. The magic function %%color_info allows you to toggle this | ||||
inter- actively for testing.""", | ||||
"Disable using colors for info related things." | ||||
) | ||||
addflag('confirm-exit', 'TerminalInteractiveShell.confirm_exit', | ||||
"""Set to confirm when you try to exit IPython with an EOF (Control-D | ||||
MinRK
|
r3967 | in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit', | ||
you can force a direct exit without any confirmation.""", | ||||
MinRK
|
r3963 | "Don't prompt the user when exiting." | ||
) | ||||
addflag('deep-reload', 'InteractiveShell.deep_reload', | ||||
"""Enable deep (recursive) reloading by default. IPython can use the | ||||
deep_reload module which reloads changes in modules recursively (it | ||||
replaces the reload() function, so you don't need to change anything to | ||||
use it). deep_reload() forces a full reload of modules whose code may | ||||
have changed, which the default reload() function does not. When | ||||
deep_reload is off, IPython will use the normal reload(), but | ||||
MinRK
|
r3967 | deep_reload will still be available as dreload(). This feature is off | ||
MinRK
|
r3963 | by default [which means that you have both normal reload() and | ||
dreload()].""", | ||||
"Disable deep (recursive) reloading by default." | ||||
) | ||||
addflag('readline', 'InteractiveShell.readline_use', | ||||
"Enable readline for command line usage.", | ||||
"Disable readline for command line usage." | ||||
) | ||||
addflag('term-title', 'TerminalInteractiveShell.term_title', | ||||
"Enable auto setting the terminal title.", | ||||
"Disable auto setting the terminal title." | ||||
) | ||||
classic_config = Config() | ||||
classic_config.InteractiveShell.cache_size = 0 | ||||
classic_config.PlainTextFormatter.pprint = False | ||||
classic_config.InteractiveShell.prompt_in1 = '>>> ' | ||||
classic_config.InteractiveShell.prompt_in2 = '... ' | ||||
classic_config.InteractiveShell.prompt_out = '' | ||||
classic_config.InteractiveShell.separate_in = '' | ||||
classic_config.InteractiveShell.separate_out = '' | ||||
classic_config.InteractiveShell.separate_out2 = '' | ||||
classic_config.InteractiveShell.colors = 'NoColor' | ||||
classic_config.InteractiveShell.xmode = 'Plain' | ||||
flags['classic']=( | ||||
classic_config, | ||||
"Gives IPython a similar feel to the classic Python prompt." | ||||
) | ||||
# # log doesn't make so much sense this way anymore | ||||
# paa('--log','-l', | ||||
# action='store_true', dest='InteractiveShell.logstart', | ||||
# help="Start logging to the default log file (./ipython_log.py).") | ||||
# | ||||
# # quick is harder to implement | ||||
flags['quick']=( | ||||
{'IPythonApp' : {'quick' : True}}, | ||||
"Enable quick startup with no config files." | ||||
) | ||||
nosep_config = Config() | ||||
nosep_config.InteractiveShell.separate_in = '' | ||||
nosep_config.InteractiveShell.separate_out = '' | ||||
nosep_config.InteractiveShell.separate_out2 = '' | ||||
flags['nosep']=(nosep_config, "Eliminate all spacing between prompts.") | ||||
flags['i'] = ( | ||||
{'IPythonApp' : {'force_interact' : True}}, | ||||
"If running code from the command line, become interactive afterwards." | ||||
) | ||||
flags['pylab'] = ( | ||||
{'IPythonApp' : {'pylab' : 'auto'}}, | ||||
"""Pre-load matplotlib and numpy for interactive use with | ||||
the default matplotlib backend.""" | ||||
) | ||||
aliases = dict(base_aliases) | ||||
# it's possible we don't want short aliases for *all* of these: | ||||
aliases.update(dict( | ||||
autocall='InteractiveShell.autocall', | ||||
cache_size='InteractiveShell.cache_size', | ||||
colors='InteractiveShell.colors', | ||||
editor='TerminalInteractiveShell.editor', | ||||
logfile='InteractiveShell.logfile', | ||||
log_append='InteractiveShell.logappend', | ||||
pi1='InteractiveShell.prompt_in1', | ||||
pi2='InteractiveShell.prompt_in1', | ||||
po='InteractiveShell.prompt_out', | ||||
sl='TerminalInteractiveShell.screen_length', | ||||
si='InteractiveShell.separate_in', | ||||
so='InteractiveShell.separate_out', | ||||
so2='InteractiveShell.separate_out2', | ||||
xmode='InteractiveShell.xmode', | ||||
c='IPythonApp.code_to_run', | ||||
ext='IPythonApp.extra_extension', | ||||
gui='IPythonApp.gui', | ||||
pylab='IPythonApp.pylab', | ||||
)) | ||||
Brian Granger
|
r2506 | |||
#----------------------------------------------------------------------------- | ||||
Fernando Perez
|
r2427 | # Main classes and functions | ||
#----------------------------------------------------------------------------- | ||||
Brian Granger
|
r2245 | |||
MinRK
|
r3963 | class IPythonApp(BaseIPythonApplication): | ||
Brian Granger
|
r2328 | name = u'ipython' | ||
MinRK
|
r3963 | description = usage.cl_usage | ||
# command_line_loader = IPAppConfigLoader | ||||
Brian Granger
|
r2511 | default_config_file_name = default_config_file_name | ||
Brian Granger
|
r2506 | crash_handler_class = IPAppCrashHandler | ||
MinRK
|
r3963 | flags = Dict(flags) | ||
aliases = Dict(aliases) | ||||
classes = [TerminalInteractiveShell, ProfileDir, PlainTextFormatter] | ||||
# *do* autocreate requested profile | ||||
auto_create=Bool(True) | ||||
copy_config_files=Bool(True) | ||||
# configurables | ||||
ignore_old_config=Bool(False, config=True, | ||||
help="Suppress warning messages about legacy config files" | ||||
) | ||||
quick = Bool(False, config=True, | ||||
help="""Start IPython quickly by skipping the loading of config files.""" | ||||
) | ||||
def _quick_changed(self, name, old, new): | ||||
if new: | ||||
self.load_config_file = lambda *a, **kw: None | ||||
self.ignore_old_config=True | ||||
gui = CaselessStrEnum(('qt','wx','gtk'), config=True, | ||||
help="Enable GUI event loop integration ('qt', 'wx', 'gtk')." | ||||
) | ||||
pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'auto'], | ||||
config=True, | ||||
help="""Pre-load matplotlib and numpy for interactive use, | ||||
selecting a particular matplotlib backend and loop integration. | ||||
""" | ||||
) | ||||
display_banner = Bool(True, config=True, | ||||
help="Whether to display a banner upon starting IPython." | ||||
) | ||||
extensions = List(Unicode, config=True, | ||||
help="A list of dotted module names of IPython extensions to load." | ||||
) | ||||
extra_extension = Unicode('', config=True, | ||||
help="dotted module name of an IPython extension to load." | ||||
) | ||||
def _extra_extension_changed(self, name, old, new): | ||||
if new: | ||||
# add to self.extensions | ||||
self.extensions.append(new) | ||||
# if there is code of files to run from the cmd line, don't interact | ||||
# unless the --i flag (App.force_interact) is true. | ||||
force_interact = Bool(False, config=True, | ||||
help="""If a command or file is given via the command-line, | ||||
e.g. 'ipython foo.py""" | ||||
) | ||||
def _force_interact_changed(self, name, old, new): | ||||
if new: | ||||
self.interact = True | ||||
exec_files = List(Unicode, config=True, | ||||
help="""List of files to run at IPython startup.""" | ||||
) | ||||
file_to_run = Unicode('', config=True, | ||||
help="""A file to be run""") | ||||
def _file_to_run_changed(self, name, old, new): | ||||
if new and not self.force_interact: | ||||
self.interact = False | ||||
exec_lines = List(Unicode, config=True, | ||||
help="""lines of code to run at IPython startup.""" | ||||
) | ||||
code_to_run = Unicode('', config=True, | ||||
help="Execute the given command string." | ||||
) | ||||
_code_to_run_changed = _file_to_run_changed | ||||
# internal, not-configurable | ||||
interact=Bool(True) | ||||
def initialize(self, argv=None): | ||||
"""Do actions after construct, but before starting the app.""" | ||||
super(IPythonApp, self).initialize(argv) | ||||
if not self.ignore_old_config: | ||||
check_for_old_config(self.ipython_dir) | ||||
Brian Granger
|
r2253 | |||
MinRK
|
r3963 | # print self.extra_args | ||
if self.extra_args: | ||||
self.file_to_run = self.extra_args[0] | ||||
# create the shell | ||||
self.init_shell() | ||||
# and draw the banner | ||||
self.init_banner() | ||||
# Now a variety of things that happen after the banner is printed. | ||||
self.init_gui_pylab() | ||||
self.init_extensions() | ||||
self.init_code() | ||||
def init_shell(self): | ||||
"""initialize the InteractiveShell instance""" | ||||
Brian Granger
|
r2203 | # I am a little hesitant to put these into InteractiveShell itself. | ||
# But that might be the place for them | ||||
sys.path.insert(0, '') | ||||
Brian Granger
|
r2252 | |||
Brian Granger
|
r2731 | # Create an InteractiveShell instance. | ||
Brian Granger
|
r2252 | # shell.display_banner should always be False for the terminal | ||
# based app, because we call shell.show_banner() by hand below | ||||
# so the banner shows *before* all extension loading stuff. | ||||
MinRK
|
r3963 | self.shell = TerminalInteractiveShell.instance(config=self.config, | ||
display_banner=False, profile_dir=self.profile_dir, | ||||
ipython_dir=self.ipython_dir) | ||||
Brian Granger
|
r2252 | |||
MinRK
|
r3963 | def init_banner(self): | ||
"""optionally display the banner""" | ||||
if self.display_banner and self.interact: | ||||
self.shell.show_banner() | ||||
Brian Granger
|
r2252 | # Make sure there is a space below the banner. | ||
if self.log_level <= logging.INFO: print | ||||
Fernando Perez
|
r2363 | |||
MinRK
|
r3963 | def init_gui_pylab(self): | ||
Fernando Perez
|
r2363 | """Enable GUI event loop integration, taking pylab into account.""" | ||
MinRK
|
r3963 | gui = self.gui | ||
Fernando Perez
|
r2363 | |||
MinRK
|
r3963 | # Using `pylab` will also require gui activation, though which toolkit | ||
Fernando Perez
|
r2388 | # to use may be chosen automatically based on mpl configuration. | ||
MinRK
|
r3963 | if self.pylab: | ||
Fernando Perez
|
r2363 | activate = self.shell.enable_pylab | ||
MinRK
|
r3963 | if self.pylab == 'auto': | ||
Fernando Perez
|
r2388 | gui = None | ||
else: | ||||
MinRK
|
r3963 | gui = self.pylab | ||
Fernando Perez
|
r2363 | else: | ||
# Enable only GUI integration, no pylab | ||||
activate = inputhook.enable_gui | ||||
MinRK
|
r3963 | if gui or self.pylab: | ||
Fernando Perez
|
r2363 | try: | ||
Fernando Perez
|
r2388 | self.log.info("Enabling GUI event loop integration, " | ||
MinRK
|
r3963 | "toolkit=%s, pylab=%s" % (gui, self.pylab) ) | ||
Fernando Perez
|
r2363 | activate(gui) | ||
except: | ||||
self.log.warn("Error in enabling GUI event loop integration:") | ||||
self.shell.showtraceback() | ||||
Brian Granger
|
r2252 | |||
MinRK
|
r3963 | def init_extensions(self): | ||
"""Load all IPython extensions in IPythonApp.extensions. | ||||
Brian Granger
|
r2252 | |||
Brian Granger
|
r2731 | This uses the :meth:`ExtensionManager.load_extensions` to load all | ||
MinRK
|
r3963 | the extensions listed in ``self.extensions``. | ||
Brian Granger
|
r2252 | """ | ||
MinRK
|
r3963 | if not self.extensions: | ||
return | ||||
Brian Granger
|
r2252 | try: | ||
MinRK
|
r3963 | self.log.debug("Loading IPython extensions...") | ||
extensions = self.extensions | ||||
for ext in extensions: | ||||
try: | ||||
self.log.info("Loading IPython extension: %s" % ext) | ||||
self.shell.extension_manager.load_extension(ext) | ||||
except: | ||||
self.log.warn("Error in loading extension: %s" % ext) | ||||
self.shell.showtraceback() | ||||
Brian Granger
|
r2252 | except: | ||
self.log.warn("Unknown error in loading extensions:") | ||||
self.shell.showtraceback() | ||||
MinRK
|
r3963 | def init_code(self): | ||
"""run the pre-flight code, specified via exec_lines""" | ||||
self._run_exec_lines() | ||||
self._run_exec_files() | ||||
self._run_cmd_line_code() | ||||
Brian Granger
|
r2252 | def _run_exec_lines(self): | ||
MinRK
|
r3963 | """Run lines of code in IPythonApp.exec_lines in the user's namespace.""" | ||
if not self.exec_lines: | ||||
return | ||||
Brian Granger
|
r2252 | try: | ||
MinRK
|
r3963 | self.log.debug("Running code from IPythonApp.exec_lines...") | ||
for line in self.exec_lines: | ||||
try: | ||||
self.log.info("Running code in user namespace: %s" % | ||||
line) | ||||
self.shell.run_cell(line, store_history=False) | ||||
except: | ||||
self.log.warn("Error in executing line in user " | ||||
"namespace: %s" % line) | ||||
self.shell.showtraceback() | ||||
Brian Granger
|
r2252 | except: | ||
MinRK
|
r3963 | self.log.warn("Unknown error in handling IPythonApp.exec_lines:") | ||
Brian Granger
|
r2252 | self.shell.showtraceback() | ||
Brian Granger
|
r2253 | def _exec_file(self, fname): | ||
Brian Granger
|
r2328 | full_filename = filefind(fname, [u'.', self.ipython_dir]) | ||
Brian Granger
|
r2253 | if os.path.isfile(full_filename): | ||
Brian Granger
|
r2328 | if full_filename.endswith(u'.py'): | ||
Fernando Perez
|
r2574 | self.log.info("Running file in user namespace: %s" % | ||
full_filename) | ||||
# Ensure that __file__ is always defined to match Python behavior | ||||
self.shell.user_ns['__file__'] = fname | ||||
try: | ||||
self.shell.safe_execfile(full_filename, self.shell.user_ns) | ||||
finally: | ||||
del self.shell.user_ns['__file__'] | ||||
Brian Granger
|
r2253 | elif full_filename.endswith('.ipy'): | ||
Fernando Perez
|
r2574 | self.log.info("Running file in user namespace: %s" % | ||
full_filename) | ||||
Brian Granger
|
r2253 | self.shell.safe_execfile_ipy(full_filename) | ||
else: | ||||
Fernando Perez
|
r2574 | self.log.warn("File does not have a .py or .ipy extension: <%s>" | ||
% full_filename) | ||||
MinRK
|
r3963 | |||
Brian Granger
|
r2252 | def _run_exec_files(self): | ||
MinRK
|
r3963 | """Run files from IPythonApp.exec_files""" | ||
if not self.exec_files: | ||||
return | ||||
self.log.debug("Running files in IPythonApp.exec_files...") | ||||
Brian Granger
|
r2252 | try: | ||
MinRK
|
r3963 | for fname in self.exec_files: | ||
self._exec_file(fname) | ||||
Brian Granger
|
r2252 | except: | ||
MinRK
|
r3963 | self.log.warn("Unknown error in handling IPythonApp.exec_files:") | ||
Brian Granger
|
r2252 | self.shell.showtraceback() | ||
Brian Granger
|
r2253 | def _run_cmd_line_code(self): | ||
MinRK
|
r3963 | """Run code or file specified at the command-line""" | ||
if self.code_to_run: | ||||
line = self.code_to_run | ||||
Brian Granger
|
r2253 | try: | ||
MinRK
|
r3963 | self.log.info("Running code given at command line (c=): %s" % | ||
Fernando Perez
|
r2574 | line) | ||
MinRK
|
r3746 | self.shell.run_cell(line, store_history=False) | ||
Brian Granger
|
r2253 | except: | ||
Fernando Perez
|
r2574 | self.log.warn("Error in executing line in user namespace: %s" % | ||
line) | ||||
Brian Granger
|
r2253 | self.shell.showtraceback() | ||
MinRK
|
r3963 | |||
Brian Granger
|
r2253 | # Like Python itself, ignore the second if the first of these is present | ||
MinRK
|
r3963 | elif self.file_to_run: | ||
fname = self.file_to_run | ||||
Brian Granger
|
r2253 | try: | ||
self._exec_file(fname) | ||||
except: | ||||
Fernando Perez
|
r2574 | self.log.warn("Error in executing file in user namespace: %s" % | ||
fname) | ||||
Brian Granger
|
r2253 | self.shell.showtraceback() | ||
MinRK
|
r3963 | |||
def start(self): | ||||
# perform any prexec steps: | ||||
if self.interact: | ||||
Brian Granger
|
r2253 | self.log.debug("Starting IPython's mainloop...") | ||
self.shell.mainloop() | ||||
Fernando Perez
|
r2391 | else: | ||
MinRK
|
r3963 | self.log.debug("IPython not interactive...") | ||
Brian Granger
|
r2202 | |||
Fernando Perez
|
r2363 | |||
Brian Granger
|
r2322 | def load_default_config(ipython_dir=None): | ||
"""Load the default config file from the default ipython_dir. | ||||
Brian Granger
|
r2245 | |||
This is useful for embedded shells. | ||||
""" | ||||
Brian Granger
|
r2322 | if ipython_dir is None: | ||
ipython_dir = get_ipython_dir() | ||||
MinRK
|
r3963 | profile_dir = os.path.join(ipython_dir, 'profile_default') | ||
cl = PyFileConfigLoader(default_config_file_name, profile_dir) | ||||
Brian Granger
|
r2245 | config = cl.load_config() | ||
return config | ||||
Brian Granger
|
r2269 | def launch_new_instance(): | ||
Brian Granger
|
r2296 | """Create and run a full blown IPython instance""" | ||
Brian Granger
|
r2202 | app = IPythonApp() | ||
MinRK
|
r3963 | app.initialize() | ||
# print app.config | ||||
# print app.profile_dir.location | ||||
Brian Granger
|
r2269 | app.start() | ||
Brian Granger
|
r2501 | |||
Brian Granger
|
r2507 | |||
if __name__ == '__main__': | ||||
launch_new_instance() | ||||