diff --git a/PLUGINS.md b/PLUGINS.md index 46f55230..5e10a76b 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -160,6 +160,12 @@ You can display an error in EDMC's status area by returning a string from your ` The status area is shared between EDMC itself and all other plugins, so your message won't be displayed for very long. Create a dedicated widget if you need to display routine status information. +# Python Package Plugins + +A _Package Plugin_ is both a standard Python package (i.e. contains an `__init__.py` file) and an EDMC plugin (i.e. contains a `load.py` file providing at minimum a `plugin_start()` function). These plugins are loaded before any non-Package plugins. + +Other plugins can access features in a Package Plugin by `import`ing the package by name in the usual way. + # Distributing a Plugin To package your plugin for distribution simply create a `.zip` archive of your plugin's folder: diff --git a/plug.py b/plug.py index c50940d9..91784026 100644 --- a/plug.py +++ b/plug.py @@ -162,8 +162,13 @@ def load_plugins(master): print_exc() PLUGINS.extend(sorted(internal, key = lambda p: operator.attrgetter('name')(p).lower())) + # Add plugin folder to load path so packages can be loaded from plugin folder + sys.path.append(config.plugin_dir) + found = [] - for name in os.listdir(config.plugin_dir): + # Load any plugins that are also packages first + for name in sorted(os.listdir(config.plugin_dir), + key = lambda n: (not os.path.isfile(os.path.join(config.plugin_dir, n, '__init__.py')), n.lower())): if name[0] in ['.', '_']: pass elif name.endswith('.disabled'): @@ -171,7 +176,7 @@ def load_plugins(master): found.append(Plugin(name, None)) else: try: - # Add plugin's folder to Python's load path in case plugin has dependencies. + # Add plugin's folder to load path in case plugin has internal package dependencies sys.path.append(os.path.join(config.plugin_dir, name)) found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py'))) except: