Generate a list of all available plugin modules, either in the dshell.plugins directory or external packages
()
| 15 | |
| 16 | |
| 17 | def get_plugins(): |
| 18 | """ |
| 19 | Generate a list of all available plugin modules, either in the |
| 20 | dshell.plugins directory or external packages |
| 21 | """ |
| 22 | plugins = {} |
| 23 | # List of directories above the plugins directory that we don't care about |
| 24 | import_base = get_plugin_path().split(os.path.sep)[:-1] |
| 25 | |
| 26 | # Walk through the plugin path and find any Python modules that aren't |
| 27 | # __init__.py. These are assumed to be plugin modules and will be |
| 28 | # treated as such. |
| 29 | for root, dirs, files in os.walk(get_plugin_path()): |
| 30 | if '__init__.py' in files: |
| 31 | import_path = root.split(os.path.sep)[len(import_base):] |
| 32 | for f in iglob("{}/*.py".format(root)): |
| 33 | name = os.path.splitext(os.path.basename(f))[0] |
| 34 | if name != '__init__': |
| 35 | if name in plugins and logger: |
| 36 | logger.warning("Duplicate plugin name found: {}".format(name)) |
| 37 | module = '.'.join(["dshell"] + import_path + [name]) |
| 38 | plugins[name] = module |
| 39 | |
| 40 | # Next, try to discover additional plugins installed externally. |
| 41 | # Uses entry points in setup.py files. |
| 42 | for ep_plugin in pkg_resources.iter_entry_points("dshell_plugins"): |
| 43 | if ep_plugin.name in plugins: |
| 44 | logger.warning("Duplicate plugin name found: {}".format(ep_plugin.name)) |
| 45 | plugins[ep_plugin.name] = ep_plugin.module_name |
| 46 | |
| 47 | return plugins |
| 48 | |
| 49 | |
| 50 | def get_output_modules(output_module_path): |
no test coverage detected