INNER CODE UNIT · Python
load_app_from_file
KLR-Pattern/fastapi-voyager · src/fastapi_voyager/cli.py:20
def load_app_from_file(module_path: str, app_name: str = "app", framework: str | None = None) -> Any:
"""Load web framework app from a Python module file."""
try:
# Convert relative path to absolute path
if not os.path.isabs(module_path):
module_path = os.path.abspath(module_path)
# Load the module
spec = importlib.util.spec_from_file_location("app_module", module_path)
if spec is None or spec.loader is None:
logger.error(f"Could not load module from {module_path}")
return None
module = importlib.util.module_from_spec(spec)
sys.modules["app_module"] = module
spec.loader.exec_module(module)
# Get the app instance