refactor: 将核心代码迁移到 scripts 目录

- 创建 scripts/ 目录作为核心代码根目录
- 移动 core/, readers/, utils/ 到 scripts/ 下
- 移动 config.py, lyxy_document_reader.py 到 scripts/
- 移动 encoding_detection.py 到 scripts/utils/
- 更新 pyproject.toml 中的入口点路径和 pytest 配置
- 更新所有内部导入语句为 scripts.* 模块
- 更新 README.md 目录结构说明
- 更新 openspec/config.yaml 添加目录结构说明
- 删除无用的 main.py

此变更使项目结构更清晰,便于区分核心代码与测试、文档等支撑文件。
This commit is contained in:
2026-03-08 17:41:03 +08:00
parent 750ef50a8d
commit 15b63800a8
50 changed files with 66 additions and 60 deletions

48
scripts/readers/base.py Normal file
View File

@@ -0,0 +1,48 @@
"""Reader 基类,定义所有文档阅读器的公共接口。"""
from abc import ABC, abstractmethod
from pathlib import Path
from typing import List, Optional, Tuple
class BaseReader(ABC):
"""文档阅读器基类。"""
@property
@abstractmethod
def supported_extensions(self) -> List[str]:
"""返回支持的文件扩展名列表(如 ['.docx', '.doc'])。"""
pass
@abstractmethod
def supports(self, file_path: str) -> bool:
"""
判断是否支持给定的输入(轻量检查)。
仅做初步判断如扩展名、URL 模式),不进行完整验证。
完整验证(文件存在、格式有效性)在 parse() 中进行。
不访问文件系统,不打开文件。
Args:
file_path: 文件路径或 URL
Returns:
True 如果可能支持False 否则
"""
pass
@abstractmethod
def parse(self, file_path: str) -> Tuple[Optional[str], List[str]]:
"""
解析文件并返回 Markdown 内容。
需要检查文件存在和格式有效性,然后执行实际解析逻辑。
Args:
file_path: 文件路径或 URL
Returns: (content, failures)
- content: 成功时返回 Markdown 内容,失败时返回 None
- failures: 各解析器的失败原因列表
"""
pass