From 568e1e338ee8e020385a21eccce9167c0dce1844 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Fri, 8 Aug 2025 21:49:07 -0700 Subject: [PATCH] refactor: Improve compatibility shim for historical imports and enhance module loading --- src/thechart/main.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/thechart/main.py b/src/thechart/main.py index 0c88a1f..f9d2cdd 100644 --- a/src/thechart/main.py +++ b/src/thechart/main.py @@ -1,8 +1,38 @@ +from __future__ import annotations + """Package proxy to the development entry module. This makes `thechart.main` importable while keeping the app in `src/main.py`. """ -from __future__ import annotations +"""Compatibility shim for historical `from thechart import main` imports. -from src.main import * # noqa: F401,F403 +Delegates to the existing application entrypoint from common locations +without forcing a hard dependency on the src layout. +""" + +import importlib # noqa: E402 + +# Re-export run() and MedTrackerApp from the located main module +try: + _mod = importlib.import_module("src.main") +except Exception: + try: + _mod = importlib.import_module("main") + except Exception: # Fallback to package dispatcher + from .__main__ import main as _entry_main # type: ignore + + def run() -> None: # noqa: D401 + """Run the application.""" + + _entry_main() + + __all__ = ["run"] + else: + from main import * # type: ignore # noqa: F401,F403 + + __all__ = [name for name in dir() if not name.startswith("_")] +else: + from src.main import * # type: ignore # noqa: F401,F403 + + __all__ = [name for name in dir() if not name.startswith("_")]