INNER CODE UNIT · Python

load_app_from_module

KLR-Pattern/fastapi-voyager · src/fastapi_voyager/cli.py:57

def load_app_from_module(module_name: str, app_name: str = "app", framework: str | None = None) -> Any:
    """Load web framework app from a Python module name."""
    try:
        # Temporarily add the current working directory to sys.path
        current_dir = os.getcwd()
        if current_dir not in sys.path:
            sys.path.insert(0, current_dir)
            path_added = True
        else:
            path_added = False

        try:
            # Import the module by name
            module = importlib.import_module(module_name)

            # Get the app instance
            if not hasattr(module, app_name):
                logger.error(f"No attribute '{app_name}' found in module '{module_name}'")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…