Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autobrew any kwargs #476

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion brewtils/auto_decorator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import inspect
from inspect import Parameter as InspectParameter # noqa
from inspect import signature


from brewtils.models import Command, Parameter

Expand Down Expand Up @@ -27,8 +29,17 @@ 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()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using has_kwargs as the input to allow_any_kwargs for both thr hidden and not hidden scenarios.

We could redo this as
_wrapped.command = Command(hidden=func.startswith(""), allow_any_kwargs=has_kwargs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one line should now cover all three if states we have here. So you can drop them and just have that single statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I botched this fix. Fixed better this time. Good solution.

Expand Down
Loading