fix: 支持从任意路径调用 lyxy_document_reader.py

- 从 __file__ 动态计算项目根目录
- 使用绝对路径引用 bootstrap.py
- 设置正确的 PYTHONPATH 和 cwd
- 添加路径解析测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 12:06:44 +08:00
parent a5c0b67360
commit edbdeec90d
2 changed files with 62 additions and 4 deletions

View File

@@ -8,8 +8,13 @@ import subprocess
import sys
from pathlib import Path
# 确定项目根目录和脚本路径
script_file = Path(__file__).resolve()
scripts_dir = script_file.parent
project_root = scripts_dir.parent
bootstrap_path = str(scripts_dir / "bootstrap.py")
# 将 scripts/ 目录添加到 sys.path
scripts_dir = Path(__file__).resolve().parent
if str(scripts_dir) not in sys.path:
sys.path.append(str(scripts_dir))
@@ -96,7 +101,7 @@ def main():
# 生成 uv 命令参数列表
uv_args = generate_uv_args(
dependencies=dependencies,
script_path="scripts/bootstrap.py",
script_path=bootstrap_path,
python_version=python_version,
include_pyarmor=True
)
@@ -106,10 +111,10 @@ def main():
# 设置环境变量
env = os.environ.copy()
env["PYTHONPATH"] = "."
env["PYTHONPATH"] = str(project_root)
# 自启动:使用 subprocess 替代 execvpeWindows 兼容)
result = subprocess.run(uv_args, env=env)
result = subprocess.run(uv_args, env=env, cwd=str(project_root))
sys.exit(result.returncode)