From 80f92d5f9cd8bdaf2edbfc5ae299bd25bac38fd6 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Thu, 4 Aug 2022 13:31:11 -0400 Subject: [PATCH] Allow simpler passing for individual host classes Most used of Broker are for simple (single host type per operation) cases. Becuase of this, most users passing in custom host classes are passing in a single class. In these cases, it makes more sense to allow for an easier way to pass along the class than to specify it via key/Class mappings. --- README.md | 2 +- broker/broker.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2497ee24..05599809 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ from broker.hosts import Host class MyHost(Host): ... -with Broker(..., host_classes={'host': MyHost}) as my_host: +with Broker(..., host_class=MyHost) as my_host: ... ``` diff --git a/broker/broker.py b/broker/broker.py index 089d2f36..6fc6901a 100644 --- a/broker/broker.py +++ b/broker/broker.py @@ -105,7 +105,10 @@ def __init__(self, **kwargs): nick = kwargs.pop("nick") kwargs = helpers.merge_dicts(kwargs, helpers.resolve_nick(nick)) logger.debug(f"kwargs after nick resolution {kwargs=}") - if "host_classes" in kwargs: + # Allow users to more simply pass a host class instead of a dict + if "host_class" in kwargs: + self.host_classes["host"] = kwargs.pop("host_class") + elif "host_classes" in kwargs: self.host_classes.update(kwargs.pop("host_classes")) # determine the provider actions based on kwarg parameters self._provider_actions = {}