From 92f69ac4633ea2bc6dd46acfa89ca74a2421ee58 Mon Sep 17 00:00:00 2001 From: Kevin Turner <566360-keturn@users.noreply.gitlab.com> Date: Tue, 25 Mar 2025 09:13:57 -0700 Subject: [PATCH] fix: make source location discovery more robust The top-level `invokeai` package may have an obscured origin due to the way editible installs work, but it's much more likely that this module is from a specific file. --- invokeai/app/util/startup_utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/invokeai/app/util/startup_utils.py b/invokeai/app/util/startup_utils.py index bfed204ff5..a89c1c1dcb 100644 --- a/invokeai/app/util/startup_utils.py +++ b/invokeai/app/util/startup_utils.py @@ -34,9 +34,17 @@ def check_cudnn(logger: logging.Logger) -> None: ) +def invokeai_source_dir() -> Path: + # `invokeai.__file__` doesn't always work for editable installs + this_module_path = Path(__file__).resolve() + # https://youtrack.jetbrains.com/issue/PY-38382/Unresolved-reference-spec-but-this-is-standard-builtin + # noinspection PyUnresolvedReferences + depth = len(__spec__.parent.split(".")) + return this_module_path.parents[depth - 1] + + def enable_dev_reload(custom_nodes_path=None) -> None: """Enable hot reloading on python file changes during development.""" - import invokeai from invokeai.backend.util.logging import InvokeAILogger try: @@ -46,7 +54,7 @@ def enable_dev_reload(custom_nodes_path=None) -> None: 'Can\'t start `--dev_reload` because jurigged is not found; `pip install -e ".[dev]"` to include development dependencies.' ) from e else: - paths = [str(Path(invokeai.__file__).with_name("*.py"))] + paths = [str(invokeai_source_dir() / "*.py")] if custom_nodes_path: paths.append(str(custom_nodes_path / "*.py")) jurigged.watch(pattern=paths, logger=InvokeAILogger.get_logger(name="jurigged").info)