Index: pluginconf/bind.py ================================================================== --- pluginconf/bind.py +++ pluginconf/bind.py @@ -1,17 +1,17 @@ # encoding: utf-8 # api: pluginconf ##type: loader # title: plugin loader # description: implements a trivial unified namespace importer -# version: 0.1 +# version: 0.2 # state: alpha # priority: optional # # Most basic plugin management/loader. It unifies meta data retrieval # and instantiation. It still doesn't dictate a plugin API or config -# storage (using json in examples). And can be a simpler setup: +# storage (using json in examples), but some simple structuring: # # Create an empty plugins/__init__.py to use as package and for # plugin discovery. # # Designate it as such: @@ -23,11 +23,13 @@ # or updating it from a stored config file: # # conf = { # "first_run": 1, # "debug": 0, -# "plugins": {}, +# "plugins": { +# "mainwindow": True, +# }, # } # conf.update( # json.load(open("app.json", "r")) # ) # @@ -82,27 +84,25 @@ # automatic settings+update storage, btw. # #-- bit briefer for API docs -- """ -Basic plugin loader implementation for flat namespaces. Ties together -pluginconf lookups and config management for plugin loading in apps. -It's rather basic, and subject to change. Does impose a config dict -format, but no storage still. +Basic plugin loader implementation. Plugins are assumed to reside +in a flat namespace (main difference to module imports). This ties +together pluginconf lookups and config management for plugin loading +in apps. It's rather basic, and subject to change. Does impose a +config dict format, but no storage still. ### Usage example # designate a plugins/*.py package as plugin_base import plugins import pluginconf.bind - pluginconf.bind.base(plugins) + pluginconf.bind.base(__package__) # or "plugins" etc. # preset core app settings / load from json, add plugin options - conf = { - "plugins": { - } - } + conf = {} pluginconf.bind.defaults(conf) # load conf-enabled plugins, and register modules somehow for mod in pluginconf.bind.load_enabled(conf): mod.init() @@ -237,10 +237,12 @@ | Parameters | | | |-------------|-----------|-------------------------------------------| | conf | dict 🔁 | Expands the conf dict with preset values from any plugins. | | **Returns** | None | - | """ + if not "plugins" in conf: + conf["plugins"] = dict() for name, pmd in pluginconf.all_plugin_meta().items(): pluginconf.add_plugin_defaults(conf, conf["plugins"], pmd, name) # pylint: disable=invalid-name @@ -295,11 +297,11 @@ conf = {"plugins": {}} defaults(conf) return conf -def _enable_cache(state=True): +def cache(state=True): """ Reduce plugin_meta() lookup costs, suitable for repeat find() calls """ if hasattr(pluginconf.plugin_meta, "__wrapped__"): if state: