From 647277056f439c44b4968e744d3db07d22f60660 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 15 Jan 2025 13:49:04 -0800 Subject: [PATCH] reload_dirs: search up from app_module for last directory containing __init__ --- reflex/config.py | 5 ++--- reflex/utils/exec.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/reflex/config.py b/reflex/config.py index 65188f8da..c337f3044 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -773,9 +773,8 @@ class Config(Base): Returns: The module name. """ - if self.app_module and self.app_module.__file__: - module_file = Path(self.app_module.__file__) - return f"{module_file.parent.name}.{module_file.stem}" + if self.app_module is not None: + return self.app_module.__qualname__ return ".".join([self.app_name, self.app_name]) def update_from_env(self) -> dict[str, Any]: diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index 22de8b948..6087818d9 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -248,8 +248,17 @@ def get_reload_dirs() -> list[str]: """ config = get_config() reload_dirs = [config.app_name] - if app_module_path := config.app_module_path: - reload_dirs.append(str(Path(app_module_path).resolve().parent.parent)) + if config.app_module is not None and config.app_module.__file__: + module_path = Path(config.app_module.__file__).resolve().parent + while module_path.parent.name: + for parent_file in module_path.parent.iterdir(): + if parent_file == "__init__.py": + # go up a level to find dir without `__init__.py` + module_path = module_path.parent + break + else: + break + reload_dirs.append(str(module_path)) return reload_dirs