IPython Documentation

Table Of Contents

Previous topic

IPython

Next topic

config.configurable

This Page

config.application

Module: config.application

Inheritance diagram for IPython.config.application:

A base class for a configurable application.

Authors:

  • Brian Granger
  • Min RK

Classes

Application

class IPython.config.application.Application(**kwargs)

Bases: IPython.config.configurable.SingletonConfigurable

A singleton application with full configuration support.

__init__(**kwargs)
aliases

An instance of a Python dict.

classmethod class_config_section()

Get the config class config section

classmethod class_get_help(inst=None)

Get the help string for this class in ReST format.

If inst is given, it’s current trait values will be used in place of class defaults.

classmethod class_get_trait_help(trait, inst=None)

Get the help string for a single trait.

If inst is given, it’s current trait values will be used in place of the class default.

classmethod class_print_help(inst=None)

Get the help string for a single trait and print it.

classmethod class_trait_names(**metadata)

Get a list of all the names of this classes traits.

This method is just like the trait_names() method, but is unbound.

classmethod class_traits(**metadata)

Get a list of all the traits of this class.

This method is just like the traits() method, but is unbound.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

classes

An instance of a Python list.

classmethod clear_instance()

unset _instance for this class and singleton parents.

config

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

created = None
description

A trait for unicode strings.

examples

A trait for unicode strings.

exit(exit_status=0)
extra_args

An instance of a Python list.

flags

An instance of a Python dict.

flatten_flags()

flatten flags and aliases, so cl-args override as expected.

This prevents issues such as an alias pointing to InteractiveShell, but a config file setting the same trait in TerminalInteraciveShell getting inappropriate priority over the command-line arg.

Only aliases with exactly one descendent in the class list will be promoted.

generate_config_file()

generate default config file from Configurables

initialize(argv=None)

Do the basic steps to configure me.

Override in subclasses.

initialize_subcommand(subc, argv=None)

Initialize a subcommand with argv.

classmethod initialized()

Has an instance been created?

classmethod instance(*args, **kwargs)

Returns a global instance of this class.

This method create a new instance if none have previously been created and returns a previously created instance is one already exists.

The arguments and keyword arguments passed to this method are passed on to the __init__() method of the class upon instantiation.

Examples

Create a singleton class using instance, and retrieve it:

>>> from IPython.config.configurable import SingletonConfigurable
>>> class Foo(SingletonConfigurable): pass
>>> foo = Foo.instance()
>>> foo == Foo.instance()
True

Create a subclass that is retrived using the base class instance:

>>> class Bar(SingletonConfigurable): pass
>>> class Bam(Bar): pass
>>> bam = Bam.instance()
>>> bam == Bar.instance()
True
keyvalue_description

A trait for unicode strings.

load_config_file(filename, path=None)

Load a .py based config file by filename and path.

log

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

log_format

A trait for unicode strings.

log_level

An enum that whose value must be in a given sequence.

name

A trait for unicode strings.

on_trait_change(handler, name=None, remove=False)

Setup a handler to be called when a trait changes.

This is used to setup dynamic notifications of trait changes.

Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).

Parameters :

handler : callable

A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new) or handler(name, old, new).

name : list, str, None

If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.

remove : bool

If False (the default), then install the handler. If True then unintall it.

option_description

A trait for unicode strings.

parse_command_line(argv=None)

Parse the command line arguments.

print_alias_help()

Print the alias part of the help.

print_description()

Print the application description.

print_examples()

Print usage and examples.

This usage string goes at the end of the command line help string and should contain examples of the application’s usage.

print_flag_help()

Print the flag part of the help.

print_help(classes=False)

Print the help for each Configurable class in self.classes.

If classes=False (the default), only flags and aliases are printed.

print_options()
print_subcommands()

Print the subcommand part of the help.

print_version()

Print the version string.

start()

Start the app mainloop.

Override in subclasses.

subapp

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

subcommand_description

A trait for unicode strings.

subcommands

An instance of a Python dict.

trait_metadata(traitname, key)

Get metadata values for trait by key.

trait_names(**metadata)

Get a list of all the names of this classes traits.

traits(**metadata)

Get a list of all the traits of this class.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

update_config(config)

Fire the traits events when the config is updated.

version

A trait for unicode strings.

ApplicationError

class IPython.config.application.ApplicationError

Bases: exceptions.Exception

__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

args
message

Functions

IPython.config.application.boolean_flag(name, configurable, set_help='', unset_help='')

Helper for building basic –trait, –no-trait flags.

Parameters :

name : str

The name of the flag.

configurable : str

The ‘Class.trait’ string of the trait to be set/unset with the flag

set_help : unicode

help string for –name flag

unset_help : unicode

help string for –no-name flag

Returns :

cfg : dict

A dict with two keys: ‘name’, and ‘no-name’, for setting and unsetting the trait, respectively.

IPython.config.application.catch_config_error(method)

Method decorator for catching invalid config (Trait/ArgumentErrors) during init.

On a TraitError (generally caused by bad config), this will print the trait’s message, and exit the app.

For use on init methods, to prevent invoking excepthook on invalid input.