Skip to content

Commit cc4e76b

Browse files
committed
refactor(doc): 重构文档构建工具并移除版本管理模块
- 移除独立的版本管理模块,改为直接从pyproject.toml获取版本号 - 重构文档构建工具,改进路径处理和构建选项配置 - 统一文档输出目录结构,默认使用doc/_build/html作为构建目标 - 增强tree命令的兼容性,添加回退方案 - 更新项目版本号至0.5.1
1 parent b3988e9 commit cc4e76b

File tree

4 files changed

+35
-155
lines changed

4 files changed

+35
-155
lines changed

pyproject.toml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "taolib"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
description = "道可道,非恒道"
55
authors = [
66
{name = "xinetzone", email = "[email protected]"},
@@ -55,13 +55,3 @@ dev = [
5555
"numpy",
5656
"matplotlib",
5757
]
58-
59-
[build-system]
60-
requires = ["setuptools>=61", "wheel"]
61-
build-backend = "setuptools.build_meta"
62-
63-
[tool.setuptools]
64-
package-dir = {"" = "src"}
65-
66-
[tool.setuptools.packages.find]
67-
where = ["src"]

src/taolib/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
from importlib.metadata import version, PackageNotFoundError
2-
3-
4-
def get_version(pkg_name: str) -> str:
5-
try:
6-
return version(pkg_name)
7-
except PackageNotFoundError:
8-
return "0.0.0"

src/taolib/doc.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
from tempfile import mkdtemp
1212
from invoke import task, Context
1313

14+
15+
def _get_sphinx_paths(ctx: Context, source: str | None, target: str | None) -> tuple[str, str]:
16+
src = source or getattr(ctx.sphinx, "source", "doc")
17+
dst = target or getattr(ctx.sphinx, "target", "doc/_build/html")
18+
return src, dst
19+
1420
logger = logging.getLogger(__name__)
1521

1622
# 在非 Windows 平台上使用 pty
@@ -35,7 +41,9 @@ def build(ctx: Context,
3541
language: str | None = None,
3642
source: str | None = None,
3743
target: str | None = None,
38-
nitpick: bool = False) -> None:
44+
nitpick: bool = False,
45+
jobs: str = "auto",
46+
keep_going: bool = True) -> None:
3947
"""构建项目的 Sphinx 文档。
4048
4149
Args:
@@ -46,17 +54,18 @@ def build(ctx: Context,
4654
source: 源目录,覆盖配置设置
4755
target: 输出目录,覆盖配置设置
4856
nitpick: 是否启用更严格的警告/错误检查"""
49-
source = source or ctx.sphinx.source
50-
target = target or ctx.sphinx.target
57+
source, target = _get_sphinx_paths(ctx, source, target)
5158

52-
# 处理语言选项
5359
if language:
54-
opts = f'-D language={language}'
55-
target = f'{target}/{language}'
60+
opts = f"{opts} -D language={language}".strip()
61+
target = f"{target}/{language}"
5662

57-
# 处理严格模式选项
5863
if nitpick:
59-
opts += " -n -W -T"
64+
opts = f"{opts} -n -W -T".strip()
65+
66+
opts = f"{opts} -j {jobs}".strip()
67+
if keep_going:
68+
opts = f"{opts} --keep-going".strip()
6069

6170
# 执行构建命令
6271
cmd = f"sphinx-build -b {builder} {opts} {source} {target}"
@@ -76,14 +85,12 @@ def intl(ctx: Context, language: str = 'en') -> None:
7685
target = Path(ctx.sphinx.target).parent / 'gettext'
7786

7887
if language == 'en':
79-
# 英语是源语言,需要重新生成 POT 文件
80-
clean(ctx)
88+
if target.exists():
89+
rmtree(target)
8190
build(ctx, target=target, opts=opts)
8291
elif language:
83-
# 确保 POT 文件已生成
84-
if not Path(target).exists():
92+
if not target.exists():
8593
build(ctx, target=target, opts=opts)
86-
# 更新指定语言的翻译
8794
ctx.run(f'sphinx-intl update -p {target} -l {language}')
8895
# 以下代码已注释掉,因为当前项目可能不需要
8996
# for DIR in ['pages', 'posts', 'shop']:
@@ -109,13 +116,16 @@ def doctest(ctx: Context) -> None:
109116

110117
@task
111118
def tree(ctx: Context) -> None:
112-
"""使用 'tree' 程序显示文档内容结构。
113-
114-
Args:
115-
ctx: Invoke 上下文对象,包含 sphinx 配置信息"""
116-
# 定义需要忽略的文件和目录模式
117119
ignore = ".git|*.pyc|*.swp|dist|*.egg-info|_static|_build|_templates"
118-
ctx.run(f'tree -Ca -I "{ignore}" {ctx.sphinx.source}')
120+
try:
121+
ctx.run(f'tree -Ca -I "{ignore}" {ctx.sphinx.source}', pty=PTY)
122+
except Exception:
123+
root = Path(ctx.sphinx.source)
124+
for p in sorted(root.rglob("*")):
125+
rel = p.relative_to(root)
126+
if any(part in ignore.split("|") for part in rel.parts):
127+
continue
128+
print(rel)
119129

120130

121131
# 文档站点配置集合创建函数
@@ -132,8 +142,8 @@ def create_docs(project_configs: Union[List[Dict[str, str]], Dict[str, Dict[str,
132142
...
133143

134144
def create_docs(
135-
source: Union[str, List[Dict[str, str]], Dict[str, Dict[str, str]], None] = None,
136-
target: str = '.temp/html',
145+
source: Union[str, List[Dict[str, str]], Dict[str, Dict[str, str]], None] = None,
146+
target: str = 'doc/_build/html',
137147
children: str = ''
138148
) -> Collection:
139149
"""创建文档站点配置集合。
@@ -183,7 +193,7 @@ def create_docs(
183193
# 获取项目配置,提供默认值
184194
name = config.get('name', f'doc_{i+1}')
185195
proj_source = config.get('source', 'doc')
186-
proj_target = config.get('target', f'.temp/html/{name}')
196+
proj_target = config.get('target', f'doc/_build/html/{name}')
187197
proj_children = config.get('children', '')
188198

189199
# 创建项目特定的子命令集合
@@ -209,7 +219,7 @@ def create_docs(
209219
for name, config in project_configs.items():
210220
# 获取项目配置
211221
proj_source = config.get('source', 'doc')
212-
proj_target = config.get('target', f'.temp/html/{name}')
222+
proj_target = config.get('target', f'doc/_build/html/{name}')
213223
proj_children = config.get('children', '')
214224

215225
# 创建项目特定的子命令集合
@@ -234,7 +244,7 @@ def create_docs(
234244
return main_namespace
235245

236246

237-
def sites(source: str = 'doc', target: str = '.temp/html', children: str = '') -> Collection:
247+
def sites(source: str = 'doc', target: str = 'doc/_build/html', children: str = '') -> Collection:
238248
"""创建文档站点配置集合。
239249
240250
为不同的文档站点创建配置好的 Invoke 集合,用于构建 Sphinx 文档。

src/taolib/version.py

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)