Skip to main content

Open source plugin system.

Project description

OpenPS

Open source plugin system.

Install

Windows

pip install OpenPS

Linux

pip3 install OpenPS

Built-in events

IMPORTANT: These events will not called automatically. You need to define when need to call.

  • OnProgramStart
  • OnProgramExit
  • OnProgramInit

How to use

If you have a project and want to add a plugin system then you just need to follow these instructions. First you need to make the project folder.

.
├── main_program.py
└── plugins
    └── hello.py

You need to add a plugin.py file.

.
├── main_program.py
├── plugin.py
└── plugins
    └── hello.py

Write the following code to the plugin.py

# plugin.py
import OpenPS

event = OpenPS.Event("./plugins/")

call = lambda name: event.call(name)
register = lambda name: event.register(name)

event.init()

If you want to add your own events then add this line in the code above the event.init() line.

# plugin.py
import OpenPS

event = OpenPS.Event("./plugins/")

call = lambda name: event.call(name)
register = lambda name: event.register(name)

event.create("OnProgramFoo") # Create event.

event.init()
# main_program.py
import plugin

def main():
  plugin.call("OnProgramFoo")
  print("hello world!")

main()
# /plugins/hello.py
import plugin

@plugin.register("OnProgramFoo")
def function():
  print("hello from the plugin!")

When you run the main_program.py the output should be looks like this

hello from the plugin!
hello world!

Adding custom plugin load order

The default loading order is None. That means loads in alphabetical order.

If you want to add your own order then make a new function in the plugin.py. The function required minimum 1 parameter. The return value must be a list otherwise will not working.

# plugin.py
import OpenPS

def reverse(lst) -> list:
  lst.sort(reverse=True)
  return lst

event = OpenPS.Event("./plugins/", reverse)

call = lambda name: event.call(name)
register = lambda name: event.register(name)

event.init()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

OpenPS-1.2.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

OpenPS-1.2.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file OpenPS-1.2.0.tar.gz.

File metadata

  • Download URL: OpenPS-1.2.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

File hashes

Hashes for OpenPS-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a26838a62de738e2c9759eb5c68ce7852212f32180b1631a9af05ef46cdfe3c0
MD5 ae1e48e66a211d7e0f97e1b3a33760e6
BLAKE2b-256 fdb4fab38645143c910f699eb972e54411612962cc081a3e35949a38842a8959

See more details on using hashes here.

File details

Details for the file OpenPS-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: OpenPS-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

File hashes

Hashes for OpenPS-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce24482524e57dc55097ab8962f765f21790a3d2302c1a1582c892cc04d89211
MD5 e12e971c16352ba48aad6ddbce39da31
BLAKE2b-256 acc9b4be9dc3f1c87f2df6249d0d7dbe5ac86f080121e105569ea3889c9278ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page