Compare commits

...

2 Commits

Author SHA1 Message Date
e53e64d386 refactor: 优化 chardet 依赖配置,仅保留在 HTML reader 中
- 从 pdf/docx/xlsx/pptx reader 的依赖列表中移除 chardet
- 保留 chardet 在 html reader 的依赖配置中(唯一实际使用方)
- 更新 README.md 文档,移除不必要的 chardet 依赖说明
- 简化测试命令,移除非 HTML reader 测试中的 chardet
2026-03-10 12:44:35 +08:00
688933c228 fix: 移除 cleaner.py 顶层导入,完善 README 测试指引
- 移除 cleaner.py 中 beautifulsoup4 的顶层导入,改为完全依赖函数内动态导入
- 新增 README 快速开始章节,提供验证环境和基础测试命令
- 完善测试前置依赖说明,明确仅需 chardet 即可运行基础测试
- 更新所有测试命令,移除不必要的 --with beautifulsoup4
2026-03-10 11:08:51 +08:00
3 changed files with 37 additions and 22 deletions

View File

@@ -70,8 +70,34 @@ DEPENDENCIES = {
`--advice` 参数根据文件扩展名识别类型,检测当前平台,从 `config.DEPENDENCIES` 读取对应配置,生成 `uv run --with``pip install` 命令。
## 快速开始
### 验证环境
首先验证项目可以正常运行:
```bash
# 测试 --advice 功能(无需额外依赖)
uv run python scripts/lyxy_document_reader.py test.pdf --advice
```
### 运行基础测试
```bash
# 运行 CLI 测试(验证项目基本功能)
uv run \
--with pytest \
pytest tests/test_cli/test_main.py::TestCLIAdviceOption -v
```
## 开发指南
### 测试前置依赖说明
由于 `HtmlReader` 模块在导入时会加载 `cleaner.py`,但 `cleaner.py` 中的第三方库已改为动态导入,因此无需额外依赖。
`beautifulsoup4``chardet` 仅在实际使用 HTML 功能时才需要,模块导入时不依赖。
### 如何添加新的 Reader
1.`scripts/readers/` 下创建新目录
@@ -88,7 +114,6 @@ DEPENDENCIES = {
uv run \
--with pytest \
--with pytest-cov \
--with chardet \
pytest
```
@@ -102,7 +127,6 @@ uv run \
--with pypandoc-binary \
--with python-docx \
--with markdownify \
--with chardet \
pytest tests/test_readers/test_docx/
```
@@ -115,7 +139,6 @@ uv run \
--with "markitdown[xlsx]" \
--with pandas \
--with tabulate \
--with chardet \
pytest tests/test_readers/test_xlsx/
```
@@ -128,7 +151,6 @@ uv run \
--with "markitdown[pptx]" \
--with python-pptx \
--with markdownify \
--with chardet \
pytest tests/test_readers/test_pptx/
```
@@ -142,7 +164,6 @@ uv run \
--with "markitdown[pdf]" \
--with pypdf \
--with markdownify \
--with chardet \
--with reportlab \
pytest tests/test_readers/test_pdf/
@@ -156,7 +177,6 @@ uv run \
--with "markitdown[pdf]" \
--with pypdf \
--with markdownify \
--with chardet \
--with reportlab \
pytest tests/test_readers/test_pdf/
```
@@ -177,17 +197,20 @@ uv run \
#### 运行特定测试文件或方法
```bash
# 运行特定测试文件
# 运行特定测试文件CLI 测试无需额外依赖)
uv run \
--with pytest \
--with chardet \
pytest tests/test_cli/test_main.py
# 仅运行 --advice 相关测试(不需要额外依赖)
uv run \
--with pytest \
pytest tests/test_cli/test_main.py::TestCLIAdviceOption
# 运行特定测试类或方法
uv run \
--with pytest \
--with docling \
--with chardet \
pytest tests/test_cli/test_main.py::TestCLIDefaultOutput::test_default_output_docx
```
@@ -196,7 +219,6 @@ uv run \
uv run \
--with pytest \
--with pytest-cov \
--with chardet \
pytest --cov=scripts --cov-report=term-missing
```

View File

@@ -30,8 +30,7 @@ DEPENDENCIES = {
"unstructured[pdf]",
"markitdown[pdf]",
"pypdf",
"markdownify",
"chardet"
"markdownify"
]
},
"Darwin-x86_64": {
@@ -42,8 +41,7 @@ DEPENDENCIES = {
"numpy<2",
"markitdown[pdf]",
"pypdf",
"markdownify",
"chardet"
"markdownify"
]
}
},
@@ -56,8 +54,7 @@ DEPENDENCIES = {
"markitdown[docx]",
"pypandoc-binary",
"python-docx",
"markdownify",
"chardet"
"markdownify"
]
}
},
@@ -69,8 +66,7 @@ DEPENDENCIES = {
"unstructured[xlsx]",
"markitdown[xlsx]",
"pandas",
"tabulate",
"chardet"
"tabulate"
]
}
},
@@ -82,8 +78,7 @@ DEPENDENCIES = {
"unstructured[pptx]",
"markitdown[pptx]",
"python-pptx",
"markdownify",
"chardet"
"markdownify"
]
}
},

View File

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