mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 00:07:14 +03:00
Add plugins' folders to sys.path
This commit is contained in:
parent
da2e24f8a0
commit
5797af8861
14
PLUGINS.md
14
PLUGINS.md
@ -143,19 +143,7 @@ To package your plugin for distribution simply create a `.zip` archive of your p
|
||||
* Windows: In Explorer right click on your plugin's folder and choose Send to → Compressed (zipped) folder.
|
||||
* Mac: In Finder right click on your plugin's folder and choose Compress.
|
||||
|
||||
If there are any external dependencies then bundle them within the plugin's folder and add the plugin's folder to Python's load path.
|
||||
|
||||
```python
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add plugin's folder to Python's load path.
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__)))
|
||||
|
||||
# Assumes the dependency has been bundled in the plugin's folder.
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
```
|
||||
If there are any external dependencies then include them in the plugin's folder.
|
||||
|
||||
# Disable a plugin
|
||||
|
||||
|
10
plug.py
10
plug.py
@ -45,11 +45,15 @@ def load_plugins():
|
||||
for plugname in disabled:
|
||||
sys.stdout.write("plugin {} disabled\n".format(plugname))
|
||||
|
||||
for plugname in found:
|
||||
for plugname, loadfile in found.iteritems():
|
||||
try:
|
||||
sys.stdout.write("loading plugin {}\n".format(plugname))
|
||||
with open(found[plugname], "rb") as plugfile:
|
||||
plugmod = imp.load_module(plugname, plugfile, found[plugname].encode(sys.getfilesystemencoding()),
|
||||
|
||||
# Add plugin's folder to Python's load path in case plugin has dependencies.
|
||||
sys.path.append(os.path.dirname(loadfile))
|
||||
|
||||
with open(loadfile, "rb") as plugfile:
|
||||
plugmod = imp.load_module(plugname, plugfile, loadfile.encode(sys.getfilesystemencoding()),
|
||||
(".py", "r", imp.PY_SOURCE))
|
||||
if hasattr(plugmod, "plugin_start"):
|
||||
newname = plugmod.plugin_start()
|
||||
|
Loading…
x
Reference in New Issue
Block a user