reload_dirs: search up from app_module for last directory containing __init__

This commit is contained in:
Masen Furer 2025-01-15 13:49:04 -08:00
parent dc34c9a4b4
commit 647277056f
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95
2 changed files with 13 additions and 5 deletions

View File

@ -773,9 +773,8 @@ class Config(Base):
Returns: Returns:
The module name. The module name.
""" """
if self.app_module and self.app_module.__file__: if self.app_module is not None:
module_file = Path(self.app_module.__file__) return self.app_module.__qualname__
return f"{module_file.parent.name}.{module_file.stem}"
return ".".join([self.app_name, self.app_name]) return ".".join([self.app_name, self.app_name])
def update_from_env(self) -> dict[str, Any]: def update_from_env(self) -> dict[str, Any]:

View File

@ -248,8 +248,17 @@ def get_reload_dirs() -> list[str]:
""" """
config = get_config() config = get_config()
reload_dirs = [config.app_name] reload_dirs = [config.app_name]
if app_module_path := config.app_module_path: if config.app_module is not None and config.app_module.__file__:
reload_dirs.append(str(Path(app_module_path).resolve().parent.parent)) 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 return reload_dirs