"""
Python 路径配置模块
用于确保在不同环境（本地、Docker）中都能正确导入模块
"""
import sys
import os

def setup_python_path():
    """设置 Python 路径"""
    # 获取当前文件所在目录
    current_dir = os.path.dirname(os.path.abspath(__file__))
    
    # 添加项目根目录和 src 目录到 Python 路径
    project_root = os.path.dirname(current_dir)  # LQAdminPlatform
    src_dir = current_dir  # src
    
    paths_to_add = [
        project_root,  # LQAdminPlatform
        src_dir,       # LQAdminPlatform/src
        os.path.join(src_dir, 'app'),  # LQAdminPlatform/src/app
    ]
    
    for path in paths_to_add:
        if path not in sys.path:
            sys.path.insert(0, path)
    
    # 设置 PYTHONPATH 环境变量
    pythonpath = os.environ.get('PYTHONPATH', '')
    new_paths = [p for p in paths_to_add if p not in pythonpath.split(os.pathsep)]
    if new_paths:
        if pythonpath:
            os.environ['PYTHONPATH'] = os.pathsep.join([pythonpath] + new_paths)
        else:
            os.environ['PYTHONPATH'] = os.pathsep.join(new_paths)

# 自动执行路径配置
setup_python_path()