|
1 | | -""" |
2 | | -CodeFlow Engine - Automated Code Review and Quality Management System |
3 | | -
|
4 | | -This package provides AI-powered code analysis, automated fixes, and quality assurance workflows. |
| 1 | +"""CodeFlow Engine public package API. |
5 | 2 |
|
6 | | -Main Components: |
7 | | -- CodeFlowEngine: Main orchestrator for all automation activities |
8 | | -- ActionRegistry: Registry for managing action plugins |
9 | | -- WorkflowEngine: Workflow execution engine |
10 | | -- LLMProviderManager: Multi-provider LLM abstraction |
11 | | -- MetricsCollector: Quality metrics collection |
| 3 | +The canonical package lives under ``engine/codeflow_engine`` in the monorepo. |
| 4 | +Keep this module lightweight so submodule imports such as |
| 5 | +``codeflow_engine.actions.analysis.ai_comment_analyzer`` do not eagerly import |
| 6 | +optional runtime dependencies during package initialization. |
12 | 7 | """ |
13 | 8 |
|
| 9 | +from __future__ import annotations |
| 10 | + |
| 11 | +import importlib |
14 | 12 | import logging |
15 | 13 | import os |
16 | | -from typing import Any, cast |
17 | | - |
18 | | -from codeflow_engine.actions.registry import ActionRegistry |
19 | | -from codeflow_engine.ai.core.base import LLMProvider |
20 | | -from codeflow_engine.ai.core.providers.manager import LLMProviderManager |
21 | | -from codeflow_engine.config import CodeFlowConfig |
22 | | -from codeflow_engine.engine import CodeFlowEngine |
23 | | -from codeflow_engine.exceptions import ( |
24 | | - ActionError, |
25 | | - AuthenticationError, |
26 | | - CodeFlowException, |
27 | | - CodeFlowPermissionError, |
28 | | - ConfigurationError, |
29 | | - IntegrationError, |
30 | | - LLMProviderError, |
31 | | - RateLimitError, |
32 | | - ValidationError, |
33 | | - WorkflowError, |
34 | | -) |
35 | | -from codeflow_engine.integrations.base import Integration |
36 | | -from codeflow_engine.quality.metrics_collector import MetricsCollector |
37 | | - |
38 | | -# Security - guarded import |
39 | | -EnterpriseAuthorizationManager: type[Any] | None = None |
40 | | -try: |
| 14 | +from typing import TYPE_CHECKING, Any, cast |
| 15 | + |
| 16 | +if TYPE_CHECKING: |
| 17 | + from codeflow_engine.actions.registry import ActionRegistry |
| 18 | + from codeflow_engine.ai.core.base import LLMProvider |
| 19 | + from codeflow_engine.ai.core.providers.manager import LLMProviderManager |
| 20 | + from codeflow_engine.config import CodeFlowConfig |
| 21 | + from codeflow_engine.engine import CodeFlowEngine |
| 22 | + from codeflow_engine.exceptions import ( |
| 23 | + ActionError, |
| 24 | + AuthenticationError, |
| 25 | + CodeFlowException, |
| 26 | + CodeFlowPermissionError, |
| 27 | + ConfigurationError, |
| 28 | + IntegrationError, |
| 29 | + LLMProviderError, |
| 30 | + RateLimitError, |
| 31 | + ValidationError, |
| 32 | + WorkflowError, |
| 33 | + ) |
| 34 | + from codeflow_engine.integrations.base import Integration |
| 35 | + from codeflow_engine.quality.metrics_collector import MetricsCollector |
41 | 36 | from codeflow_engine.security.authorization.enterprise_manager import ( |
42 | 37 | EnterpriseAuthorizationManager, |
43 | 38 | ) |
44 | | -except (ImportError, OSError): |
45 | | - pass |
46 | | - |
47 | | -from codeflow_engine.workflows.base import Workflow |
48 | | -from codeflow_engine.workflows.engine import WorkflowEngine |
| 39 | + from codeflow_engine.workflows.base import Workflow |
| 40 | + from codeflow_engine.workflows.engine import WorkflowEngine |
49 | 41 |
|
50 | 42 | # Import structlog with error handling |
51 | 43 | STRUCTLOG_AVAILABLE: bool |
|
60 | 52 |
|
61 | 53 | __version__ = "0.2.0-alpha.1" |
62 | 54 |
|
| 55 | +_LAZY_EXPORTS = { |
| 56 | + "CodeFlowEngine": "codeflow_engine.engine:CodeFlowEngine", |
| 57 | + "CodeFlowConfig": "codeflow_engine.config:CodeFlowConfig", |
| 58 | + "ActionRegistry": "codeflow_engine.actions.registry:ActionRegistry", |
| 59 | + "LLMProvider": "codeflow_engine.ai.core.base:LLMProvider", |
| 60 | + "LLMProviderManager": "codeflow_engine.ai.core.providers.manager:LLMProviderManager", |
| 61 | + "Integration": "codeflow_engine.integrations.base:Integration", |
| 62 | + "Workflow": "codeflow_engine.workflows.base:Workflow", |
| 63 | + "WorkflowEngine": "codeflow_engine.workflows.engine:WorkflowEngine", |
| 64 | + "MetricsCollector": "codeflow_engine.quality.metrics_collector:MetricsCollector", |
| 65 | + "EnterpriseAuthorizationManager": "codeflow_engine.security.authorization.enterprise_manager:EnterpriseAuthorizationManager", |
| 66 | + "ActionError": "codeflow_engine.exceptions:ActionError", |
| 67 | + "AuthenticationError": "codeflow_engine.exceptions:AuthenticationError", |
| 68 | + "CodeFlowException": "codeflow_engine.exceptions:CodeFlowException", |
| 69 | + "CodeFlowPermissionError": "codeflow_engine.exceptions:CodeFlowPermissionError", |
| 70 | + "ConfigurationError": "codeflow_engine.exceptions:ConfigurationError", |
| 71 | + "IntegrationError": "codeflow_engine.exceptions:IntegrationError", |
| 72 | + "LLMProviderError": "codeflow_engine.exceptions:LLMProviderError", |
| 73 | + "RateLimitError": "codeflow_engine.exceptions:RateLimitError", |
| 74 | + "ValidationError": "codeflow_engine.exceptions:ValidationError", |
| 75 | + "WorkflowError": "codeflow_engine.exceptions:WorkflowError", |
| 76 | +} |
| 77 | + |
63 | 78 | # Public API exports |
64 | 79 | __all__ = [ |
65 | 80 | # Core engine |
@@ -127,6 +142,31 @@ def configure_logging(level: str = "INFO", *, format_json: bool = False) -> None |
127 | 142 | ) |
128 | 143 |
|
129 | 144 |
|
| 145 | +def __getattr__(name: str) -> Any: |
| 146 | + """Lazily load public exports to avoid importing optional dependencies.""" |
| 147 | + target = _LAZY_EXPORTS.get(name) |
| 148 | + if target is None: |
| 149 | + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
| 150 | + |
| 151 | + module_name, attribute_name = target.split(":", 1) |
| 152 | + try: |
| 153 | + module = importlib.import_module(module_name) |
| 154 | + value = getattr(module, attribute_name) |
| 155 | + except (ImportError, OSError): |
| 156 | + if name == "EnterpriseAuthorizationManager": |
| 157 | + value = None |
| 158 | + else: |
| 159 | + raise |
| 160 | + |
| 161 | + globals()[name] = value |
| 162 | + return value |
| 163 | + |
| 164 | + |
| 165 | +def __dir__() -> list[str]: |
| 166 | + """Return module attributes including lazy exports for interactive tooling.""" |
| 167 | + return sorted(set(globals()) | set(__all__)) |
| 168 | + |
| 169 | + |
130 | 170 | # Configure logging on import |
131 | 171 | log_level = os.getenv("CODEFLOW_LOG_LEVEL", "INFO") |
132 | 172 | json_logging = os.getenv("CODEFLOW_JSON_LOGGING", "false").lower() == "true" |
|
0 commit comments