feat: 添加自启动机制,移除 --advice 参数

- 创建 bootstrap.py 承载实际 CLI 逻辑
- 重写 lyxy_document_reader.py 为轻量入口,自动检测依赖并启动
- 使用 subprocess.run() 实现跨平台兼容的自启动
- 移除 --advice 参数及相关测试
- 更新文档和规范,简化使用方式
This commit is contained in:
2026-03-11 23:49:39 +08:00
parent e67ec24dfd
commit 229f17bfee
8 changed files with 252 additions and 202 deletions

View File

@@ -10,17 +10,18 @@
- 使用 uv 运行脚本和测试,禁用主机 Python
- 依赖管理:使用 `uv run --with` 按需加载依赖
- 快速获取建议:使用 `-a/--advice` 参数查看执行命令
- 自启动机制:脚本自动检测依赖并用正确的 uv 命令执行
## 项目架构
```
scripts/
├── lyxy_document_reader.py # CLI 入口
├── lyxy_document_reader.py # CLI 入口(自启动)
├── bootstrap.py # 实际执行模块
├── config.py # 配置(含 DEPENDENCIES 依赖配置)
├── core/ # 核心模块
│ ├── parser.py # 解析调度
│ ├── advice_generator.py # --advice 执行建议生成
│ ├── advice_generator.py # 依赖检测和配置生成
│ ├── markdown.py # Markdown 工具
│ └── exceptions.py # 异常定义
├── readers/ # 格式阅读器
@@ -94,9 +95,9 @@ DEPENDENCIES = {
}
```
### --advice 生成机制
### 自启动机制
`--advice` 参数根据文件扩展名识别类型,检测当前平台,从 `config.DEPENDENCIES` 读取对应配置,生成 `uv run --with``pip install` 命令。
入口脚本根据文件扩展名识别类型,检测当前平台,从 `config.DEPENDENCIES` 读取对应配置,自动生成并执行正确的 `uv run --with` 命令。
## 快速开始
@@ -105,8 +106,8 @@ DEPENDENCIES = {
首先验证项目可以正常运行:
```bash
# 测试 --advice 功能(无需额外依赖
uv run python scripts/lyxy_document_reader.py test.pdf --advice
# 测试解析功能(自动检测依赖并执行
python scripts/lyxy_document_reader.py "https://example.com"
```
### 运行基础测试
@@ -115,7 +116,7 @@ uv run python scripts/lyxy_document_reader.py test.pdf --advice
# 运行 CLI 测试(验证项目基本功能)
uv run \
--with pytest \
pytest tests/test_cli/test_main.py::TestCLIAdviceOption -v
pytest tests/test_cli/ -v
```
## 开发指南
@@ -242,11 +243,6 @@ uv run \
--with pytest \
pytest tests/test_cli/test_main.py
# 仅运行 --advice 相关测试(不需要额外依赖)
uv run \
--with pytest \
pytest tests/test_cli/test_main.py::TestCLIAdviceOption
# 运行特定测试类或方法
uv run \
--with pytest \