From dd5904c27324ca23718e3bf5efffd05078978a86 Mon Sep 17 00:00:00 2001 From: Jan Lerking Date: Thu, 27 Mar 2025 10:46:05 +0100 Subject: [PATCH] 0.2.1 Updated to include keyword arguments in run() method. /JL --- example.py | 2 +- plugins/example_plugin/example_plugin.py | 17 +++++++++++++---- setup.py | 2 +- xtendr/xtendrbase.py | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/example.py b/example.py index f34bfde..ce3ed26 100644 --- a/example.py +++ b/example.py @@ -16,7 +16,7 @@ if __name__ == "__main__": """ system = XtendRSystem() system.attach("example_plugin") # Assuming 'example_plugin/plugin_info.json' exists - system.run("example_plugin", "Hello!") + system.run("example_plugin", test="Hello!") system.stop("example_plugin") system.run("example_plugin", 25) system.stop("example_plugin") diff --git a/plugins/example_plugin/example_plugin.py b/plugins/example_plugin/example_plugin.py index 516abd7..0dbef91 100644 --- a/plugins/example_plugin/example_plugin.py +++ b/plugins/example_plugin/example_plugin.py @@ -13,10 +13,19 @@ class ExamplePlugin(XtendRBase): >>> plugin.stop() ExamplePlugin has stopped! """ - def run(self, *args): - print(f"Passed arguments {len(args)}:") - for idx, a in enumerate(args): - print(f"Argument {idx}: {a}") + def run(self, *args, **kwargs): + arglen = len(args) + keylen = len(kwargs) + if arglen > 0: + print(f"Passed arguments {arglen}:") + for idx, a in enumerate(args): + print(f"Argument {idx}: {a}") + if keylen > 0: + print(f"Keyword arguments passed {keylen}") + if not "test" in kwargs: + raise ValueError("Didn't get expected 'test' keyword!") + for kw in kwargs: + print(f"Argument {kw}: {kwargs[kw]}") print("ExamplePlugin is running!") diff --git a/setup.py b/setup.py index 4e0294c..302cc2b 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ if __name__ == "__main__": setup( name="XtendR", - version="0.2.0", + version="0.2.1", packages=find_packages(), install_requires=[], author="Jan Lerking", diff --git a/xtendr/xtendrbase.py b/xtendr/xtendrbase.py index e7f2e30..d5c9234 100644 --- a/xtendr/xtendrbase.py +++ b/xtendr/xtendrbase.py @@ -17,7 +17,7 @@ class XtendRBase(ABC): Stopping TestPlugin """ @abstractmethod - def run(self, *args): + def run(self, *args, **kwargs): pass @abstractmethod