generated from Lerking/python-module-repo-template
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
e74b780017 | |||
59fc0ef000 | |||
64f5e4207e | |||
0b78012951 | |||
5d4e5809af |
@@ -3,7 +3,7 @@
|
|||||||
[](https://www.python.org/)
|
[](https://www.python.org/)
|
||||||
|
|
||||||
Coding time for this reposotory.</br>
|
Coding time for this reposotory.</br>
|
||||||
[](https://wakatime.com/badge/user/d43f2852-fd6f-45b4-b713-558ad18204d4/project/dcf411f9-6d3e-4b14-9290-5ed419cf4012)
|
[](https://wakatime.com/badge/user/d43f2852-fd6f-45b4-b713-558ad18204d4/project/4e75f1fd-6bb3-40d6-9b84-e69a9cc0317c)
|
||||||
|
|
||||||
See the wiki for usage and examples.
|
See the wiki for usage and examples.
|
||||||
[pluginlib wiki page](https://gitpot-lerking.servehttp.com/Lerking/pluginlib/wiki)
|
[pluginlib wiki page](https://gitpot-lerking.servehttp.com/Lerking/pluginlib/wiki)
|
||||||
|
6
makefile
6
makefile
@@ -1,6 +1,6 @@
|
|||||||
dist:
|
dist:
|
||||||
python3 setup.py sdist
|
python setup.py sdist
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cd dist
|
cd dist
|
||||||
python3 -m pip install tcxmodeler-0.0.4.tar.gz
|
python -m pip install pluginlib-0.0.1.tar.gz
|
@@ -0,0 +1,4 @@
|
|||||||
|
from . import pluginlib_init
|
||||||
|
from . import pluginlib_manager
|
||||||
|
from . import pluginlib_register
|
||||||
|
from . import pluginlib_relay
|
@@ -1,3 +1,3 @@
|
|||||||
[pluginlib]
|
[pluginlib]
|
||||||
build = 2
|
build = 6
|
||||||
|
|
||||||
|
2
src/pluginlib/pluginlib_init.py
Normal file
2
src/pluginlib/pluginlib_init.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import yaml
|
||||||
|
|
0
src/pluginlib/pluginlib_manager.py
Normal file
0
src/pluginlib/pluginlib_manager.py
Normal file
19
src/pluginlib/pluginlib_register.py
Normal file
19
src/pluginlib/pluginlib_register.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import importlib.metadata as importlib_metadata
|
||||||
|
|
||||||
|
def register_plugin(name, namespace, entry_point) -> None:
|
||||||
|
"""Registers a plugin dynamically without needing to install as a package.
|
||||||
|
Args:
|
||||||
|
name (str): Name of plugin to be referenced.
|
||||||
|
namespace (str): Name of plugin namespace.
|
||||||
|
entry_point (str): Entry point in the form: some.module:some.attr
|
||||||
|
"""
|
||||||
|
ep = importlib_metadata.EntryPoint(name, entry_point, namespace)
|
||||||
|
e = ExtensionManager(namespace)
|
||||||
|
if namespace in e.ENTRY_POINT_CACHE:
|
||||||
|
entry_points = e.ENTRY_POINT_CACHE.get(namespace)
|
||||||
|
if name not in [entry_point.name for entry_point in entry_points]:
|
||||||
|
entry_points.append(ep)
|
||||||
|
e.ENTRY_POINT_CACHE[namespace] = entry_points
|
||||||
|
else:
|
||||||
|
e.ENTRY_POINT_CACHE[namespace] = [ep]
|
||||||
|
ep.load()
|
24
src/pluginlib/pluginlib_relay.py
Normal file
24
src/pluginlib/pluginlib_relay.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class RelayBase(metaclass=ABCMeta):
|
||||||
|
"""Base class for relay plugins"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""Define base attributes."""
|
||||||
|
self.connected = False
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def disconnect(self) -> None:
|
||||||
|
"""Disconnects relay."""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def connect(self) -> None:
|
||||||
|
"""Connects relay."""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def reconnect(self, seconds: int) -> None:
|
||||||
|
"""Disconnects for specified time and reconnects.
|
||||||
|
Args:
|
||||||
|
seconds (int): Amount of time to sleep between disconnect and connect.
|
||||||
|
"""
|
Reference in New Issue
Block a user