Example #1
0
    def _create_context_for_plugin(
            self, plugin: BasePlugin, args: Namespace,
            chain_config: ChainConfig,
            boot_kwargs: Dict[str, Any]) -> PluginContext:

        context: PluginContext = None
        if plugin.process_scope in self.MAIN_ANS_SHARED_SCOPES:
            # A plugin that runs in a shared process as well as a plugin that overtakes the main
            # process uses the endpoint of the PluginManager which will either be the main
            # endpoint or the networking endpoint in the case of Trinity
            context = PluginContext(self._scope.endpoint)
        elif plugin.process_scope is PluginProcessScope.ISOLATED:
            # A plugin that runs in it's own process gets a new endpoint created to get
            # passed into that new process

            # mypy doesn't know it can only be that scope at this point. The `isinstance`
            # check avoids adding an ignore
            if isinstance(self._scope, MainAndIsolatedProcessScope):
                endpoint = self._scope.event_bus.create_endpoint(plugin.name)
                context = PluginContext(endpoint)
        else:
            Exception("Invariant: unreachable code path")

        context.args = args
        context.chain_config = chain_config
        context.boot_kwargs = boot_kwargs

        return context
Example #2
0
    def create_plugin_context(self,
                              plugin: BasePlugin,
                              args: Namespace,
                              chain_config: ChainConfig,
                              boot_kwargs: Dict[str, Any]) -> PluginContext:

        # Plugins that run in a shared process all share the endpoint of the plugin manager
        context = PluginContext(self.endpoint)
        context.args = args
        context.chain_config = chain_config
        context.boot_kwargs = boot_kwargs
        return context
Example #3
0
    def create_plugin_context(self,
                              plugin: BasePlugin,
                              args: Namespace,
                              chain_config: ChainConfig,
                              boot_kwargs: Dict[str, Any]) -> PluginContext:

        if isinstance(plugin, BaseIsolatedPlugin):
            # Isolated plugins get an entirely new endpoint to be passed into that new process
            context = PluginContext(
                self.event_bus.create_endpoint(plugin.name)
            )
            context.args = args
            context.chain_config = chain_config
            context.boot_kwargs = boot_kwargs
            return context

        # A plugin that overtakes the main process never gets far enough to even get a context.
        # For now it should be safe to just return `None`. Maybe reconsider in the future.
        return None