Index: pluginconf/__init__.py ================================================================== --- pluginconf/__init__.py +++ pluginconf/__init__.py @@ -2,21 +2,24 @@ # api: python ##type: extract # category: config # title: Plugin configuration # description: Read meta data, pyz/package contents, module locating -# version: 0.7.8 +# version: 0.7.9 # state: stable # classifiers: documentation +# depends: python:pluginconf (>=0.5, <1.0), python >= 2.7 +# suggests: python:flit, python:PySimpleGUI # license: PD # priority: core +# api-docs: https://fossil.include-once.org/pluginspec/doc/trunk/html/index.html # docs: https://fossil.include-once.org/pluginspec/ # url: http://fossil.include-once.org/streamtuner2/wiki/plugin+meta+data # config: - # format: off # pylint: disable=invalid-name -# console-scripts: flit-pluginconf=pluginconf.flit:main +# console-scripts: flit-pluginconf=pluginconf.flit:main, pluginconf.flit=pluginconf.flit:main # # Provides plugin lookup and meta data extraction utility functions. # It's used to abstract module+option management in applications. # For consolidating internal use and external/tool accessibility. # @@ -67,17 +70,17 @@ # That is: module scripts in a package like `ext.plg1` and `ext.plg2`. # It can be initialized by injecting the plugin-package basename into # plugin_base = []. The associated paths will be used for module # lookup via pkgutil.iter_modules(). # -# And a central module can be extended with new lookup locations best -# by attaching new locations itself via module.__path__ + ["./local"] -# for example. +# Ideally a designated reference base_module should be extended with +# new lookup locations via `module.__path__ += ["./local"]` for exmple. +# Plugin loading thus becomes as simple as __import__("ext.local"). # -# Plugin loading thus becomes as simple as __import__("ext.local"). -# The attached plugin_state config dictionary in most cases can just -# list module basenames, if there's only one set to manage. +# Using a plugin_state config dictionary in most cases can just list +# module basenames, if there's only one namespace to manage. (Plugin +# names unique across project.) """ Plugin meta extraction and module lookup""" import sys @@ -353,11 +356,25 @@ # Turn key:value lines into dictionary for field in rx.keyval.findall(src): meta[field[0].replace("-", "_")] = field[1].strip() meta["config"] = plugin_meta_config(meta.get("config") or "") - return meta + return PluginMeta(meta) + + +# Dict wrapper +# ‾‾‾‾‾‾‾‾‾‾‾‾ +class PluginMeta(dict): + """ Plugin meta data, convenience dict with property access """ + + def __getattr__(self, key): + """ Return [key] for .property access, else None """ + return self.get(key) + + def __hasattr__(self, key): + """ Return [key] for .property access, else None """ + return key in self # Unpack config: structures # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ def plugin_meta_config(src):