def _declare_cell_magic(name, module, magic_module_loader):
    """Declare a cell magic called name in module."""
    # If the module or extension has already been imported, don't overwrite the
    # existing definition.
    if module in sys.modules or module in get_ipython(
    ).extension_manager.loaded:
        return

    def impl(line, cell, **kwargs):
        return _get_extension_magic(name, module, 'cell',
                                    magic_module_loader)(line, cell, **kwargs)

    # pylint: disable=g-long-lambda
    impl.getdoc = lambda: _get_extension_magic(name, module, 'cell',
                                               magic_module_loader).__doc__
    magic.register_cell_magic(name)(impl)
Ejemplo n.º 2
0
    def _make_cell_magic(self, cell_magic_name):
        def _run_cell_func(cell):
            run_cell(cell, store_history=self.config.store_history)

        def _dependency_safety(_, cell: str):
            self.safe_execute(cell, _run_cell_func)

        # FIXME (smacke): probably not a great idea to rely on this
        _dependency_safety.__name__ = cell_magic_name
        return register_cell_magic(_dependency_safety)
Ejemplo n.º 3
0
    def _make_cell_magic(self, cell_magic_name):
        # this is to avoid capturing `self` and creating an extra reference to the singleton
        store_history = self.settings.store_history

        def _run_cell_func(cell):
            run_cell(cell, store_history=store_history)

        def _dependency_safety(_, cell: str):
            singletons.nbs().safe_execute(cell, _run_cell_func)

        # FIXME (smacke): probably not a great idea to rely on this
        _dependency_safety.__name__ = cell_magic_name
        return register_cell_magic(_dependency_safety)
Ejemplo n.º 4
0
def load_ipython_extension(ipython):
    magic.register_cell_magic(pytest)
Ejemplo n.º 5
0
def load_ipython_extension(shell):
	"""Load the extension."""
	register_cell_magic(jinja2)
Ejemplo n.º 6
0
    def vipas(self, line, cell):
        """
        run a cell magic function, that will not hold the process
        """
        ishell = get_ipython()
        proc = Process(target=ishell.run_cell, args=(cell, ), daemon=True)
        proc.start()
        self.procs.append(proc)


try:
    ishell = get_ipython()
    from IPython.core import magic
    vipa_class = VipaClass()
    magic.register_cell_magic(vipa_class.vipas)
    vipas = vipa_class.vipas
except:
    pass


# Cell
class SingleFileLiner:
    """
    Text data reading line by line for multiprocessing
    """
    def __init__(self, file_path: Path, total: int = None):
        """
        filepath: Path,
            path to a textual file
        total: int
Ejemplo n.º 7
0
def register():
    register_cell_magic(hlt)
    register_cell_magic(cache)
    register_cell_magic(conc)
Ejemplo n.º 8
0
def load_ipython_extension(ipython):
    from IPython.core.magic import register_line_magic, register_cell_magic

    register_line_magic(profilegraph)
    register_cell_magic(profilegraph)
Ejemplo n.º 9
0
def load_ipython_extension(ipython):
    magic.register_cell_magic(pytest)