fix: 移除 cleaner.py 顶层导入,完善 README 测试指引

- 移除 cleaner.py 中 beautifulsoup4 的顶层导入,改为完全依赖函数内动态导入
- 新增 README 快速开始章节,提供验证环境和基础测试命令
- 完善测试前置依赖说明,明确仅需 chardet 即可运行基础测试
- 更新所有测试命令,移除不必要的 --with beautifulsoup4
This commit is contained in:
2026-03-10 11:08:51 +08:00
parent 25d748aa17
commit 688933c228
2 changed files with 35 additions and 3 deletions

View File

@@ -70,8 +70,36 @@ DEPENDENCIES = {
`--advice` 参数根据文件扩展名识别类型,检测当前平台,从 `config.DEPENDENCIES` 读取对应配置,生成 `uv run --with``pip install` 命令。 `--advice` 参数根据文件扩展名识别类型,检测当前平台,从 `config.DEPENDENCIES` 读取对应配置,生成 `uv run --with``pip install` 命令。
## 快速开始
### 验证环境
首先验证项目可以正常运行:
```bash
# 测试 --advice 功能(仅需 chardet
uv run --with chardet python scripts/lyxy_document_reader.py test.pdf --advice
```
### 运行基础测试
```bash
# 运行 CLI 测试(验证项目基本功能)
uv run \
--with pytest \
--with chardet \
pytest tests/test_cli/test_main.py::TestCLIAdviceOption -v
```
## 开发指南 ## 开发指南
### 测试前置依赖说明
由于 `HtmlReader` 模块在导入时会加载 `cleaner.py`,但 `cleaner.py` 中的第三方库已改为动态导入,因此仅需基础依赖:
- **chardet**:编码检测
`beautifulsoup4` 仅在实际使用 HTML 清理功能时才需要,模块导入时不依赖。
### 如何添加新的 Reader ### 如何添加新的 Reader
1.`scripts/readers/` 下创建新目录 1.`scripts/readers/` 下创建新目录
@@ -177,12 +205,18 @@ uv run \
#### 运行特定测试文件或方法 #### 运行特定测试文件或方法
```bash ```bash
# 运行特定测试文件 # 运行特定测试文件CLI 测试仅需 chardet
uv run \ uv run \
--with pytest \ --with pytest \
--with chardet \ --with chardet \
pytest tests/test_cli/test_main.py pytest tests/test_cli/test_main.py
# 仅运行 --advice 相关测试(不需要额外依赖)
uv run \
--with pytest \
--with chardet \
pytest tests/test_cli/test_main.py::TestCLIAdviceOption
# 运行特定测试类或方法 # 运行特定测试类或方法
uv run \ uv run \
--with pytest \ --with pytest \

View File

@@ -3,8 +3,6 @@
import re import re
from typing import Optional, Tuple from typing import Optional, Tuple
from bs4 import BeautifulSoup
def clean_html_content(html_content: str) -> Tuple[Optional[str], Optional[str]]: def clean_html_content(html_content: str) -> Tuple[Optional[str], Optional[str]]:
""" """