diff --git a/brewtils/decorators.py b/brewtils/decorators.py index 7186aaa5..d6e332ba 100644 --- a/brewtils/decorators.py +++ b/brewtils/decorators.py @@ -41,6 +41,8 @@ def client( group=None, # type: str groups=[], # type: Optional[List[str]] prefix_topic=None, # type: Optional[str] + require=None, # type: str + requires=[], # type: Optional[List[str]] ): # type: (...) -> Type """Class decorator that marks a class as a beer-garden Client @@ -70,6 +72,8 @@ def client( group: Optional plugin group groups: Optional plugin groups prefix_topic: Optional prefix for Generated Command to Topic mappings + require: Optional system dependency + requires: Optional system dependencies Returns: The decorated class @@ -83,6 +87,8 @@ def client( groups=groups, group=group, prefix_topic=prefix_topic, + require=require, + requires=requires, ) # noqa # Assign these here so linters don't complain @@ -92,10 +98,14 @@ def client( _wrapped._current_request = None _wrapped._groups = groups _wrapped._prefix_topic = prefix_topic + _wrapped._requires = requires if group: _wrapped._groups.append(group) + if require: + _wrapped._requires.append(require) + return _wrapped diff --git a/brewtils/plugin.py b/brewtils/plugin.py index 87e51a92..b45c5fe6 100644 --- a/brewtils/plugin.py +++ b/brewtils/plugin.py @@ -310,6 +310,8 @@ def _set_client(self, new_client): self._system.prefix_topic = getattr( new_client, "_prefix_topic", None ) # noqa + if not self._system.requires: + self._system.requires = getattr(new_client, "_requires", []) # noqa # Now roll up / interpret all metadata to get the Commands self._system.commands = _parse_client(new_client) @@ -326,6 +328,7 @@ def _set_client(self, new_client): client_clazz._bg_commands = self._system.commands client_clazz._groups = self._system.groups client_clazz._prefix_topic = self._system.prefix_topic + client_clazz._requires = self._system.requires client_clazz._current_request = client_clazz.current_request except TypeError: if sys.version_info.major != 2: diff --git a/test/decorators_test.py b/test/decorators_test.py index c7e4ad78..ed01ca8a 100644 --- a/test/decorators_test.py +++ b/test/decorators_test.py @@ -512,6 +512,7 @@ def foo(self): assert hasattr(ClientClass, "_current_request") assert hasattr(ClientClass, "_groups") assert hasattr(ClientClass, "_prefix_topic") + assert hasattr(ClientClass, "_requires") def test_with_args(self): @client( @@ -519,6 +520,7 @@ def test_with_args(self): bg_version="1.0.0", groups=["GroupA"], prefix_topic="custom_topic", + requires=["SystemA"], ) class ClientClass(object): @command @@ -531,11 +533,13 @@ def foo(self): assert hasattr(ClientClass, "_current_request") assert hasattr(ClientClass, "_groups") assert hasattr(ClientClass, "_prefix_topic") + assert hasattr(ClientClass, "_requires") assert ClientClass._bg_name == "sys" assert ClientClass._bg_version == "1.0.0" assert ClientClass._groups == ["GroupA"] assert ClientClass._prefix_topic == "custom_topic" + assert ClientClass._requires == ["SystemA"] def test_group(self): @client(bg_name="sys", bg_version="1.0.0", group="GroupB") @@ -571,6 +575,42 @@ def foo(self): assert ClientClass._bg_version == "1.0.0" assert ClientClass._groups == ["GroupA", "GroupB"] + def test_require(self): + @client(bg_name="sys", bg_version="1.0.0", require="SystemB") + class ClientClass(object): + @command + def foo(self): + pass + + assert hasattr(ClientClass, "_bg_name") + assert hasattr(ClientClass, "_bg_version") + assert hasattr(ClientClass, "_bg_commands") + assert hasattr(ClientClass, "_current_request") + assert hasattr(ClientClass, "_requires") + + assert ClientClass._bg_name == "sys" + assert ClientClass._bg_version == "1.0.0" + assert ClientClass._requires == ["SystemB"] + + def test_requires_combine(self): + @client( + bg_name="sys", bg_version="1.0.0", requires=["SystemA"], require="SystemB" + ) + class ClientClass(object): + @command + def foo(self): + pass + + assert hasattr(ClientClass, "_bg_name") + assert hasattr(ClientClass, "_bg_version") + assert hasattr(ClientClass, "_bg_commands") + assert hasattr(ClientClass, "_current_request") + assert hasattr(ClientClass, "_requires") + + assert ClientClass._bg_name == "sys" + assert ClientClass._bg_version == "1.0.0" + assert ClientClass._requires == ["SystemA", "SystemB"] + class TestCommand(object): """Test command decorator"""