From 5ec113e4df2e925a2ba5e169560b14228d6fcbae Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Mon, 13 May 2024 17:04:17 +0000 Subject: [PATCH 1/4] Autobrew any kwargs --- CHANGELOG.rst | 1 + brewtils/auto_decorator.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index db4b7146..1ec6869b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Brewtils Changelog ------ TBD +- Added support for autobrew any kwargs - Added API support for Latest System, SystemClient will use Version `latest` instead of resolved version. Allowing Beer Garden to resolve the latest version. - Must upgrade to a minimum version of Beer Garden 3.26.0 to support new APIs diff --git a/brewtils/auto_decorator.py b/brewtils/auto_decorator.py index b4fc7f64..0f7f358c 100644 --- a/brewtils/auto_decorator.py +++ b/brewtils/auto_decorator.py @@ -1,4 +1,6 @@ -import inspect +from inspect import Parameter as InspectParameter # noqa +from inspect import signature + from brewtils.models import Command, Parameter @@ -27,8 +29,11 @@ def addFunctions(self, client): _wrapped = getattr(client, func) if not hasattr(_wrapped, "_command") and not func.startswith("__"): # decorators.py will handle all of the markings + has_kwargs = any([True for p in signature(_wrapped).parameters.values() if p.kind == InspectParameter.VAR_KEYWORD]) if func.startswith("_"): _wrapped._command = Command(hidden=True) + elif has_kwargs: + _wrapped._command = Command(allow_any_kwargs=True) else: _wrapped._command = Command() From 83e9e632eb3778875b064ac5e112c4446f6ab4cc Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Mon, 13 May 2024 17:14:29 +0000 Subject: [PATCH 2/4] Linting --- brewtils/auto_decorator.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/brewtils/auto_decorator.py b/brewtils/auto_decorator.py index 0f7f358c..045d60fa 100644 --- a/brewtils/auto_decorator.py +++ b/brewtils/auto_decorator.py @@ -29,7 +29,13 @@ def addFunctions(self, client): _wrapped = getattr(client, func) if not hasattr(_wrapped, "_command") and not func.startswith("__"): # decorators.py will handle all of the markings - has_kwargs = any([True for p in signature(_wrapped).parameters.values() if p.kind == InspectParameter.VAR_KEYWORD]) + has_kwargs = any( + [ + True + for p in signature(_wrapped).parameters.values() + if p.kind == InspectParameter.VAR_KEYWORD + ] + ) if func.startswith("_"): _wrapped._command = Command(hidden=True) elif has_kwargs: From 605cf9d87d8fb7ed6c54aeda4cc7aad570e7c5ad Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Mon, 13 May 2024 17:32:35 +0000 Subject: [PATCH 3/4] Fix to handle hidden parameter --- brewtils/auto_decorator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brewtils/auto_decorator.py b/brewtils/auto_decorator.py index 045d60fa..09855c11 100644 --- a/brewtils/auto_decorator.py +++ b/brewtils/auto_decorator.py @@ -39,7 +39,7 @@ def addFunctions(self, client): if func.startswith("_"): _wrapped._command = Command(hidden=True) elif has_kwargs: - _wrapped._command = Command(allow_any_kwargs=True) + _wrapped._command = Command(hidden=func.startswith("_"), allow_any_kwargs=True) else: _wrapped._command = Command() From 4db1bcc5b7c2f6b2b34b4c50bc4ed13e95860618 Mon Sep 17 00:00:00 2001 From: 1maple1 <160027655+1maple1@users.noreply.github.com> Date: Tue, 14 May 2024 09:24:05 +0000 Subject: [PATCH 4/4] Rewrite auto decorator to use one liner --- brewtils/auto_decorator.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/brewtils/auto_decorator.py b/brewtils/auto_decorator.py index 09855c11..0ddd3049 100644 --- a/brewtils/auto_decorator.py +++ b/brewtils/auto_decorator.py @@ -36,11 +36,8 @@ def addFunctions(self, client): if p.kind == InspectParameter.VAR_KEYWORD ] ) - if func.startswith("_"): - _wrapped._command = Command(hidden=True) - elif has_kwargs: - _wrapped._command = Command(hidden=func.startswith("_"), allow_any_kwargs=True) - else: - _wrapped._command = Command() + _wrapped._command = Command( + hidden=func.startswith("_"), allow_any_kwargs=has_kwargs + ) return client