module ipythonhelper.magic_class

Inheritance diagram of pyquickhelper.ipythonhelper.magic_class

Short summary

module pyquickhelper.ipythonhelper.magic_class

Magic command to handle files

source on GitHub

Classes

class

truncated documentation

MagicClassWithHelpers

Provides some functions reused in others classes inherited from Magics. The class should not be registered as it is …

Properties

property

truncated documentation

Context

return the context or None

cross_validation_lock

A contextmanager for running a block with our cross validation lock set to True. At the end of the block, …

Methods

method

truncated documentation

add_context

add context to the class, mostly for debug purpose

get_args

parser a command line with a given parser

get_parser

Returns a parser for a magic command, initializes it if it does not exists, it creates it. The parsers are stored …

Documentation

Magic command to handle files

source on GitHub

class pyquickhelper.ipythonhelper.magic_class.MagicClassWithHelpers(**kwargs: Any)[source]

Bases: Magics

Provides some functions reused in others classes inherited from Magics. The class should not be registered as it is but should be used as an ancestor for another class. It can be registered this way:

def register_file_magics():
    from IPython import get_ipython
    ip = get_ipython()
    ip.register_magics(MagicFile)

source on GitHub

Create a configurable given a config config.

Parameters

configConfig

If this is empty, default values are used. If config is a Config instance, it will be used to configure the instance.

parentConfigurable instance, optional

The parent Configurable instance of this object.

Notes

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

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.

property Context[source]

return the context or None

source on GitHub

_all_trait_default_generators: Dict[str, Any] = {'config': <bound method TraitType.default of <traitlets.traitlets.Instance object>>, 'parent': <bound method TraitType.default of <traitlets.traitlets.Instance object>>}[source]
_cross_validation_lock: bool[source]
_descriptors = [<traitlets.traitlets.ObserveHandler object>, <traitlets.traitlets.Instance object>, <traitlets.traitlets.Instance object>][source]
_instance_inits = [<bound method ObserveHandler.instance_init of <traitlets.traitlets.ObserveHandler object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>][source]
_parser_store = {}[source]
_static_immutable_initial_values: Dict[str, Any] = {'parent': None}[source]
_trait_default_generators = {}[source]
_trait_notifiers: Dict[str, Any][source]
_trait_validators: Dict[str, Any][source]
_trait_values: Dict[str, Any][source]
_traits: Dict[str, Any] = {'config': <traitlets.traitlets.Instance object>, 'parent': <traitlets.traitlets.Instance object>}[source]
add_context(context)[source]

add context to the class, mostly for debug purpose

Parameters:

context – dictionary

source on GitHub

get_args(line, parser, print_function=<built-in function print>)[source]

parser a command line with a given parser

Parameters:
  • line – string (command line)

  • parser – parser which has to be used to parse line

  • print_function – function to use to display the help

Returns:

results

If the line cannot be parsed, the function displays the help using function print.

Example:

@line_magic
def custom_magic_command(self, line):
    parser = self.get_parser(MagicClass.custom_magic_command_parser, "custom_magic_command")
    args = self.get_args(line, parser)
    if args is not None:
        param = args.param

        # ....

source on GitHub

get_parser(parser_class, name)[source]

Returns a parser for a magic command, initializes it if it does not exists, it creates it. The parsers are stored in static member _parser_store.

Parameters:
  • parser_class – the parser to use for this magic command

  • name – name of the static variable which will contain the parser

See method get_args

source on GitHub