From d8687b6d1b15543ba09a628e634e2e1f41525f05 Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:12:36 +0100 Subject: [PATCH] Use 'resolve' instead of 'absolute' for obtaining absolute paths; gui.py GUI debug now redirects SELF_PATH to main.py as well --- build.spec | 2 +- constants.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build.spec b/build.spec index 4ff7224..3b54c24 100644 --- a/build.spec +++ b/build.spec @@ -5,7 +5,7 @@ import sys from pathlib import Path from typing import Any, TYPE_CHECKING -SELF_PATH = str(Path(".").absolute()) +SELF_PATH = str(Path(".").resolve()) if SELF_PATH not in sys.path: sys.path.insert(0, SELF_PATH) diff --git a/constants.py b/constants.py index 7e713ac..def4510 100644 --- a/constants.py +++ b/constants.py @@ -42,7 +42,7 @@ def _resource_path(relative_path: Path | str) -> Path: Works for dev and for PyInstaller. """ if IS_APPIMAGE: - base_path = Path(sys.argv[0]).absolute().parent + base_path = Path(sys.argv[0]).resolve().parent elif IS_PACKAGED: # PyInstaller's folder where the one-file app is unpacked meipass: str = getattr(sys, "_MEIPASS") @@ -78,13 +78,14 @@ def _merge_vars(base_vars: JsonType, vars: JsonType) -> None: # Base Paths if IS_APPIMAGE: - SELF_PATH = Path(os.environ["APPIMAGE"]).absolute() + SELF_PATH = Path(os.environ["APPIMAGE"]).resolve() else: - # NOTE: pyinstaller will set sys.argv[0] to its own executable when building, - # detect this to use __file__ and main.py redirection instead - SELF_PATH = Path(sys.argv[0]).absolute() - if SELF_PATH.stem == "pyinstaller": - SELF_PATH = Path(__file__).with_name("main.py").absolute() + # NOTE: pyinstaller will set sys.argv[0] to its own executable when building + # NOTE: sys.argv[0] will point to gui.py when running the gui.py directly for GUI debug + # detect these and use __file__ and main.py redirection instead + SELF_PATH = Path(sys.argv[0]).resolve() + if SELF_PATH.stem == "pyinstaller" or SELF_PATH.name == "gui.py": + SELF_PATH = Path(__file__).with_name("main.py").resolve() WORKING_DIR = SELF_PATH.parent # Development paths VENV_PATH = Path(WORKING_DIR, "env")