Hello World
What better way to demonstrate how this works than with a simple hello world?
In [3]:
Copied!
from spf.PluginMount import PluginMount
from abc import abstractmethod
from spf.PluginMount import PluginMount
from abc import abstractmethod
In [4]:
Copied!
class HelloMountPoint(metaclass=PluginMount):
entry_point = "hello_world"
@property
@abstractmethod
def hello(self) -> str:
pass
class HelloMountPoint(metaclass=PluginMount):
entry_point = "hello_world"
@property
@abstractmethod
def hello(self) -> str:
pass
In [5]:
Copied!
class HelloWorldPlugin(HelloMountPoint):
@property
def hello(self) -> str:
return "Hello, world."
class HelloWorldPlugin(HelloMountPoint):
@property
def hello(self) -> str:
return "Hello, world."
In [6]:
Copied!
class HelloUniversePlugin(HelloMountPoint):
@property
def hello(self) -> str:
return "Hello, universe."
class HelloUniversePlugin(HelloMountPoint):
@property
def hello(self) -> str:
return "Hello, universe."
In [7]:
Copied!
HelloMountPoint.plugins
HelloMountPoint.plugins
Out[7]:
{'HelloWorldPlugin': __main__.HelloWorldPlugin, 'HelloUniversePlugin': __main__.HelloUniversePlugin}
In [11]:
Copied!
plugins = HelloMountPoint.plugins
for name, plugin in plugins.items():
print(plugin().hello)
plugins = HelloMountPoint.plugins
for name, plugin in plugins.items():
print(plugin().hello)
Hello, world. Hello, universe.
In [ ]:
Copied!