From 0ad14582409d51ccbe8ec75b66d79bd33a61e6b6 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Fri, 12 Nov 2021 16:59:40 -0500 Subject: [PATCH 1/4] Change load to introduce a name (rather than have plugin look it up) Also, DynamicPlugin placeholder --- src/rosdiscover/interpreter/interpreter.py | 2 +- src/rosdiscover/interpreter/plugin.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/rosdiscover/interpreter/interpreter.py b/src/rosdiscover/interpreter/interpreter.py index 50ab9d5e..a3cc37d9 100644 --- a/src/rosdiscover/interpreter/interpreter.py +++ b/src/rosdiscover/interpreter/interpreter.py @@ -123,7 +123,7 @@ def key(x: NodeConfig) -> str: # now that all nodes have been initialised, load all plugins for node_context in self.nodes.values(): for plugin in node_context._plugins: - plugin.load(self) + plugin.load(self, node_context) def _create_nodelet_manager(self, name: str, diff --git a/src/rosdiscover/interpreter/plugin.py b/src/rosdiscover/interpreter/plugin.py index c4048888..298df6b3 100644 --- a/src/rosdiscover/interpreter/plugin.py +++ b/src/rosdiscover/interpreter/plugin.py @@ -4,6 +4,11 @@ import abc import typing +import attr +from loguru import logger + +from . import NodeContext + if typing.TYPE_CHECKING: from .interpreter import Interpreter @@ -12,6 +17,19 @@ class ModelPlugin(abc.ABC): """Models the architectural effects of a dynamically-loaded node plugin (e.g., a Gazebo plugin).""" @abc.abstractmethod - def load(self, interpreter: 'Interpreter') -> None: + def load(self, interpreter: 'Interpreter', context: NodeContext) -> None: """Simulates the effects of loading this plugin in a given context.""" ... + + +@attr.s(frozen=True, slots=True) +class DynamicPlugin(abc.ABC): + """ + Models dynamically loaded plygins, taking in a name of the plygin that + will be recovered when the plugin is loaded + """ + + name: str = attr.ib() + + def load(self, interpreter: 'Interpreter', context: NodeContext) -> None: + logger.warning("Dynamic loading of plugins for {name} not implemented") From 4acb58d8fc81e3f8caba40885c0c43df34f6a3b4 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Fri, 12 Nov 2021 17:00:36 -0500 Subject: [PATCH 2/4] Change navigation to use new plugin refactor --- src/rosdiscover/models/plugins/navigation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rosdiscover/models/plugins/navigation.py b/src/rosdiscover/models/plugins/navigation.py index f310dfb9..f0cecaaf 100644 --- a/src/rosdiscover/models/plugins/navigation.py +++ b/src/rosdiscover/models/plugins/navigation.py @@ -62,8 +62,8 @@ class StaticLayerPlugin(NavigationPlugin): node_name: str = attr.ib() reference_name: t.Optional[str] = attr.ib() - def load(self, interpreter: Interpreter) -> None: - move_base = get_move_base(interpreter, self.node_name) + def load(self, interpreter: Interpreter, c: NodeContext) -> None: + move_base = c # get_move_base(interpreter, self.node_name) move_base.read('~unknown_cost_value', -1) move_base.read('~lethal_cost_value', 100) From 3ef6151504dc1ce98206e2cd7d088e925e4ee348 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Mon, 15 Nov 2021 09:19:05 -0500 Subject: [PATCH 3/4] Added generate_dynamic_plugin to dynamically creat plugin class. --- src/rosdiscover/interpreter/plugin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rosdiscover/interpreter/plugin.py b/src/rosdiscover/interpreter/plugin.py index 298df6b3..5024e02c 100644 --- a/src/rosdiscover/interpreter/plugin.py +++ b/src/rosdiscover/interpreter/plugin.py @@ -22,14 +22,15 @@ def load(self, interpreter: 'Interpreter', context: NodeContext) -> None: ... -@attr.s(frozen=True, slots=True) -class DynamicPlugin(abc.ABC): +class DynamicPlugin(type, ModelPlugin): """ Models dynamically loaded plygins, taking in a name of the plygin that will be recovered when the plugin is loaded """ - name: str = attr.ib() - def load(self, interpreter: 'Interpreter', context: NodeContext) -> None: logger.warning("Dynamic loading of plugins for {name} not implemented") + + +def generate_dynamic_plugin(plugin_name: str) -> type: + return type(f"{plugin_name}DynamicPlugin", (DynamicPlugin), {'plugin_name': plugin_name}) From 84fc822d65f8d2fc68b6856574a238c5d815dc66 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Mon, 15 Nov 2021 13:44:50 -0500 Subject: [PATCH 4/4] attrs --- src/rosdiscover/interpreter/plugin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rosdiscover/interpreter/plugin.py b/src/rosdiscover/interpreter/plugin.py index 5024e02c..fd21eb21 100644 --- a/src/rosdiscover/interpreter/plugin.py +++ b/src/rosdiscover/interpreter/plugin.py @@ -4,7 +4,6 @@ import abc import typing -import attr from loguru import logger from . import NodeContext @@ -24,7 +23,7 @@ def load(self, interpreter: 'Interpreter', context: NodeContext) -> None: class DynamicPlugin(type, ModelPlugin): """ - Models dynamically loaded plygins, taking in a name of the plygin that + Models dynamically loaded plugins, taking in a name of the plygin that will be recovered when the plugin is loaded """