From c140bda66b40b35feecfe9c9e232e10e000dfaaa Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Mon, 9 Mar 2026 14:14:33 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E7=A7=BB=E9=99=A4=20pyproject.toml?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BA=20uv=20run=20--with=20=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E7=AE=A1=E7=90=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 pyproject.toml 和 uv.lock - 更新 SKILL.md:使用 uv run --with 按需加载依赖 - 更新 README.md:添加多行格式的测试命令 - 更新项目规范文档 - 修复脚本:支持从任意位置执行 - 新增 uv-with-dependency-management 规范 --- README.md | 146 ++++++++++++++---- SKILL.md | 117 +++++--------- openspec/config.yaml | 2 +- .../specs/multi-platform-dependencies/spec.md | 79 ++++------ .../uv-with-dependency-management/spec.md | 77 +++++++++ pyproject.toml | 132 ---------------- scripts/lyxy_document_reader.py | 6 + 7 files changed, 267 insertions(+), 292 deletions(-) create mode 100644 openspec/specs/uv-with-dependency-management/spec.md delete mode 100644 pyproject.toml diff --git a/README.md b/README.md index 253a5e4..6470260 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,9 @@ ## 开发环境 -- 使用 uv 管理依赖,禁用主机 Python -- 依赖声明:pyproject.toml -- 安装:根据平台选择对应的 extras(详见 SKILL.md) - - macOS x86_64 (Intel): `uv pip install -e ".[pdf-macos-intel]"` - - macOS arm64 (Apple Silicon): `uv pip install -e ".[pdf-macos-arm]"` - - Windows: `uv pip install -e ".[pdf-win]"` - - Linux: `uv pip install -e ".[pdf-linux]"` +- 使用 uv 运行脚本和测试,禁用主机 Python +- 依赖管理:使用 `uv run --with` 按需加载依赖 +- 依赖说明:详见 SKILL.md 的"依赖安装指南"章节 ## 项目结构 @@ -26,25 +22,128 @@ skill/ # SKILL 文档 ## 开发工作流 +使用 `uv run --with` 方式运行测试和开发工具: + ```bash -# 运行测试 -uv run pytest +# 运行测试(需要先安装 pytest) +uv run \ + --with pytest \ + --with pytest-cov \ + --with chardet \ + pytest # 运行测试并查看覆盖率 -uv run pytest --cov=scripts --cov-report=term-missing +uv run \ + --with pytest \ + --with pytest-cov \ + --with chardet \ + pytest --cov=scripts --cov-report=term-missing # 运行特定测试文件 -uv run pytest tests/test_readers/test_docx/ +uv run \ + --with pytest \ + --with chardet \ + pytest tests/test_readers/test_docx/ # 运行特定测试类或方法 -uv run pytest tests/test_cli/test_main.py::TestCLIDefaultOutput::test_default_output_docx +uv run \ + --with pytest \ + --with chardet \ + pytest tests/test_cli/test_main.py::TestCLIDefaultOutput::test_default_output_docx # 代码格式化 -uv run black . -uv run isort . +uv run \ + --with black \ + --with isort \ + --with chardet \ + bash -c "black . && isort ." # 类型检查 -uv run mypy . +uv run \ + --with mypy \ + --with chardet \ + mypy . +``` + +**测试 DOCX reader**: + +```bash +uv run \ + --with pytest \ + --with docling \ + --with "unstructured[docx]" \ + --with "markitdown[docx]" \ + --with pypandoc-binary \ + --with python-docx \ + --with markdownify \ + --with chardet \ + pytest tests/test_readers/test_docx/ +``` + +**测试 PDF reader**: + +```bash +# 默认命令(macOS ARM、Linux、Windows) +uv run \ + --with pytest \ + --with docling \ + --with "unstructured[pdf]" \ + --with "markitdown[pdf]" \ + --with pypdf \ + --with markdownify \ + --with chardet \ + pytest tests/test_readers/test_pdf/ + +# macOS x86_64 (Intel) 特殊命令 +uv run \ + --python 3.12 \ + --with pytest \ + --with "docling==2.40.0" \ + --with "docling-parse==4.0.0" \ + --with "numpy<2" \ + --with "markitdown[pdf]" \ + --with pypdf \ + --with markdownify \ + --with chardet \ + pytest tests/test_readers/test_pdf/ +``` + +**测试其他格式**: + +```bash +# XLSX reader +uv run \ + --with pytest \ + --with docling \ + --with "unstructured[xlsx]" \ + --with "markitdown[xlsx]" \ + --with pandas \ + --with tabulate \ + --with chardet \ + pytest tests/test_readers/test_xlsx/ + +# PPTX reader +uv run \ + --with pytest \ + --with docling \ + --with "unstructured[pptx]" \ + --with "markitdown[pptx]" \ + --with python-pptx \ + --with markdownify \ + --with chardet \ + pytest tests/test_readers/test_pptx/ + +# HTML reader +uv run \ + --with pytest \ + --with trafilatura \ + --with domscribe \ + --with markitdown \ + --with html2text \ + --with beautifulsoup4 \ + --with httpx \ + --with chardet \ + pytest tests/test_readers/test_html/ ``` ## 测试 @@ -61,13 +160,8 @@ uv run mypy . - 编码测试(GBK、UTF-8 BOM 等) - 一致性测试(验证不同 Reader 解析结果的一致性) -运行测试前确保已安装所有依赖(根据你的平台选择对应的 extras): -```bash -# macOS x86_64 (Intel) 示例 -uv pip install -e ".[office-macos-intel]" +运行测试前,请根据测试类型使用 `uv run --with` 安装对应的依赖包。详见上方的"开发工作流"章节和 SKILL.md 的"依赖安装指南"。 -# 其他平台请参考 SKILL.md 的"多平台依赖安装指南" -``` ## 代码规范 @@ -98,16 +192,12 @@ skill/SKILL.md 面向 AI 用户,必须遵循 Claude Skill 构建指南的最 6. **错误处理**: 常见错误及解决方案 7. **References**: 指向项目文档的链接 -### 双路径执行策略 - -- **优先**: 使用 lyxy-runner-python skill(自动管理依赖) -- **回退**: 主机 Python 环境(需手动安装依赖) - -### 依赖说明 +### 依赖管理 +- 使用 `uv run --with` 方式按需加载依赖 - 必须使用具体的 pip 包名 -- 不能使用 lyxy-document[xxx] 形式(发布时没有 pyproject.toml) - 按文档类型分组说明 +- 详见 SKILL.md 的"依赖安装指南"章节 ## 解析器架构 diff --git a/SKILL.md b/SKILL.md index fc82a95..833031f 100644 --- a/SKILL.md +++ b/SKILL.md @@ -5,7 +5,7 @@ license: MIT metadata: version: "1.0" author: lyxy -compatibility: Requires Python 3.11+. 优先使用 lyxy-runner-python skill 执行(自动管理依赖)。回退到主机 Python 时需根据平台手动安装依赖:Windows(pdf-win/office-win) / macOS Intel(pdf-macos-intel/office-macos-intel,需Python 3.12) / macOS ARM(pdf-macos-arm/office-macos-arm) / Linux(pdf-linux/office-linux)。详见"多平台依赖安装指南"章节。 +compatibility: Requires Python 3.11+. 使用 uv run --with 方式按需加载依赖,详见"依赖安装指南"章节。 --- # 统一文档解析 Skill @@ -16,7 +16,7 @@ compatibility: Requires Python 3.11+. 优先使用 lyxy-runner-python skill 执 **统一入口**:使用 `scripts/lyxy_document_reader.py` 作为统一的命令行入口,自动识别文件类型并执行解析。 -**双路径执行**:此 skill 必须优先使用 **lyxy-runner-python skill** 执行脚本,该 skill 会自动管理 uv 隔离环境和依赖。当 lyxy-runner-python 不可用时,回退到主机 Python 环境执行。 +**依赖管理**:使用 `uv run --with` 方式按需加载解析器依赖。每次执行时根据文档类型指定对应的依赖包。 **支持的文档类型**: - **DOCX**:Word 文档 @@ -78,17 +78,16 @@ compatibility: Requires Python 3.11+. 优先使用 lyxy-runner-python skill 执 ### 基本语法 -```bash -# 方式 1:使用 lyxy-runner-python(推荐) -# lyxy-runner-python 会自动分析脚本依赖并使用 uv --with 安装 -# AI 只需执行: -python scripts/lyxy_document_reader.py <文件路径或URL> +使用 `uv run --with` 按需加载依赖包: -# 方式 2:回退到主机 Python(需要预先手动安装依赖) -# 根据文档类型安装对应依赖后执行: -python scripts/lyxy_document_reader.py <文件路径或URL> +```bash +# 根据文档类型选择对应的依赖包 +uv run --with <依赖包1> --with <依赖包2> ... \ + scripts/lyxy_document_reader.py <文件路径或URL> ``` +具体的依赖包列表请参考下方的"依赖安装指南"。 + ### 使用示例 ```bash @@ -117,13 +116,13 @@ python scripts/lyxy_document_reader.py document.docx -s "\d{4}-\d{2}-\d{2}" python scripts/lyxy_document_reader.py document.docx -s "关键词" -n 5 ``` -### 多平台依赖安装指南 +### 依赖安装指南 -**重要说明**:本项目为不同平台提供特定的依赖配置,请根据你的平台选择对应的 extra。 +使用 `uv run --with` 方式按需加载解析器依赖。以下命令适用于大多数平台(macOS ARM、Linux、Windows)。 #### 平台检测 -在使用前,请先检测你的平台: +在遇到问题时,可以检测你的平台: ```bash # macOS / Linux @@ -137,92 +136,52 @@ $env:OS # 或检查环境变量 python -c "import platform; print(f'{platform.system()}-{platform.machine()}')" ``` -#### PDF 解析依赖 +#### PDF 解析 -根据你的平台选择对应的安装命令: +**默认命令**(适用于 macOS ARM、Linux、Windows): -**Windows x86_64** ```bash -uv run --with "lyxy-document[pdf-win]" scripts/lyxy_document_reader.py file.pdf -``` -- 依赖:docling, unstructured, PaddleOCR -- Python:>=3.11 -- 特殊说明:无 - -**macOS x86_64 (Intel)** -⚠️ **特殊平台**:需要特定版本配置 -```bash -uv run --python 3.12 --with "lyxy-document[pdf-macos-intel]" scripts/lyxy_document_reader.py file.pdf -``` -- 依赖:docling==2.40.0, docling-parse==4.0.0, numpy<2 -- Python:**必须 3.12** -- 特殊说明: - - `docling-parse` 5.x 无 x86_64 wheel,必须使用 4.0.0 - - `easyocr`(docling 的 OCR 后端)与 NumPy 2.x 不兼容 - -**macOS arm64 (Apple Silicon)** -```bash -uv run --with "lyxy-document[pdf-macos-arm]" scripts/lyxy_document_reader.py file.pdf -``` -- 依赖:docling, unstructured -- Python:>=3.11 -- 特殊说明:无 - -**Linux** -```bash -uv run --with "lyxy-document[pdf-linux]" scripts/lyxy_document_reader.py file.pdf -``` -- 依赖:docling, unstructured -- Python:>=3.11 -- 特殊说明:无 - -#### Office 文档依赖 - -**Windows x86_64** -```bash -uv run --with "lyxy-document[office-win]" scripts/lyxy_document_reader.py file.docx +uv run --with docling --with "unstructured[pdf]" --with "markitdown[pdf]" --with pypdf --with markdownify --with chardet scripts/lyxy_document_reader.py file.pdf ``` -**macOS x86_64 (Intel)** +**macOS x86_64 (Intel) 特殊说明**: + +此平台需要使用 Python 3.12 和特定版本的依赖: + ```bash -uv run --python 3.12 --with "lyxy-document[office-macos-intel]" scripts/lyxy_document_reader.py file.docx +uv run --python 3.12 --with "docling==2.40.0" --with "docling-parse==4.0.0" --with "numpy<2" --with "markitdown[pdf]" --with pypdf --with markdownify --with chardet scripts/lyxy_document_reader.py file.pdf ``` -**macOS arm64 (Apple Silicon)** +原因:`docling-parse` 5.x 无 x86_64 wheel,必须使用 4.0.0;`easyocr`(docling 的 OCR 后端)与 NumPy 2.x 不兼容。 + +#### DOCX 解析 + ```bash -uv run --with "lyxy-document[office-macos-arm]" scripts/lyxy_document_reader.py file.docx +uv run --with docling --with "unstructured[docx]" --with "markitdown[docx]" --with pypandoc-binary --with python-docx --with markdownify --with chardet scripts/lyxy_document_reader.py file.docx ``` -**Linux** +#### XLSX 解析 + ```bash -uv run --with "lyxy-document[office-linux]" scripts/lyxy_document_reader.py file.docx +uv run --with docling --with "unstructured[xlsx]" --with "markitdown[xlsx]" --with pandas --with tabulate --with chardet scripts/lyxy_document_reader.py file.xlsx ``` -### 主机 Python 环境依赖安装 - -当 lyxy-runner-python 不可用时,需要根据文档类型手动安装依赖: +#### PPTX 解析 ```bash -# DOCX 文档 -pip install docling unstructured markitdown pypandoc-binary python-docx markdownify chardet +uv run --with docling --with "unstructured[pptx]" --with "markitdown[pptx]" --with python-pptx --with markdownify --with chardet scripts/lyxy_document_reader.py file.pptx +``` -# XLSX 表格 -pip install docling unstructured markitdown pandas tabulate chardet +#### HTML/URL 解析 -# PPTX 演示文稿 -pip install docling unstructured markitdown python-pptx markdownify chardet +```bash +uv run --with trafilatura --with domscribe --with markitdown --with html2text --with beautifulsoup4 --with httpx --with chardet scripts/lyxy_document_reader.py https://example.com +``` -# PDF 文档 -pip install docling unstructured unstructured-paddleocr markitdown pypdf markdownify chardet +**需要 JavaScript 渲染的网页**,额外添加: -# HTML/URL 网页 -pip install trafilatura domscribe markitdown html2text beautifulsoup4 httpx chardet - -# 网页(需要 JS 渲染时,额外添加) -pip install pyppeteer selenium - -# 安装所有文档类型支持 -pip install docling unstructured unstructured-paddleocr markitdown pypandoc-binary python-docx python-pptx pandas tabulate pypdf markdownify trafilatura domscribe html2text beautifulsoup4 httpx pyppeteer selenium chardet +```bash +--with pyppeteer --with selenium ``` ## 错误处理 diff --git a/openspec/config.yaml b/openspec/config.yaml index d1c2ab7..a9da0e8 100644 --- a/openspec/config.yaml +++ b/openspec/config.yaml @@ -7,7 +7,7 @@ context: | - 依赖: pyproject.toml声明,使用uv安装 - 主机环境: 禁止污染配置,需操作须请求用户 - 开发文档: README.md,每次迭代按需更新开发文档; 禁emoji/特殊字符 - - skill文档: SKILL.md,每次迭代按需更新skill文档(面向AI且需按无uv环境的前提编写) + - skill文档: SKILL.md,每次迭代按需更新skill文档 - 测试: 所有需求必须设计全面测试 - 任务: 禁止创建git变更任务(push/commit等); git读取允许(status/log/diff等) - 代码: 模块文件150-300行; 错误需自定义异常+清晰信息+位置上下文 diff --git a/openspec/specs/multi-platform-dependencies/spec.md b/openspec/specs/multi-platform-dependencies/spec.md index 6383244..28cb6f1 100644 --- a/openspec/specs/multi-platform-dependencies/spec.md +++ b/openspec/specs/multi-platform-dependencies/spec.md @@ -2,45 +2,31 @@ ## Purpose -为不同平台提供特定的依赖配置,解决平台特定的依赖兼容性问题(如 macOS x86_64 的 docling-parse 版本限制)。通过强制用户选择平台特定的 extras,确保依赖在不同平台上都能正常安装和运行。 +为不同平台提供特定的依赖配置,解决平台特定的依赖兼容性问题(如 macOS x86_64 的 docling-parse 版本限制)。通过 `uv run --with` 方式按需加载依赖,在文档中提供平台特定的命令示例。 ## Requirements -### Requirement: 平台特定的依赖配置 -系统必须在 `pyproject.toml` 中为不同平台提供特定的依赖 extras。 +### Requirement: 平台检测文档 +系统必须在 SKILL.md 中提供平台检测方法和平台特定的 `uv run --with` 命令示例。 -#### Scenario: PDF 解析的平台特定 extras -- **WHEN** 用户查看 `pyproject.toml` 中的 `[project.optional-dependencies]` 配置 -- **THEN** 系统必须提供以下 PDF 解析 extras: - - `pdf-win`: Windows x86_64 平台的 PDF 解析依赖 - - `pdf-macos-intel`: macOS x86_64 (Intel) 平台的 PDF 解析依赖 - - `pdf-macos-arm`: macOS arm64 (Apple Silicon) 平台的 PDF 解析依赖 - - `pdf-linux`: Linux 平台的 PDF 解析依赖 +#### Scenario: 平台检测命令 +- **WHEN** 用户阅读 SKILL.md 中的多平台依赖安装指南 +- **THEN** 系统必须提供以下平台的检测命令: + - macOS / Linux: `uname -m` 和 `uname -s` + - Windows: PowerShell 环境变量检测 + - Python 跨平台检测: `import platform; print(f'{platform.system()}-{platform.machine()}')` -#### Scenario: macOS x86_64 的特殊版本约束 -- **WHEN** 用户安装 `pdf-macos-intel` extra -- **THEN** 系统必须使用以下硬编码版本: - - `docling==2.40.0` - - `docling-parse==4.0.0` +#### Scenario: macOS x86_64 特殊说明 +- **WHEN** 用户在 macOS x86_64 平台阅读 PDF 解析依赖的安装说明 +- **THEN** 系统必须明确说明以下特殊要求: + - 必须使用 Python 3.12 + - `docling-parse` 5.x 无 x86_64 wheel,必须使用 4.0.0 + - 提供完整的 `uv run --python 3.12 --with "docling==2.40.0" --with "docling-parse==4.0.0" --with "numpy<2" ...` 命令示例 -#### Scenario: Office 文档的平台特定 extras -- **WHEN** 用户查看 `pyproject.toml` 中的 Office 文档 extras -- **THEN** 系统必须提供以下组合 extras: - - `office-win`: Windows x86_64 平台的完整 Office 文档依赖 - - `office-macos-intel`: macOS x86_64 (Intel) 平台的完整 Office 文档依赖 - - `office-macos-arm`: macOS arm64 (Apple Silicon) 平台的完整 Office 文档依赖 - - `office-linux`: Linux 平台的完整 Office 文档依赖 - -### Requirement: 移除通用平台 extras -系统必须移除通用的平台无关 extras,强制用户明确选择平台。 - -#### Scenario: PDF extra 不存在 -- **WHEN** 用户尝试安装 `lyxy-document[pdf]` extra -- **THEN** 系统必须报错或提示用户选择平台特定的 extra - -#### Scenario: Office extra 不存在 -- **WHEN** 用户尝试安装 `lyxy-document[office]` extra -- **THEN** 系统必须报错或提示用户选择平台特定的 extra +#### Scenario: 每个平台的运行命令 +- **WHEN** 用户阅读 SKILL.md +- **THEN** 系统必须为每个平台(Windows/macOS Intel/macOS ARM/Linux)和每种文档格式提供清晰的 `uv run --with` 命令示例 +- **AND** 命令必须包含所有必需的依赖包 ### Requirement: 平台检测文档 系统必须在 `SKILL.md` 中提供平台检测方法和平台特定的安装指南。 @@ -63,24 +49,13 @@ - **THEN** 系统必须为每个平台(Windows/macOS Intel/macOS ARM/Linux)提供清晰的 `uv run` 命令示例 ### Requirement: Lock 文件管理 -系统必须忽略 `uv.lock` 文件,不将其提交到版本控制。 +系统必须移除 `uv.lock` 文件,每次 `uv run` 都是全新的依赖解析。 -#### Scenario: gitignore 配置 +#### Scenario: 移除 uv.lock 文件 +- **WHEN** 用户查看项目根目录 +- **THEN** 系统必须不包含 uv.lock 文件 +- **AND** 依赖版本由文档中的版本约束说明 + +#### Scenario: gitignore 配置(可选) - **WHEN** 用户查看项目的 `.gitignore` 文件 -- **THEN** 系统必须在文件中包含 `uv.lock` 条目 - -#### Scenario: 依赖安装灵活性 -- **WHEN** 用户使用 `uv run --with` 安装依赖 -- **THEN** 系统必须能够根据当前平台动态解析依赖,而不依赖预先锁定的 lock 文件 - -### Requirement: 依赖重复但清晰 -系统允许在多个平台 extras 中重复声明相同的依赖,以保持清晰和简单。 - -#### Scenario: 重复声明基础依赖 -- **WHEN** 用户查看不同的平台 extras -- **THEN** 系统可以在每个 extra 中重复声明基础依赖(如 `markitdown[pdf]`、`pypdf`、`markdownify`) -- **AND** 这些重复声明必须版本一致 - -#### Scenario: 维护简单性优先 -- **WHEN** 开发者需要修改依赖版本 -- **THEN** 系统优先选择简单清晰的重复声明,而不是复杂的依赖引用或约束文件 +- **THEN** 系统可以包含 `uv.lock` 条目以确保不会误提交(如果用户重新创建了 lock 文件) diff --git a/openspec/specs/uv-with-dependency-management/spec.md b/openspec/specs/uv-with-dependency-management/spec.md new file mode 100644 index 0000000..a0c104e --- /dev/null +++ b/openspec/specs/uv-with-dependency-management/spec.md @@ -0,0 +1,77 @@ +# UV --with 依赖管理 + +## Purpose + +基于文档的依赖管理方式,使用 `uv run --with` 按需加载依赖。移除 pyproject.toml 和 uv.lock,通过 SKILL.md 和 README.md 提供完整的依赖说明和命令示例。 + +## Requirements + +### Requirement: 文档驱动的依赖声明 +系统必须在 SKILL.md 和 README.md 中明确说明每种文档格式和平台所需的依赖包。 + +#### Scenario: SKILL.md 包含完整的依赖命令 +- **WHEN** AI 或用户阅读 SKILL.md +- **THEN** 文档必须为每种文档格式(DOCX/XLSX/PPTX/PDF/HTML)和平台提供完整的 `uv run --with` 命令示例 +- **AND** 命令必须包含所有必需的依赖包 + +#### Scenario: README.md 包含开发依赖速查表 +- **WHEN** 开发者阅读 README.md +- **THEN** 文档必须提供测试每种格式的 `uv run --with` 命令示例 +- **AND** 必须包含特殊平台的版本约束说明(如 macOS Intel) + +### Requirement: 按需加载依赖 +系统必须使用 `uv run --with` 方式按需加载依赖,无需预先安装 extras 组合。 + +#### Scenario: 运行 PDF 解析 +- **WHEN** 用户执行 `uv run --with docling --with pypdf --with chardet scripts/lyxy_document_reader.py file.pdf` +- **THEN** 系统必须自动安装这些依赖(如果尚未安装) +- **AND** 必须成功执行脚本 + +#### Scenario: 测试 DOCX reader +- **WHEN** 开发者执行 `uv run --with docling --with python-docx ... pytest tests/test_readers/test_docx/` +- **THEN** 系统必须只安装指定的依赖 +- **AND** 必须成功运行测试 + +### Requirement: 平台特定版本约束 +系统必须在文档和命令中明确说明特殊平台的版本约束。 + +#### Scenario: macOS Intel 的 PDF 解析 +- **WHEN** 用户在 macOS x86_64 平台阅读 PDF 解析说明 +- **THEN** 文档必须明确说明需要 Python 3.12 +- **AND** 命令必须包含版本约束:`--with "docling==2.40.0" --with "docling-parse==4.0.0" --with "numpy<2"` +- **AND** 必须说明原因:docling-parse 5.x 无 x86_64 wheel + +#### Scenario: 其他平台使用最新版本 +- **WHEN** 用户在 macOS ARM 或 Linux 平台 +- **THEN** 命令可以省略版本号,使用最新兼容版本 +- **AND** 文档必须说明这是可行的 + +### Requirement: 移除 pyproject.toml +系统必须移除 pyproject.toml 文件,不再使用 extras 声明依赖。 + +#### Scenario: 项目根目录不包含 pyproject.toml +- **WHEN** 用户查看项目根目录 +- **THEN** 系统必须不包含 pyproject.toml 文件 + +#### Scenario: 依赖说明不在 pyproject.toml +- **WHEN** 用户尝试查找依赖声明 +- **THEN** 系统必须引导用户查阅 SKILL.md 或 README.md + +### Requirement: 移除 uv.lock +系统必须移除 uv.lock 文件,每次 `uv run` 都是全新的依赖解析。 + +#### Scenario: 项目不包含 uv.lock +- **WHEN** 用户查看项目根目录 +- **THEN** 系统必须不包含 uv.lock 文件 + +#### Scenario: 依赖版本由文档说明 +- **WHEN** 用户需要了解依赖版本约束 +- **THEN** 系统必须在 SKILL.md 或 README.md 中说明 +- **AND** 不依赖 uv.lock 锁定版本 + +### Requirement: 核心 chardet 依赖 +系统必须在所有 `uv run --with` 命令中包含 chardet 依赖。 + +#### Scenario: 所有格式都包含 chardet +- **WHEN** 用户查阅任何格式的依赖命令 +- **THEN** 命令必须包含 `--with chardet` diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 768b454..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,132 +0,0 @@ -[project] -name = "lyxy-document" -version = "0.1.0" -description = "帮助AI工具读取转换文档到markdown的skill" -readme = "README.md" -requires-python = ">=3.11" -dependencies = [ - "chardet>=5.0.0", -] - -[project.optional-dependencies] -# 平台特定的 DOCX 解析 extras -docx-win = [ - "docling>=2.0.0", - "unstructured[docx]>=0.12.0", - "markitdown[docx]>=0.1.0", - "pypandoc-binary>=1.13.0", - "python-docx>=1.1.0", - "markdownify>=0.12.0", -] -docx-unix = [ - "docling>=2.0.0", - "unstructured[docx]>=0.12.0", - "markitdown[docx]>=0.1.0", - "pypandoc-binary>=1.13.0", - "python-docx>=1.1.0", - "markdownify>=0.12.0", -] - -# 平台特定的 XLSX 解析 extras -xlsx-win = [ - "docling>=2.0.0", - "unstructured[xlsx]>=0.12.0", - "markitdown[xlsx]>=0.1.0", - "pandas>=2.0.0", - "tabulate>=0.9.0", -] -xlsx-unix = [ - "docling>=2.0.0", - "unstructured[xlsx]>=0.12.0", - "markitdown[xlsx]>=0.1.0", - "pandas>=2.0.0", - "tabulate>=0.9.0", -] - -# 平台特定的 PPTX 解析 extras -pptx-win = [ - "docling>=2.0.0", - "unstructured[pptx]>=0.12.0", - "markitdown[pptx]>=0.1.0", - "python-pptx>=0.6.0", - "markdownify>=0.12.0", -] -pptx-unix = [ - "docling>=2.0.0", - "unstructured[pptx]>=0.12.0", - "markitdown[pptx]>=0.1.0", - "python-pptx>=0.6.0", - "markdownify>=0.12.0", -] - -# 平台特定的 PDF 解析 extras -pdf-win = [ - "docling>=2.0.0", - "unstructured[pdf]>=0.12.0", - "unstructured-paddleocr>=0.1.0", - "paddlepaddle==2.6.2", - "ml-dtypes>=0.3.0", - "markitdown[pdf]>=0.1.0", - "pypdf>=4.0.0", - "markdownify>=0.12.0", -] -pdf-macos-intel = [ - "docling==2.40.0", - "docling-parse==4.0.0", - "markitdown[pdf]>=0.1.0", - "pypdf>=4.0.0", - "markdownify>=0.12.0", -] -pdf-macos-arm = [ - "docling>=2.0.0", - "unstructured[pdf]>=0.12.0", - "markitdown[pdf]>=0.1.0", - "pypdf>=4.0.0", - "markdownify>=0.12.0", -] -pdf-linux = [ - "docling>=2.0.0", - "unstructured[pdf]>=0.12.0", - "markitdown[pdf]>=0.1.0", - "pypdf>=4.0.0", - "markdownify>=0.12.0", -] - -# 平台特定的 Office 文档组合 extras -office-win = [ - "lyxy-document[docx-win,xlsx-win,pptx-win,pdf-win]", -] -office-macos-intel = [ - "lyxy-document[docx-unix,xlsx-unix,pptx-unix,pdf-macos-intel]", -] -office-macos-arm = [ - "lyxy-document[docx-unix,xlsx-unix,pptx-unix,pdf-macos-arm]", -] -office-linux = [ - "lyxy-document[docx-unix,xlsx-unix,pptx-unix,pdf-linux]", -] - -# 其他 extras(非平台特定) -html = [ - "trafilatura>=1.10.0", - "domscribe>=0.1.0", - "markitdown>=0.1.0", - "html2text>=2024.2.26", - "beautifulsoup4>=4.12.0", -] -http = [ - "httpx>=0.27.0", - "pyppeteer>=2.0.0", - "selenium>=4.18.0", -] -web = [ - "lyxy-document[html,http]", -] -full = [ - "lyxy-document[office-macos-arm,web]", -] -dev = [ - "pytest>=8.0.0", - "pytest-cov>=4.1.0", - "reportlab>=4.0.0", -] diff --git a/scripts/lyxy_document_reader.py b/scripts/lyxy_document_reader.py index dbab245..83e5ae4 100644 --- a/scripts/lyxy_document_reader.py +++ b/scripts/lyxy_document_reader.py @@ -7,6 +7,12 @@ import os import sys import warnings +# 将项目根目录添加到 sys.path,支持从任意位置执行脚本 +_current_dir = os.path.dirname(os.path.abspath(__file__)) +_project_root = os.path.dirname(_current_dir) +if _project_root not in sys.path: + sys.path.insert(0, _project_root) + # 抑制第三方库的进度条和日志,仅保留解析结果输出 os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1" os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"