From a8ad2754722e58853289da6c10378cddc7adc530 Mon Sep 17 00:00:00 2001 From: razinkele Date: Sun, 4 Jan 2026 22:12:57 +0200 Subject: [PATCH] fix(app): robust imports for both package and script execution contexts --- app/app.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/app.py b/app/app.py index f7dd2c9..1f1d179 100644 --- a/app/app.py +++ b/app/app.py @@ -24,13 +24,20 @@ sys.path.insert(0, str(root_dir)) # Import page modules - organized by category -# Core pages -from app.pages import home, data_import, ecopath, prebalance, ecosim, results, analysis, about -# Advanced features -from app.pages import multistanza, forcing_demo, diet_rewiring_demo, optimization_demo, ecospace - -# Configuration imports -from app.config import UI +# Try absolute imports first (normal when app is a package). +# Fall back to local imports when running app/app.py directly (e.g., 'uvicorn app.app:app' run from inside the app/ directory). +try: + # Core pages + from app.pages import home, data_import, ecopath, prebalance, ecosim, results, analysis, about + # Advanced features + from app.pages import multistanza, forcing_demo, diet_rewiring_demo, optimization_demo, ecospace + # Configuration imports + from app.config import UI +except ModuleNotFoundError: + # Fallback: import modules as top-level local modules (when script is executed from the app/ dir) + from pages import home, data_import, ecopath, prebalance, ecosim, results, analysis, about + from pages import multistanza, forcing_demo, diet_rewiring_demo, optimization_demo, ecospace + from config import UI # App UI with dashboard layout and Bootstrap theme app_ui = ui.page_navbar(