1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 16:27:13 +03:00

Load any plugins that are also packages first

Addresses #313
This commit is contained in:
Jonathan Harris 2018-04-26 18:53:29 +01:00
parent 6c254f4bcd
commit fa3cf23c09
2 changed files with 13 additions and 2 deletions

View File

@ -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. 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 # Distributing a Plugin
To package your plugin for distribution simply create a `.zip` archive of your plugin's folder: To package your plugin for distribution simply create a `.zip` archive of your plugin's folder:

View File

@ -162,8 +162,13 @@ def load_plugins(master):
print_exc() print_exc()
PLUGINS.extend(sorted(internal, key = lambda p: operator.attrgetter('name')(p).lower())) 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 = [] 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 ['.', '_']: if name[0] in ['.', '_']:
pass pass
elif name.endswith('.disabled'): elif name.endswith('.disabled'):
@ -171,7 +176,7 @@ def load_plugins(master):
found.append(Plugin(name, None)) found.append(Plugin(name, None))
else: else:
try: 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)) sys.path.append(os.path.join(config.plugin_dir, name))
found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py'))) found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py')))
except: except: