Initialize the application by discovering and registering modules. Raises: ImportError: If critical module import operations fail RuntimeError: If application initialization fails
()
| 186 | |
| 187 | |
| 188 | def init_app() -> None: |
| 189 | """Initialize the application by discovering and registering modules. |
| 190 | |
| 191 | Raises: |
| 192 | ImportError: If critical module import operations fail |
| 193 | RuntimeError: If application initialization fails |
| 194 | """ |
| 195 | logger = logging.getLogger(__name__) |
| 196 | failed_imports = [] |
| 197 | failed_registrations = [] |
| 198 | |
| 199 | try: |
| 200 | # Auto-discover and import all modules |
| 201 | modules_path = Path(cli.modules.__file__).parent |
| 202 | logger.debug(f"Discovering modules in {modules_path}") |
| 203 | failed_imports = _import_modules(modules_path, logger) |
| 204 | |
| 205 | # Register core repo command |
| 206 | repo_failures = _register_repo_command(logger) |
| 207 | |
| 208 | # Register template-based modules |
| 209 | module_classes, failed_registrations = _register_module_classes(logger) |
| 210 | failed_registrations.extend(repo_failures) |
| 211 | |
| 212 | # Validate we have modules |
| 213 | if not module_classes and not failed_imports: |
| 214 | raise RuntimeError("No modules found to register") |
| 215 | |
| 216 | # Log summary |
| 217 | successful_modules = len(module_classes) - len(failed_registrations) |
| 218 | logger.info(f"Application initialized: {successful_modules} modules registered successfully") |
| 219 | if failed_imports: |
| 220 | logger.info(f"Module import failures: {len(failed_imports)}") |
| 221 | if failed_registrations: |
| 222 | logger.info(f"Module registration failures: {len(failed_registrations)}") |
| 223 | |
| 224 | except Exception as e: |
| 225 | details = _build_error_details(failed_imports, failed_registrations) or str(e) |
| 226 | raise RuntimeError(f"Application initialization failed: {details}") from e |
| 227 | |
| 228 | |
| 229 | def run() -> None: |
no test coverage detected