Fix misuse of pyinstaller

This commit is contained in:
suchmememanyskill
2024-07-14 11:45:52 +02:00
parent dc9f89afad
commit fae0bb3a6f
3 changed files with 16 additions and 13 deletions
+5 -1
View File
@@ -90,7 +90,11 @@ def get_system_pythonpaths() -> list[str]:
proc = subprocess.run(["python3" if localplatform.ON_LINUX else "python", "-c", "import sys; print('\\n'.join(x for x in sys.path if x))"], proc = subprocess.run(["python3" if localplatform.ON_LINUX else "python", "-c", "import sys; print('\\n'.join(x for x in sys.path if x))"],
# TODO make this less insane # TODO make this less insane
capture_output=True, user=localplatform.localplatform._get_user_id() if localplatform.ON_LINUX else None, env={} if localplatform.ON_LINUX else None) # pyright: ignore [reportPrivateUsage] capture_output=True, user=localplatform.localplatform._get_user_id() if localplatform.ON_LINUX else None, env={} if localplatform.ON_LINUX else None) # pyright: ignore [reportPrivateUsage]
return [x.strip() for x in proc.stdout.decode().strip().split("\n")]
proc.check_returncode()
versions = [x.strip() for x in proc.stdout.decode().strip().split("\n")]
return [x for x in versions if x and not x.isspace()]
except Exception as e: except Exception as e:
logger.warn(f"Failed to execute get_system_pythonpaths(): {str(e)}") logger.warn(f"Failed to execute get_system_pythonpaths(): {str(e)}")
return [] return []
+4 -5
View File
@@ -7,14 +7,16 @@ from .localplatform.localplatform import (chmod, chown, service_stop, service_st
get_privileged_path, restart_webhelper) get_privileged_path, restart_webhelper)
if hasattr(sys, '_MEIPASS'): if hasattr(sys, '_MEIPASS'):
chmod(sys._MEIPASS, 755) # type: ignore chmod(sys._MEIPASS, 755) # type: ignore
# Full imports # Full imports
import multiprocessing
multiprocessing.freeze_support()
from asyncio import AbstractEventLoop, CancelledError, Task, all_tasks, current_task, gather, new_event_loop, set_event_loop, sleep from asyncio import AbstractEventLoop, CancelledError, Task, all_tasks, current_task, gather, new_event_loop, set_event_loop, sleep
from logging import basicConfig, getLogger from logging import basicConfig, getLogger
from os import path from os import path
from traceback import format_exc from traceback import format_exc
import multiprocessing
import aiohttp_cors # pyright: ignore [reportMissingTypeStubs] import aiohttp_cors # pyright: ignore [reportMissingTypeStubs]
# Partial imports # Partial imports
from aiohttp import client_exceptions from aiohttp import client_exceptions
from aiohttp.web import Application, Response, Request, get, run_app, static # pyright: ignore [reportUnknownVariableType] from aiohttp.web import Application, Response, Request, get, run_app, static # pyright: ignore [reportUnknownVariableType]
@@ -223,9 +225,6 @@ def main():
# Fix windows/flask not recognising that .js means 'application/javascript' # Fix windows/flask not recognising that .js means 'application/javascript'
import mimetypes import mimetypes
mimetypes.add_type('application/javascript', '.js') mimetypes.add_type('application/javascript', '.js')
# Required for multiprocessing support in frozen files
multiprocessing.freeze_support()
else: else:
if get_effective_user_id() != 0: if get_effective_user_id() != 0:
logger.warning(f"decky is running as an unprivileged user, this is not officially supported and may cause issues") logger.warning(f"decky is running as an unprivileged user, this is not officially supported and may cause issues")
@@ -1,9 +1,9 @@
import sys
from os import path, environ from os import path, environ
from signal import SIG_IGN, SIGINT, SIGTERM, getsignal, signal from signal import SIG_IGN, SIGINT, SIGTERM, getsignal, signal
from importlib.util import module_from_spec, spec_from_file_location from importlib.util import module_from_spec, spec_from_file_location
from json import dumps, loads from json import dumps, loads
from logging import getLogger from logging import getLogger
from sys import exit, path as syspath, modules as sysmodules
from traceback import format_exc from traceback import format_exc
from asyncio import (get_event_loop, new_event_loop, from asyncio import (get_event_loop, new_event_loop,
set_event_loop) set_event_loop)
@@ -78,12 +78,12 @@ class SandboxedPlugin:
environ["DECKY_PLUGIN_AUTHOR"] = self.author environ["DECKY_PLUGIN_AUTHOR"] = self.author
# append the plugin's `py_modules` to the recognized python paths # append the plugin's `py_modules` to the recognized python paths
syspath.append(path.join(environ["DECKY_PLUGIN_DIR"], "py_modules")) sys.path.append(path.join(environ["DECKY_PLUGIN_DIR"], "py_modules"))
#TODO: FIX IN A LESS CURSED WAY #TODO: FIX IN A LESS CURSED WAY
keys = [key for key in sysmodules if key.startswith("decky_loader.")] keys = [key for key in sys.modules if key.startswith("decky_loader.")]
for key in keys: for key in keys:
sysmodules[key.replace("decky_loader.", "")] = sysmodules[key] sys.modules[key.replace("decky_loader.", "")] = sys.modules[key]
from .imports import decky from .imports import decky
async def emit(event: str, *args: Any) -> None: async def emit(event: str, *args: Any) -> None:
@@ -95,9 +95,9 @@ class SandboxedPlugin:
# copy the docstring over so we don't have to duplicate it # copy the docstring over so we don't have to duplicate it
emit.__doc__ = decky.emit.__doc__ emit.__doc__ = decky.emit.__doc__
decky.emit = emit decky.emit = emit
sysmodules["decky"] = decky sys.modules["decky"] = decky
# provided for compatibility # provided for compatibility
sysmodules["decky_plugin"] = decky sys.modules["decky_plugin"] = decky
spec = spec_from_file_location("_", self.file) spec = spec_from_file_location("_", self.file)
assert spec is not None assert spec is not None
@@ -180,7 +180,7 @@ class SandboxedPlugin:
loop = get_event_loop() loop = get_event_loop()
loop.call_soon_threadsafe(loop.stop) loop.call_soon_threadsafe(loop.stop)
exit(0) sys.exit(0)
d: SocketResponseDict = {"type": SocketMessageType.RESPONSE, "res": None, "success": True, "id": data["id"]} d: SocketResponseDict = {"type": SocketMessageType.RESPONSE, "res": None, "success": True, "id": data["id"]}
try: try: