Move controlpi.plugins to controlpi-plugins
authorBenjamin Braatz <bb@bbraatz.eu>
Fri, 5 Mar 2021 00:32:39 +0000 (01:32 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Fri, 5 Mar 2021 00:32:39 +0000 (01:32 +0100)
Namespace packages should not be inside regular packages:
https://stackoverflow.com/a/62992832

controlpi-plugins/util.py [new file with mode: 0644]
controlpi/__init__.py
controlpi/plugins/util.py [deleted file]
doc/index.md
setup.py

diff --git a/controlpi-plugins/util.py b/controlpi-plugins/util.py
new file mode 100644 (file)
index 0000000..0e598a2
--- /dev/null
@@ -0,0 +1,97 @@
+"""Provide utility plugins for all kinds of systems.
+
+TODO: documentation, doctests, check configurations during _process_conf
+TODO: State, AndState, OrState?
+"""
+import asyncio
+
+from controlpi import BasePlugin, Message, PluginConfiguration
+
+
+class Log(BasePlugin):
+    async def _log(self, message: Message) -> None:
+        print(f"{self._name}: {message}")
+
+    def _process_conf(self, conf: PluginConfiguration) -> None:
+        self._bus.register(self._name, [], conf['filter'], self._log)
+        super()._process_conf(conf)
+
+
+class Init(BasePlugin):
+    async def _execute(self, message: Message) -> None:
+        for message in self._messages:
+            await self._bus.send(message)
+
+    def _process_conf(self, conf: PluginConfiguration) -> None:
+        self._messages = []
+        for message in conf['messages']:
+            complete_message = {'sender': self._name}
+            complete_message.update(message)
+            self._messages.append(complete_message)
+        receives = [{'target': self._name, 'command': 'execute'}]
+        sends = []
+        sends.extend(receives)
+        sends.extend(conf['messages'])
+        self._bus.register(self._name, sends, receives, self._execute)
+        super()._process_conf(conf)
+
+    async def run(self) -> None:
+        await super().run()
+        await self._bus.send({'sender': self._name, 'target': self._name,
+                              'command': 'execute'})
+
+
+class Wait(BasePlugin):
+    async def _wait(self, message: Message) -> None:
+        await asyncio.sleep(self._seconds)
+        await self._bus.send({'sender': self._name, 'event': 'finished'})
+
+    def _process_conf(self, conf: PluginConfiguration) -> None:
+        self._seconds = conf['seconds']
+        receives = [{'target': self._name, 'command': 'wait'}]
+        sends = [{'event': 'finished'}]
+        self._bus.register(self._name, sends, receives, self._wait)
+        super()._process_conf(conf)
+
+
+class Alias(BasePlugin):
+    async def _alias(self, message: Message) -> None:
+        alias_message = {}
+        alias_message['sender'] = self._name
+        alias_message.update(self._to)
+        for key in message:
+            if key != 'sender' and key not in self._from:
+                alias_message[key] = message[key]
+        await self._bus.send(alias_message)
+
+    def _process_conf(self, conf: PluginConfiguration) -> None:
+        self._from = conf['from']
+        self._to = conf['to']
+        self._bus.register(self._name, [self._to], [self._from], self._alias)
+        super()._process_conf(conf)
+
+
+class State(BasePlugin):
+    async def _receive(self, message: Message) -> None:
+        if 'command' in message:
+            if message['command'] == 'get state':
+                await self._bus.send({'sender': self._name,
+                                      'state': self._state,
+                                      'changed': False})
+            elif message['command'] == 'set state':
+                if 'state' in message and self._state != message['state']:
+                    self._state: bool = message['state']
+                    await self._bus.send({'sender': self._name,
+                                          'state': self._state,
+                                          'changed': True})
+
+    def _process_conf(self, conf: PluginConfiguration) -> None:
+        self._state = False
+        sends: list[Message] = [{'sender': self._name, 'state': bool}]
+        receives: list[Message] = [{'target': self._name,
+                                    'command': 'get state'},
+                                   {'target': self._name,
+                                    'command': 'set state',
+                                    'state': bool}]
+        self._bus.register(self._name, sends, receives, self._receive)
+        super()._process_conf(conf)
index 8657d2aa3734d190f6328b548a477283a30f58cd..176a1c00e62102b826bcf27c9c153cf9368f4ddb 100644 (file)
@@ -257,7 +257,7 @@ async def run(conf: Configuration) -> None:
     """
     if not conf or not check_configuration(conf):
         return
-    plugins = PluginRegistry('controlpi.plugins', BasePlugin)
+    plugins = PluginRegistry('controlpi-plugins', BasePlugin)
     message_bus = MessageBus()
     coroutines = [message_bus.run()]
     for instance_name in conf:
diff --git a/controlpi/plugins/util.py b/controlpi/plugins/util.py
deleted file mode 100644 (file)
index 0e598a2..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-"""Provide utility plugins for all kinds of systems.
-
-TODO: documentation, doctests, check configurations during _process_conf
-TODO: State, AndState, OrState?
-"""
-import asyncio
-
-from controlpi import BasePlugin, Message, PluginConfiguration
-
-
-class Log(BasePlugin):
-    async def _log(self, message: Message) -> None:
-        print(f"{self._name}: {message}")
-
-    def _process_conf(self, conf: PluginConfiguration) -> None:
-        self._bus.register(self._name, [], conf['filter'], self._log)
-        super()._process_conf(conf)
-
-
-class Init(BasePlugin):
-    async def _execute(self, message: Message) -> None:
-        for message in self._messages:
-            await self._bus.send(message)
-
-    def _process_conf(self, conf: PluginConfiguration) -> None:
-        self._messages = []
-        for message in conf['messages']:
-            complete_message = {'sender': self._name}
-            complete_message.update(message)
-            self._messages.append(complete_message)
-        receives = [{'target': self._name, 'command': 'execute'}]
-        sends = []
-        sends.extend(receives)
-        sends.extend(conf['messages'])
-        self._bus.register(self._name, sends, receives, self._execute)
-        super()._process_conf(conf)
-
-    async def run(self) -> None:
-        await super().run()
-        await self._bus.send({'sender': self._name, 'target': self._name,
-                              'command': 'execute'})
-
-
-class Wait(BasePlugin):
-    async def _wait(self, message: Message) -> None:
-        await asyncio.sleep(self._seconds)
-        await self._bus.send({'sender': self._name, 'event': 'finished'})
-
-    def _process_conf(self, conf: PluginConfiguration) -> None:
-        self._seconds = conf['seconds']
-        receives = [{'target': self._name, 'command': 'wait'}]
-        sends = [{'event': 'finished'}]
-        self._bus.register(self._name, sends, receives, self._wait)
-        super()._process_conf(conf)
-
-
-class Alias(BasePlugin):
-    async def _alias(self, message: Message) -> None:
-        alias_message = {}
-        alias_message['sender'] = self._name
-        alias_message.update(self._to)
-        for key in message:
-            if key != 'sender' and key not in self._from:
-                alias_message[key] = message[key]
-        await self._bus.send(alias_message)
-
-    def _process_conf(self, conf: PluginConfiguration) -> None:
-        self._from = conf['from']
-        self._to = conf['to']
-        self._bus.register(self._name, [self._to], [self._from], self._alias)
-        super()._process_conf(conf)
-
-
-class State(BasePlugin):
-    async def _receive(self, message: Message) -> None:
-        if 'command' in message:
-            if message['command'] == 'get state':
-                await self._bus.send({'sender': self._name,
-                                      'state': self._state,
-                                      'changed': False})
-            elif message['command'] == 'set state':
-                if 'state' in message and self._state != message['state']:
-                    self._state: bool = message['state']
-                    await self._bus.send({'sender': self._name,
-                                          'state': self._state,
-                                          'changed': True})
-
-    def _process_conf(self, conf: PluginConfiguration) -> None:
-        self._state = False
-        sends: list[Message] = [{'sender': self._name, 'state': bool}]
-        receives: list[Message] = [{'target': self._name,
-                                    'command': 'get state'},
-                                   {'target': self._name,
-                                    'command': 'set state',
-                                    'state': bool}]
-        self._bus.register(self._name, sends, receives, self._receive)
-        super()._process_conf(conf)
index bdfff6a277cff44c839799e4f4b193499d86011b..b0fe96fe3ad1abe65862ca26aa62e68e9d6771e7 100644 (file)
@@ -91,8 +91,8 @@ Die ControlPi-Infrastruktur hat zwei Haupt-Bestandteile:
   weitere Plugin-Klassen in Python zu implementieren und (in anderen
   Code-Repositories und anderen Distributions-Paketen) zum System
   hinzuzufügen.
-  Im Modul `controlpi.plugins.util` bzw. der Datei
-  `controlpi/plugins/util.py` befindet sich eine Reihe nützlicher
+  Im Modul `controlpi-plugins.util` bzw. der Datei
+  `controlpi-plugins/util.py` befindet sich eine Reihe nützlicher
   Standard-Plugins, an denen die generelle Struktur nachvollzogen werden
   kann.
 - Ein Nachrichten-Bus erlaubt den Austausch von Nachrichten zwischen allen
@@ -119,7 +119,7 @@ Nachrichten.
 Sie müssen nicht unbedingt bestimmte Empfänger haben, sie gehören nicht
 unbedingt zu einem bestimmten Typen etc.
 
-Einige Konventionen, die z.B. von den Plugins in `controlpi.plugins.util`
+Einige Konventionen, die z.B. von den Plugins in `controlpi-plugins.util`
 eingehalten werden, sind aber:
 - Einige Nachrichten signalisieren, dass ein Ereignis eingetreten ist.
   Sie haben in der Regel einen Schlüssel `'event'` mit einem Wert, der die
index fb945fd588040d91a2652c555c65ebf8e41b8294..af67d931b737ebdbf2ce9eb01795e397865d52bc 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ setuptools.setup(
     long_description=long_description,
     long_description_content_type="text/markdown",
     url="http://docs.graph-it.com/graphit/controlpi",
-    packages=["controlpi", "controlpi.plugins"],
+    packages=["controlpi", "controlpi-plugins"],
     package_data={"controlpi": ["py.typed"]},
     zip_safe=False,
     extras_require={