Add plugins' folders to sys.path

This commit is contained in:
Jonathan Harris committed 2017-06-24 00:41:40 +01:00
1 parent da2e24f8a0
commit 5797af8861
2 files changed
+8 -16

No files matched your search

+1 -13
View File
@@ -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
+7 -3
View File
@@ -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()