##// END OF EJS Templates
Testing '#:' attribute docstrings for sphinx....
Testing '#:' attribute docstrings for sphinx. This is supposed to work and give us class/instance docstrings, but it's not yet. I have a question on the sphinx list about it, let's leave it in the code until we figure out what we need to do to sphinx for it to work (it doesn't hurt otherwise).

File last commit:

r2363:f4d0cb7d
r2387:284a8dec
Show More
ipapp.py
555 lines | 21.9 KiB | text/x-python | PythonLexer
Brian Granger
Massive, crazy refactoring of everything....
r2202 #!/usr/bin/env python
# encoding: utf-8
"""
Brian Granger
ipcontroller/ipengine use the new clusterdir.py module.
r2301 The :class:`~IPython.core.application.Application` object for the command
line :command:`ipython` program.
Brian Granger
Massive, crazy refactoring of everything....
r2202
Authors:
* Brian Granger
* Fernando Perez
Notes
-----
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2009 The IPython Development Team
#
# 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
Work on startup related things....
r2252 import logging
Brian Granger
More work on getting rid of ipmaker.
r2203 import os
import sys
Brian Granger
Massive, crazy refactoring of everything....
r2202 from IPython.core import release
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 from IPython.core.application import Application, BaseAppArgParseConfigLoader
from IPython.core.error import UsageError
Brian Granger
Massive, crazy refactoring of everything....
r2202 from IPython.core.iplib import InteractiveShell
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 from IPython.core.pylabtools import pylab_activate
Brian Granger
Massive refactoring of of the core....
r2245 from IPython.config.loader import (
NoConfigDefault,
Config,
PyFileConfigLoader
)
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 from IPython.lib import inputhook
Brian Granger
Work on startup related things....
r2252 from IPython.utils.genutils import filefind, get_ipython_dir
Brian Granger
More work on getting rid of ipmaker.
r2203
#-----------------------------------------------------------------------------
# Utilities and helpers
#-----------------------------------------------------------------------------
Brian Granger
Massive, crazy refactoring of everything....
r2202 ipython_desc = """
A Python shell with automatic history (input and output), dynamic object
introspection, easier configuration, command completion, access to the system
shell and more.
"""
Brian Granger
More work on getting rid of ipmaker.
r2203 #-----------------------------------------------------------------------------
# Main classes and functions
#-----------------------------------------------------------------------------
cl_args = (
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--autocall',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=int, dest='InteractiveShell.autocall', default=NoConfigDefault,
help='Set the autocall value (0,1,2).',
metavar='InteractiveShell.autocall')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--autoindent',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.autoindent', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help='Turn on autoindenting.')
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-autoindent',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.autoindent', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help='Turn off autoindenting.')
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--automagic',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.automagic', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help='Turn on the auto calling of magic commands.')
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-automagic',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.automagic', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help='Turn off the auto calling of magic commands.')
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--autoedit-syntax',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help='Turn on auto editing of files with syntax errors.')
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-autoedit-syntax',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help='Turn off auto editing of files with syntax errors.')
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--banner',), dict(
Brian Granger
Work on startup related things....
r2252 action='store_true', dest='Global.display_banner', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help='Display a banner upon starting IPython.')
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-banner',), dict(
Brian Granger
Work on startup related things....
r2252 action='store_false', dest='Global.display_banner', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Don't display a banner upon starting IPython.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--cache-size',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=int, dest='InteractiveShell.cache_size', default=NoConfigDefault,
help="Set the size of the output cache.",
metavar='InteractiveShell.cache_size')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--classic',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='Global.classic', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Gives IPython a similar feel to the classic Python prompt.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--colors',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.colors', default=NoConfigDefault,
help="Set the color scheme (NoColor, Linux, and LightBG).",
metavar='InteractiveShell.colors')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--color-info',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.color_info', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Enable using colors for info related things.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-color-info',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.color_info', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Disable using colors for info related things.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--confirm-exit',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.confirm_exit', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Prompt the user when existing.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-confirm-exit',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.confirm_exit', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Don't prompt the user when existing.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--deep-reload',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.deep_reload', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Enable deep (recursive) reloading by default.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-deep-reload',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.deep_reload', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Disable deep (recursive) reloading by default.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--editor',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.editor', default=NoConfigDefault,
help="Set the editor used by IPython (default to $EDITOR/vi/notepad).",
metavar='InteractiveShell.editor')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--log','-l'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.logstart', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Start logging to the default file (./ipython_log.py).")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--logfile','-lf'), dict(
Brian Granger
Beginning to transition all paths, files, dirs over to unicode....
r2328 type=unicode, dest='InteractiveShell.logfile', default=NoConfigDefault,
Brian Granger
Minor changes to make sure logging is working well....
r2265 help="Start logging to logfile.",
Brian Granger
Massive refactoring of of the core....
r2245 metavar='InteractiveShell.logfile')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--log-append','-la'), dict(
Brian Granger
Beginning to transition all paths, files, dirs over to unicode....
r2328 type=unicode, dest='InteractiveShell.logappend', default=NoConfigDefault,
help="Start logging to the give file in append mode.",
Brian Granger
Minor changes to make sure logging is working well....
r2265 metavar='InteractiveShell.logfile')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--pdb',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.pdb', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Enable auto calling the pdb debugger after every exception.")
),
Brian Granger
Beginning to transition all paths, files, dirs over to unicode....
r2328 (('--no-pdb',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.pdb', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Disable auto calling the pdb debugger after every exception.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--pprint',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.pprint', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Enable auto pretty printing of results.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-pprint',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.pprint', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Disable auto auto pretty printing of results.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--prompt-in1','-pi1'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.prompt_in1', default=NoConfigDefault,
help="Set the main input prompt ('In [\#]: ')",
metavar='InteractiveShell.prompt_in1')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--prompt-in2','-pi2'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.prompt_in2', default=NoConfigDefault,
help="Set the secondary input prompt (' .\D.: ')",
metavar='InteractiveShell.prompt_in2')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--prompt-out','-po'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.prompt_out', default=NoConfigDefault,
help="Set the output prompt ('Out[\#]:')",
metavar='InteractiveShell.prompt_out')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--quick',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='Global.quick', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Enable quick startup with no config files.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--readline',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.readline_use', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Enable readline for command line usage.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-readline',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.readline_use', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Disable readline for command line usage.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--screen-length','-sl'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=int, dest='InteractiveShell.screen_length', default=NoConfigDefault,
help='Number of lines on screen, used to control printing of long strings.',
metavar='InteractiveShell.screen_length')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--separate-in','-si'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.separate_in', default=NoConfigDefault,
help="Separator before input prompts. Default '\n'.",
metavar='InteractiveShell.separate_in')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--separate-out','-so'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.separate_out', default=NoConfigDefault,
help="Separator before output prompts. Default 0 (nothing).",
metavar='InteractiveShell.separate_out')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--separate-out2','-so2'), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.separate_out2', default=NoConfigDefault,
help="Separator after output prompts. Default 0 (nonight).",
metavar='InteractiveShell.separate_out2')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('-no-sep',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='Global.nosep', default=NoConfigDefault,
Brian Granger
More work on getting rid of ipmaker.
r2203 help="Eliminate all spacing between prompts.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--term-title',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_true', dest='InteractiveShell.term_title', default=NoConfigDefault,
Brian Granger
More work on InteractiveShell and ipmaker. It works!
r2204 help="Enable auto setting the terminal title.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--no-term-title',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 action='store_false', dest='InteractiveShell.term_title', default=NoConfigDefault,
Brian Granger
More work on InteractiveShell and ipmaker. It works!
r2204 help="Disable auto setting the terminal title.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--xmode',), dict(
Brian Granger
Massive refactoring of of the core....
r2245 type=str, dest='InteractiveShell.xmode', default=NoConfigDefault,
help="Exception mode ('Plain','Context','Verbose')",
metavar='InteractiveShell.xmode')
Brian Granger
More work on getting rid of ipmaker.
r2203 ),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--ext',), dict(
Brian Granger
Work on startup related things....
r2252 type=str, dest='Global.extra_extension', default=NoConfigDefault,
help="The dotted module name of an IPython extension to load.",
metavar='Global.extra_extension')
),
Brian Granger
All code startup related things are working....
r2253 (('-c',), dict(
type=str, dest='Global.code_to_run', default=NoConfigDefault,
help="Execute the given command string.",
metavar='Global.code_to_run')
),
(('-i',), dict(
action='store_true', dest='Global.force_interact', default=NoConfigDefault,
help="If running code from the command line, become interactive afterwards.")
),
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 (('--wthread','-wthread'), dict(
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 action='store_true', dest='Global.wthread', default=NoConfigDefault,
help="Enable wxPython event loop integration.")
Brian Granger
More work on InteractiveShell and ipmaker. It works!
r2204 ),
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 (('--q4thread','--qthread','-q4thread','-qthread'), dict(
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 action='store_true', dest='Global.q4thread', default=NoConfigDefault,
help="Enable Qt4 event loop integration. Qt3 is no longer supported.")
),
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 (('--gthread','-gthread'), dict(
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 action='store_true', dest='Global.gthread', default=NoConfigDefault,
help="Enable GTK event loop integration.")
),
Brian Granger
Lots of work on command line options and env vars....
r2322 (('--pylab',), dict(
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 action='store_true', dest='Global.pylab', default=NoConfigDefault,
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 help="Pre-load matplotlib and numpy for interactive use.")
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 )
Brian Granger
More work on getting rid of ipmaker.
r2203 )
Brian Granger
Work on ipcontroller....
r2296 class IPythonAppCLConfigLoader(BaseAppArgParseConfigLoader):
Brian Granger
More work on getting rid of ipmaker.
r2203
arguments = cl_args
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357 def load_config(self):
"""Do actions just before loading the command line config."""
# Special hack: there are countless uses of 'ipython -pylab' (with one
# dash) in the wild, including in printed books. Since argparse does
# will interpret -pylab as '-p ylab', sending us in a search for a
# profile named 'ylab', instead we special-case here -pylab as the
# first or second option only (this is how old ipython used to work)
# and convert this use to --pylab. Ugly, but needed for this one
# very widely used case.
firstargs = sys.argv[:3]
try:
idx = firstargs.index('-pylab')
except ValueError:
pass
else:
sys.argv[idx] = '--pylab'
return super(IPythonAppCLConfigLoader, self).load_config()
Brian Granger
Massive, crazy refactoring of everything....
r2202
Brian Granger
Beginning to transition all paths, files, dirs over to unicode....
r2328 default_config_file_name = u'ipython_config.py'
Brian Granger
Massive refactoring of of the core....
r2245
Brian Granger
Work on ipcontroller....
r2296
Brian Granger
Massive, crazy refactoring of everything....
r2202 class IPythonApp(Application):
Brian Granger
Beginning to transition all paths, files, dirs over to unicode....
r2328 name = u'ipython'
Brian Granger
Work on ipcontroller....
r2296 description = 'IPython: an enhanced interactive Python shell.'
Brian Granger
Finished refactoring ipcontroller to be a proper application....
r2297 config_file_name = default_config_file_name
Brian Granger
Massive, crazy refactoring of everything....
r2202
Brian Granger
Work on startup related things....
r2252 def create_default_config(self):
super(IPythonApp, self).create_default_config()
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357 # Eliminate multiple lookups
Global = self.default_config.Global
# Set all default values
Global.display_banner = True
Brian Granger
All code startup related things are working....
r2253
# If the -c flag is given or a file is given to run at the cmd line
# like "ipython foo.py", normally we exit without starting the main
# loop. The force_interact config variable allows a user to override
# this and interact. It is also set by the -i cmd line flag, just
# like Python.
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357 Global.force_interact = False
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264
Brian Granger
All code startup related things are working....
r2253 # By default always interact by starting the IPython mainloop.
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357 Global.interact = True
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264
# No GUI integration by default
Fernando Perez
Improve pylab support, find profiles in IPython's own directory....
r2357 Global.wthread = False
Global.q4thread = False
Global.gthread = False
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 # Pylab off by default
Global.pylab = False
Brian Granger
Massive, crazy refactoring of everything....
r2202 def create_command_line_config(self):
"""Create and return a command line config loader."""
return IPythonAppCLConfigLoader(
Brian Granger
Work on ipcontroller....
r2296 description=self.description,
version=release.version
)
Brian Granger
Massive, crazy refactoring of everything....
r2202
Brian Granger
More work on getting rid of ipmaker.
r2203
def load_file_config(self):
Brian Granger
Massive refactoring of of the core....
r2245 if hasattr(self.command_line_config.Global, 'quick'):
if self.command_line_config.Global.quick:
self.file_config = Config()
Brian Granger
More work on getting rid of ipmaker.
r2203 return
super(IPythonApp, self).load_file_config()
def post_load_file_config(self):
Brian Granger
Work on startup related things....
r2252 if hasattr(self.command_line_config.Global, 'extra_extension'):
if not hasattr(self.file_config.Global, 'extensions'):
self.file_config.Global.extensions = []
self.file_config.Global.extensions.append(
self.command_line_config.Global.extra_extension)
del self.command_line_config.Global.extra_extension
Brian Granger
More work on getting rid of ipmaker.
r2203
def pre_construct(self):
config = self.master_config
Brian Granger
Massive refactoring of of the core....
r2245 if hasattr(config.Global, 'classic'):
if config.Global.classic:
config.InteractiveShell.cache_size = 0
config.InteractiveShell.pprint = 0
config.InteractiveShell.prompt_in1 = '>>> '
config.InteractiveShell.prompt_in2 = '... '
config.InteractiveShell.prompt_out = ''
config.InteractiveShell.separate_in = \
config.InteractiveShell.separate_out = \
config.InteractiveShell.separate_out2 = ''
config.InteractiveShell.colors = 'NoColor'
config.InteractiveShell.xmode = 'Plain'
Brian Granger
More work on getting rid of ipmaker.
r2203
Brian Granger
Massive refactoring of of the core....
r2245 if hasattr(config.Global, 'nosep'):
if config.Global.nosep:
config.InteractiveShell.separate_in = \
config.InteractiveShell.separate_out = \
Brian Granger
All code startup related things are working....
r2253 config.InteractiveShell.separate_out2 = ''
# if there is code of files to run from the cmd line, don't interact
# unless the -i flag (Global.force_interact) is true.
code_to_run = config.Global.get('code_to_run','')
file_to_run = False
if len(self.extra_args)>=1:
if self.extra_args[0]:
file_to_run = True
if file_to_run or code_to_run:
if not config.Global.force_interact:
config.Global.interact = False
Brian Granger
More work on getting rid of ipmaker.
r2203
Brian Granger
Massive, crazy refactoring of everything....
r2202 def construct(self):
Brian Granger
More work on getting rid of ipmaker.
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
Work on startup related things....
r2252
Brian Granger
More work on getting rid of ipmaker.
r2203 # Create an InteractiveShell instance
Brian Granger
Massive, crazy refactoring of everything....
r2202 self.shell = InteractiveShell(
parent=None,
config=self.master_config
)
Brian Granger
Work on startup related things....
r2252
def post_construct(self):
"""Do actions after construct, but before starting the app."""
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 config = self.master_config
Brian Granger
Work on startup related things....
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.
self.shell.display_banner = False
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264 if config.Global.display_banner and \
config.Global.interact:
Brian Granger
Work on startup related things....
r2252 self.shell.show_banner()
# Make sure there is a space below the banner.
if self.log_level <= logging.INFO: print
Brian Granger
Fixing minor bug with the logging level in ipapp.py.
r2270 # Now a variety of things that happen after the banner is printed.
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 self._enable_gui_pylab()
Brian Granger
Work on startup related things....
r2252 self._load_extensions()
self._run_exec_lines()
self._run_exec_files()
Brian Granger
All code startup related things are working....
r2253 self._run_cmd_line_code()
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 self._configure_xmode()
def _enable_gui_pylab(self):
"""Enable GUI event loop integration, taking pylab into account."""
Global = self.master_config.Global
# Select which gui to use
if Global.wthread:
gui = inputhook.GUI_WX
elif Global.q4thread:
gui = inputhook.GUI_QT
elif Global.gthread:
gui = inputhook.GUI_GTK
else:
gui = None
if Global.pylab:
activate = self.shell.enable_pylab
else:
# Enable only GUI integration, no pylab
activate = inputhook.enable_gui
if gui or Global.pylab:
try:
m = "Enabling GUI event loop integration, toolkit=%s, pylab=%s"\
% (gui, Global.pylab)
self.log.info(m)
activate(gui)
except:
self.log.warn("Error in enabling GUI event loop integration:")
self.shell.showtraceback()
Brian Granger
Work on startup related things....
r2252
Brian Granger
Reenabled -wthread/-q4thread/-gthread and added warning for -pylab....
r2264
Brian Granger
Work on startup related things....
r2252 def _load_extensions(self):
"""Load all IPython extensions in Global.extensions.
This uses the :meth:`InteractiveShell.load_extensions` to load all
the extensions listed in ``self.master_config.Global.extensions``.
"""
try:
if hasattr(self.master_config.Global, 'extensions'):
self.log.debug("Loading IPython extensions...")
extensions = self.master_config.Global.extensions
for ext in extensions:
try:
self.log.info("Loading IPython extension: %s" % ext)
self.shell.load_extension(ext)
except:
self.log.warn("Error in loading extension: %s" % ext)
self.shell.showtraceback()
except:
self.log.warn("Unknown error in loading extensions:")
self.shell.showtraceback()
def _run_exec_lines(self):
"""Run lines of code in Global.exec_lines in the user's namespace."""
try:
if hasattr(self.master_config.Global, 'exec_lines'):
self.log.debug("Running code from Global.exec_lines...")
exec_lines = self.master_config.Global.exec_lines
for line in exec_lines:
try:
self.log.info("Running code in user namespace: %s" % line)
self.shell.runlines(line)
except:
self.log.warn("Error in executing line in user namespace: %s" % line)
self.shell.showtraceback()
except:
self.log.warn("Unknown error in handling Global.exec_lines:")
self.shell.showtraceback()
Brian Granger
All code startup related things are working....
r2253 def _exec_file(self, fname):
Brian Granger
Beginning to transition all paths, files, dirs over to unicode....
r2328 full_filename = filefind(fname, [u'.', self.ipython_dir])
Brian Granger
All code startup related things are working....
r2253 if os.path.isfile(full_filename):
Brian Granger
Beginning to transition all paths, files, dirs over to unicode....
r2328 if full_filename.endswith(u'.py'):
Brian Granger
All code startup related things are working....
r2253 self.log.info("Running file in user namespace: %s" % full_filename)
self.shell.safe_execfile(full_filename, self.shell.user_ns)
elif full_filename.endswith('.ipy'):
self.log.info("Running file in user namespace: %s" % full_filename)
self.shell.safe_execfile_ipy(full_filename)
else:
self.log.warn("File does not have a .py or .ipy extension: <%s>" % full_filename)
Brian Granger
Work on startup related things....
r2252 def _run_exec_files(self):
try:
if hasattr(self.master_config.Global, 'exec_files'):
self.log.debug("Running files in Global.exec_files...")
exec_files = self.master_config.Global.exec_files
for fname in exec_files:
Brian Granger
All code startup related things are working....
r2253 self._exec_file(fname)
Brian Granger
Work on startup related things....
r2252 except:
self.log.warn("Unknown error in handling Global.exec_files:")
self.shell.showtraceback()
Brian Granger
All code startup related things are working....
r2253 def _run_cmd_line_code(self):
if hasattr(self.master_config.Global, 'code_to_run'):
line = self.master_config.Global.code_to_run
try:
self.log.info("Running code given at command line (-c): %s" % line)
self.shell.runlines(line)
except:
self.log.warn("Error in executing line in user namespace: %s" % line)
self.shell.showtraceback()
return
# Like Python itself, ignore the second if the first of these is present
try:
fname = self.extra_args[0]
except:
pass
else:
try:
self._exec_file(fname)
except:
self.log.warn("Error in executing file in user namespace: %s" % fname)
self.shell.showtraceback()
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363 def _configure_xmode(self):
# XXX - shouldn't this be read from the config? I'm still a little
# lost with all the details of handling the new config guys...
self.shell.InteractiveTB.set_mode(mode=self.shell.xmode)
Brian Granger
Massive, crazy refactoring of everything....
r2202 def start_app(self):
Brian Granger
All code startup related things are working....
r2253 if self.master_config.Global.interact:
self.log.debug("Starting IPython's mainloop...")
self.shell.mainloop()
Brian Granger
Massive, crazy refactoring of everything....
r2202
Fernando Perez
First semi-complete support for -pylab and %pylab....
r2363
Brian Granger
Lots of work on command line options and env vars....
r2322 def load_default_config(ipython_dir=None):
"""Load the default config file from the default ipython_dir.
Brian Granger
Massive refactoring of of the core....
r2245
This is useful for embedded shells.
"""
Brian Granger
Lots of work on command line options and env vars....
r2322 if ipython_dir is None:
ipython_dir = get_ipython_dir()
cl = PyFileConfigLoader(default_config_file_name, ipython_dir)
Brian Granger
Massive refactoring of of the core....
r2245 config = cl.load_config()
return config
Brian Granger
Removed ipapi compatability layer and updated top-level functions....
r2269 def launch_new_instance():
Brian Granger
Work on ipcontroller....
r2296 """Create and run a full blown IPython instance"""
Brian Granger
Massive, crazy refactoring of everything....
r2202 app = IPythonApp()
Brian Granger
Removed ipapi compatability layer and updated top-level functions....
r2269 app.start()