summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/helpers.py14
-rw-r--r--backend/plugin.py11
2 files changed, 22 insertions, 3 deletions
diff --git a/backend/helpers.py b/backend/helpers.py
index 7cab512b..35681f68 100644
--- a/backend/helpers.py
+++ b/backend/helpers.py
@@ -115,8 +115,18 @@ def mkdir_as_user(path):
# Fetches the version of loader
def get_loader_version() -> str:
- with open(os.path.join(os.path.dirname(sys.argv[0]), ".loader.version"), "r", encoding="utf-8") as version_file:
- return version_file.readline().replace("\n", "")
+ try:
+ with open(os.path.join(os.path.dirname(sys.argv[0]), ".loader.version"), "r", encoding="utf-8") as version_file:
+ return version_file.readline().replace("\n", "")
+ except:
+ return ""
+
+# returns the appropriate system python paths
+def get_system_pythonpaths() -> list[str]:
+ # run as normal normal user to also include user python paths
+ proc = subprocess.run(["python3", "-c", "import sys; print(':'.join(x for x in sys.path if x))"],
+ user=get_user_id(), env={}, capture_output=True)
+ return proc.stdout.decode().strip().split(":")
# Download Remote Binaries to local Plugin
async def download_remote_binary_to_path(url, binHash, path) -> bool:
diff --git a/backend/plugin.py b/backend/plugin.py
index efaeb322..dea35299 100644
--- a/backend/plugin.py
+++ b/backend/plugin.py
@@ -9,7 +9,7 @@ from logging import getLogger
from traceback import format_exc
from os import path, setgid, setuid, environ
from signal import SIGINT, signal
-from sys import exit
+from sys import exit, path as syspath
from time import time
import helpers
from updater import Updater
@@ -66,6 +66,7 @@ class PluginWrapper:
environ["USER"] = "root" if "root" in self.flags else helpers.get_user()
environ["DECKY_VERSION"] = helpers.get_loader_version()
environ["DECKY_USER"] = helpers.get_user()
+ environ["DECKY_USER_HOME"] = helpers.get_home_path()
environ["DECKY_HOME"] = helpers.get_homebrew_path()
environ["DECKY_PLUGIN_SETTINGS_DIR"] = path.join(environ["DECKY_HOME"], "settings", self.plugin_directory)
helpers.mkdir_as_user(environ["DECKY_PLUGIN_SETTINGS_DIR"])
@@ -77,11 +78,19 @@ class PluginWrapper:
environ["DECKY_PLUGIN_NAME"] = self.name
environ["DECKY_PLUGIN_VERSION"] = self.version
environ["DECKY_PLUGIN_AUTHOR"] = self.author
+ # append the loader's plugin path to the recognized python paths
+ syspath.append(path.realpath(path.join(path.dirname(__file__), "plugin")))
+ # append the plugin's `py_modules` to the recognized python paths
+ syspath.append(path.join(environ["DECKY_PLUGIN_DIR"], "py_modules"))
+ # append the system and user python paths
+ syspath.extend(helpers.get_system_pythonpaths())
spec = spec_from_file_location("_", self.file)
module = module_from_spec(spec)
spec.loader.exec_module(module)
self.Plugin = module.Plugin
+ if hasattr(self.Plugin, "_migration"):
+ get_event_loop().run_until_complete(self.Plugin._migration(self.Plugin))
if hasattr(self.Plugin, "_main"):
get_event_loop().create_task(self.Plugin._main(self.Plugin))
get_event_loop().create_task(self._setup_socket())