config.configurable — IPython 3.2.1 documentation (original) (raw)

A base class for objects that are configurable.

5 Classes

class IPython.config.configurable. ConfigurableError

Bases: Exception

class IPython.config.configurable. MultipleInstanceError

Bases: IPython.config.configurable.ConfigurableError

class IPython.config.configurable. Configurable(**kwargs)

Bases: IPython.utils.traitlets.HasTraits

__init__(**kwargs)

Create a configurable given a config config.

Parameters: config : Config If this is empty, default values are used. If config is aConfig instance, it will be used to configure the instance. parent : Configurable instance, optional The parent Configurable instance of this object.

Notes

Subclasses of Configurable must call the __init__() method ofConfigurable before doing anything else and usingsuper():

class MyConfigurable(Configurable): def init(self, config=None): super(MyConfigurable, self).init(config=config) # Then any other code you need to finish initialization.

This ensures that instances will be configured properly.

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 section_names()

return section names as a list

update_config(config)

Fire the traits events when the config is updated.

class IPython.config.configurable. SingletonConfigurable(**kwargs)

Bases: IPython.config.configurable.Configurable

A configurable that only allows one instance.

This class is for classes that should only have one instance of itself or any subclass. To create and retrieve such a class use theSingletonConfigurable.instance() method.

classmethod clear_instance()

unset _instance for this class and singleton parents.

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

class IPython.config.configurable. LoggingConfigurable(**kwargs)

Bases: IPython.config.configurable.Configurable

A parent class for Configurables that log.

Subclasses have a log trait, and the default behavior is to get the logger from the currently running Application.