Пример #1
0
def load_ipython_extension(ipython):
    if ECLICore.instance is not None:
        print('ECLICore already loaded')
        return None

    logging.basicConfig()

    instance = ECLICore(shell=ipython, config=ipython.config)
    ECLICore.instance = instance

    util.__ipython__ = ipython
    util.export_magic_by_decorator(ipython, globals())
    util.export_class_magic(ipython, instance)
    return instance
Пример #2
0
    def register_extension(self, plugin_class, globals_=None, class_magic=True,
                           **kwargs):
        """
        Register an extension with ECLI

        :param plugin_class: The class of the extension/plugin
        :type plugin_class: class
        :param globals_: if specified, the global namespace will be checked for
                         magicargument/ECLIExport decorators, automatically exporting
                         those to the user namespace
        :type globals_: dict
        :param class_magic: if enabled, the class will be checked for magic args/
                            ECLIExport decorators
        :type class_magic: bool
        :param kwargs: passed to the plugin class initializer
        :type kwargs: dict
        """
        assert(ECLIPlugin in plugin_class.__bases__)

        name = plugin_class.__name__
        version = plugin_class.VERSION
        requires = plugin_class.REQUIRES

        if name in self._extensions:
            logger.error('Extension already loaded: %s' % (name, ))
            return None

        if not self.check_requirements(requires):
            logger.error('* Failed to load %s (version %s)' % (name, version))
            return None

        instance = plugin_class(shell=self.shell, config=self.shell.config,
                                **kwargs)

        # IPython did away with its plugin management system:
        #self.shell.plugin_manager.register_plugin(name, instance)

        if globals_ is not None:
            util.export_magic_by_decorator(self.shell, globals_)

        if class_magic:
            util.export_class_magic(self.shell, instance)

        self._extensions[name] = instance
        logger.info('* Extension %s loaded' % name)

        self.run_callback(self.CB_EXTENSION_LOADED, self.__class__.__name__,
                          ext_name=name)
        return instance