From f1e679c3fb26bf2a3264ef63b4b207412417521e Mon Sep 17 00:00:00 2001 From: Philipp Richter Date: Sun, 19 Feb 2023 22:42:55 +0000 Subject: Expose a 'decky_plugin' module to decky plugins (#353) * Expose a 'decky_plugin' module to decky plugins * expose decky user home path * support 'py_modules' python modules in plugins * allow for a '_migration' method in plugins to have an explicit file moving step * Expose the plugin python module as .pyi stub interface * Expose system and user python paths to plugins --- backend/plugin.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'backend/plugin.py') 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()) -- cgit v1.2.3