PyUtilib / pyutilib

A collection of general Python utilities, including logging and file IO, subprocess management, plugin systems, and workflow management.
BSD 3-Clause "New" or "Revised" License
34 stars 21 forks source link

load_services undocumented #37

Open nerdoc opened 6 years ago

nerdoc commented 6 years ago

I really had a hard time finding out how PluginGlobals.load_services() works - I didn't make it. Is there any kind of documentation besides the few lines in the [pdf](https://software.sandia.gov/trac/pyutilib/export/1831/pyutilib.component.doc/trunk/doc/plugin/pca.pdf]?

AFAIK, and after having worked myself through the code of the loader, you have to import a Loader class first which implements IPluginLoader before calling load_services(). So:

# plugin.py
class Test:
    implements(ITest)
    def test():
        print("test)
# main.py
class ITest(Interface)
    def test():
        pass

class Main:
    test_extension = ExtensionPoint(ITest)

    def __init__(self):    
        loader = ImportLoader()
        PluginGlobals.get_env().load_services(path="./plugins", auto_disable=False)

    # test it:
    for ep in self.test_extension:
        ep.test()