Skip to main content

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)

Metadata

Release files for modulepy 0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modulepy 0.18
File Size Uploaded
modulepy-0.18.tar.gz 6.0 kB Details

Release files / modulepy-0.18.tar.gz

Download URL modulepy-0.18.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7f84685abf897c7b543d391c1e83bfde74c9bbe03cfa9e2c6ce73ac392555e69
BLAKE2b-256 checksum
How to use checksums
dbcadd948dd29c8ad834fa12aa5733b709799e1c216f4d1993db853cdb0df04f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.18 This release

1 release file

0.17

1 release file

0.16

1 release file

0.15

1 release file

0.14

1 release file

0.13

1 release file

0.11

1 release file

0.10

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.4

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page