module framework
Project description
modulepy
easily build modular applications
installation
pip3 install modulepy
# or
pip3 install git+https://github.com/nbdy/modulepy
features
- process based module baseline
- module loader
- one-line module loading
- one-line directory loading
- module manager
- add module
- remove module
- reload module directory
- module dependency resolution
- ipc
- module fault detection
example
main.py
from time import sleep
from modulepy.Manager import Manager
from pathlib import Path
if __name__ == '__main__':
manager = Manager(Path.cwd() / "modules")
try:
manager.start()
while manager.data.get("do_run"):
sleep(0.1)
except KeyboardInterrupt:
manager.stop()
manager.join()
modules/GPS.py
from typing import Optional
from gps import gps, WATCH_ENABLE
from modulepy import log
from modulepy.Base import Base, Information, Version
class GPS(Base):
information = Information("GPS", Version(1, 0, 0))
client: Optional[gps] = None
def on_start(self):
log.debug("Creating GPS client")
try:
self.client = gps(mode=WATCH_ENABLE)
log.debug("Created client")
self.data.set("error", None)
except ConnectionRefusedError:
self.data.set("error", "ConnectionRefusedError")
log.error("Could not create client")
pass
def on_stop(self):
log.debug("Closing GPS client")
if self.client:
self.client.close()
def work(self):
if self.client:
self.client.next()
self.data.set("latitude", self.client.fix.latitude)
self.data.set("longitude", self.client.fix.longitude)
self.data.set("altitude", self.client.fix.altitude)
self.data.set("speed", self.client.fix.speed)
self.data.set("track", self.client.fix.track)
self.data.set("satellites", self.client.satellites)
self.data.set("timestamp", self.client.utc)
modules/UI.py
from modulepy.Base import Base, Information, Version
from modulepy import log
from pyray import *
class UI(Base):
information = Information("TestUI", Version(1, 0, 0))
dependencies = [Information("Manager", Version(1, 0, 0)), Information("GPS", Version(1, 0, 0))]
def on_start(self):
log.debug("Initializing window")
init_window(800, 600, "TestUI")
set_target_fps(30)
self.data.text = "init text"
def on_stop(self):
log.debug("Closing window")
close_window()
def work(self):
error = self.clients["GPS"].get("error")
if error is None:
error = "None"
begin_drawing()
clear_background(BLACK)
draw_text(error, 100, 100, 24, GREEN)
if not error:
draw_text("Client is not connected", 100, 120, 18, RED)
else:
draw_text("Connected client", 100, 120, 18, GREEN)
end_drawing()
tmp = window_should_close()
self.data.set("do_run", not tmp)
if tmp:
print("Setting manager do_run to false")
self.clients["Manager"].set("do_run", False)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
modulepy-0.18.tar.gz
(6.0 kB
view details)
File details
Details for the file modulepy-0.18.tar.gz
.
File metadata
- Download URL: modulepy-0.18.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f84685abf897c7b543d391c1e83bfde74c9bbe03cfa9e2c6ce73ac392555e69 |
|
MD5 | c2013696bd77662bb04a9e3c7589b2ee |
|
BLAKE2b-256 | dbcadd948dd29c8ad834fa12aa5733b709799e1c216f4d1993db853cdb0df04f |