refactor(06-03): move sys.path manipulation to lazy import in analyze.py
- Remove top-level sys.path.insert for kb-deep-analyzer - Add module-level flag _deep_analyzer_path_added for single execution - Move sys.path manipulation inside _run_analysis method - External dependency import now happens lazily at runtime Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,11 +13,6 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
# Add kb-deep-analyzer to path for import
|
||||
_kb_deep_analyzer_path = Path(__file__).parent.parent.parent / "kb-deep-analyzer"
|
||||
if str(_kb_deep_analyzer_path) not in sys.path:
|
||||
sys.path.insert(0, str(_kb_deep_analyzer_path))
|
||||
|
||||
from kb_workflow.pipeline.config import get_settings
|
||||
from kb_workflow.pipeline.schemas import AnalyzeInput, AnalyzeOutput
|
||||
from kb_workflow.pipeline.state import WorkflowStateManager
|
||||
@@ -25,6 +20,9 @@ from kb_workflow.pipeline.processors.base import BaseProcessor
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Flag to ensure sys.path is only modified once for kb-deep-analyzer
|
||||
_deep_analyzer_path_added = False
|
||||
|
||||
|
||||
class AnalyzeProcessor(BaseProcessor):
|
||||
"""Analyze 处理器 - AI 深度内容分析
|
||||
@@ -201,7 +199,14 @@ class AnalyzeProcessor(BaseProcessor):
|
||||
Returns:
|
||||
AnalysisResult 对象
|
||||
"""
|
||||
# Lazy import to avoid dependency issues
|
||||
# Lazy import with delayed sys.path modification for external kb-deep-analyzer
|
||||
global _deep_analyzer_path_added
|
||||
if not _deep_analyzer_path_added:
|
||||
_kb_deep_analyzer_path = Path(__file__).parent.parent.parent / "kb-deep-analyzer"
|
||||
if str(_kb_deep_analyzer_path) not in sys.path:
|
||||
sys.path.insert(0, str(_kb_deep_analyzer_path))
|
||||
_deep_analyzer_path_added = True
|
||||
|
||||
from deep_analyzer import DeepAnalyzer, SimpleAIClient
|
||||
|
||||
# 初始化 AI 客户端
|
||||
|
||||
Reference in New Issue
Block a user