toolkitx 0.0.4__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {toolkitx-0.0.4 → toolkitx-0.0.7}/.github/workflows/python-publish.yml +7 -5
- {toolkitx-0.0.4 → toolkitx-0.0.7}/.gitignore +1 -0
- toolkitx-0.0.7/.readthedocs.yaml +16 -0
- toolkitx-0.0.7/.vscode/settings.json +10 -0
- toolkitx-0.0.7/PKG-INFO +154 -0
- toolkitx-0.0.7/README.md +125 -0
- toolkitx-0.0.7/docs/index.md +14 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-30-auto-docs.md +225 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-30-configure-mkdocs.md +109 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-30-html-to-markdown.md +233 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-30-rich-docs.md +216 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-30-rtd-deployment.md +57 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-30-upgrade-deps-ruff.md +121 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-31-enrich-text-utils-doctests.md +107 -0
- toolkitx-0.0.7/docs/superpowers/plans/2026-05-31-fix-table-expansion.md +87 -0
- toolkitx-0.0.7/docs/superpowers/specs/2026-05-30-auto-docs-design.md +69 -0
- toolkitx-0.0.7/docs/superpowers/specs/2026-05-30-docstring-completion-design.md +43 -0
- toolkitx-0.0.7/docs/superpowers/specs/2026-05-30-html-to-markdown-design.md +55 -0
- toolkitx-0.0.7/docs/superpowers/specs/2026-05-30-rich-docs-design.md +47 -0
- toolkitx-0.0.7/docs/superpowers/specs/2026-05-30-rtd-prep-design.md +73 -0
- toolkitx-0.0.7/makefile +24 -0
- toolkitx-0.0.7/mkdocs.yml +55 -0
- toolkitx-0.0.7/pyproject.toml +68 -0
- toolkitx-0.0.7/scripts/gen_ref_pages.py +35 -0
- {toolkitx-0.0.4 → toolkitx-0.0.7}/tests/lab/test_translator.py +129 -50
- toolkitx-0.0.7/tests/test_html_utils.py +259 -0
- {toolkitx-0.0.4 → toolkitx-0.0.7}/tests/test_task_utils.py +143 -115
- {toolkitx-0.0.4 → toolkitx-0.0.7}/tests/test_text_utils.py +59 -24
- {toolkitx-0.0.4 → toolkitx-0.0.7}/toolkitx/__init__.py +21 -2
- toolkitx-0.0.7/toolkitx/html_utils.py +220 -0
- toolkitx-0.0.7/toolkitx/lab/__init__.py +10 -0
- {toolkitx-0.0.4 → toolkitx-0.0.7}/toolkitx/lab/translator.py +141 -91
- {toolkitx-0.0.4 → toolkitx-0.0.7}/toolkitx/task_utils.py +64 -47
- {toolkitx-0.0.4 → toolkitx-0.0.7}/toolkitx/text_utils.py +66 -36
- toolkitx-0.0.7/uv.lock +1016 -0
- toolkitx-0.0.4/PKG-INFO +0 -150
- toolkitx-0.0.4/README.md +0 -131
- toolkitx-0.0.4/makefile +0 -5
- toolkitx-0.0.4/pyproject.toml +0 -31
- toolkitx-0.0.4/toolkitx/lab/__init__.py +0 -5
- toolkitx-0.0.4/uv.lock +0 -444
- {toolkitx-0.0.4 → toolkitx-0.0.7}/.python-version +0 -0
- {toolkitx-0.0.4 → toolkitx-0.0.7}/LICENSE +0 -0
|
@@ -10,6 +10,9 @@ on:
|
|
|
10
10
|
branches:
|
|
11
11
|
- main # 在向 main 分支发起 Pull Request 时运行测试
|
|
12
12
|
|
|
13
|
+
env:
|
|
14
|
+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
|
15
|
+
|
|
13
16
|
jobs:
|
|
14
17
|
test:
|
|
15
18
|
runs-on: ubuntu-latest
|
|
@@ -24,8 +27,8 @@ jobs:
|
|
|
24
27
|
- name: Install uv
|
|
25
28
|
uses: astral-sh/setup-uv@v5
|
|
26
29
|
with:
|
|
27
|
-
# Install
|
|
28
|
-
|
|
30
|
+
# Install the latest stable version of uv
|
|
31
|
+
enable-cache: true
|
|
29
32
|
|
|
30
33
|
- name: "Set up Python"
|
|
31
34
|
uses: actions/setup-python@v5
|
|
@@ -48,7 +51,7 @@ jobs:
|
|
|
48
51
|
permissions:
|
|
49
52
|
# 对于受信任的发布 (Trusted Publishing) 至 PyPI,此权限是必需的
|
|
50
53
|
id-token: write
|
|
51
|
-
contents:
|
|
54
|
+
contents: write # 检出仓库并创建 Release 需要写权限
|
|
52
55
|
|
|
53
56
|
steps:
|
|
54
57
|
- name: Checkout repository
|
|
@@ -57,8 +60,7 @@ jobs:
|
|
|
57
60
|
- name: Install uv
|
|
58
61
|
uses: astral-sh/setup-uv@v5
|
|
59
62
|
with:
|
|
60
|
-
|
|
61
|
-
version: "0.7.3"
|
|
63
|
+
enable-cache: true
|
|
62
64
|
|
|
63
65
|
- name: "Set up Python"
|
|
64
66
|
uses: actions/setup-python@v5
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"workbench.editorAssociations": {
|
|
3
|
+
"*.copilotmd": "vscode.markdown.preview.editor",
|
|
4
|
+
"*.ipynb": "jupyter.notebook.ipynb",
|
|
5
|
+
"*.parquet": "duckdb.dataFileViewer",
|
|
6
|
+
"*.csv": "duckdb.dataFileViewer",
|
|
7
|
+
"*.tsv": "duckdb.dataFileViewer",
|
|
8
|
+
"*.xlsx": "duckdb.dataFileViewer"
|
|
9
|
+
}
|
|
10
|
+
}
|
toolkitx-0.0.7/PKG-INFO
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: toolkitx
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: A personal Python toolkit for common tasks
|
|
5
|
+
Project-URL: Homepage, https://github.com/ider-zh/toolkitx
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/ider-zh/toolkitx/issues
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: beautifulsoup4>=4.12.0
|
|
10
|
+
Requires-Dist: diskcache>=5.6.3
|
|
11
|
+
Requires-Dist: httpx>=0.28.1
|
|
12
|
+
Requires-Dist: markdownify>=0.14.0
|
|
13
|
+
Requires-Dist: polars>=1.38.1
|
|
14
|
+
Requires-Dist: pydantic>=2.12.5
|
|
15
|
+
Requires-Dist: tencentcloud-sdk-python<3.1.106,>=3.1.50
|
|
16
|
+
Requires-Dist: tqdm>=4.67.3
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest-dotenv>=0.5.2; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest>=9.0.2; extra == 'dev'
|
|
20
|
+
Requires-Dist: ruff>=0.9.0; extra == 'dev'
|
|
21
|
+
Provides-Extra: docs
|
|
22
|
+
Requires-Dist: mkdocs-gen-files>=0.5.0; extra == 'docs'
|
|
23
|
+
Requires-Dist: mkdocs-literate-nav>=0.6.0; extra == 'docs'
|
|
24
|
+
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
|
|
25
|
+
Requires-Dist: mkdocs-section-index>=0.3.0; extra == 'docs'
|
|
26
|
+
Requires-Dist: mkdocs<2.0.0,>=1.6.0; extra == 'docs'
|
|
27
|
+
Requires-Dist: mkdocstrings[python]>=0.25.0; extra == 'docs'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# ToolkitX
|
|
31
|
+
|
|
32
|
+
[](https://toolkitx.readthedocs.io/en/latest/?badge=latest)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
[](https://www.python.org/downloads/)
|
|
35
|
+
|
|
36
|
+
A personal Python toolkit for common tasks. This package provides robust utility functions to simplify common development workflows, focusing on text processing, HTML conversion, and task resilience.
|
|
37
|
+
|
|
38
|
+
📖 **Full Documentation**: [https://toolkitx.readthedocs.io/en/latest/](https://toolkitx.readthedocs.io/en/latest/)
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
* **HTML Utilities** (`toolkitx.html_utils`):
|
|
43
|
+
* `html_to_markdown`: Robust HTML to Markdown conversion. Handles complex tables (colspan/rowspan) by expansion and serializes nested tables to JSON for better LLM/Agent understanding. Automatically promotes the first row to header if missing.
|
|
44
|
+
|
|
45
|
+
* **Text Utilities** (`toolkitx.text_utils`):
|
|
46
|
+
* `truncate_text_smart`: Smartly truncates text by characters or words, attempting to preserve sentence or word boundaries with configurable tolerance.
|
|
47
|
+
* `split_text_by_word_count`: Splits long text into overlapping chunks based on word count.
|
|
48
|
+
|
|
49
|
+
* **Task Utilities** (`toolkitx.task_utils`):
|
|
50
|
+
* `with_resilience`: A decorator for API resilience with rate limiting (QPS), exponential backoff retry, and jitter.
|
|
51
|
+
* `PersistentTaskQueue`: A persistent task queue with SQLite backend, supporting concurrent processing, automatic retry, crash recovery, and graceful shutdown.
|
|
52
|
+
|
|
53
|
+
* **Experimental Translator** (`toolkitx.lab.translator`):
|
|
54
|
+
* `Translator`: A class providing translation capabilities using Baidu or Tencent translation APIs, with disk-based caching.
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
We recommend using [uv](https://github.com/astral-sh/uv) for fast and reliable dependency management.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Clone the repository
|
|
62
|
+
git clone https://github.com/ider-zh/toolkitx.git
|
|
63
|
+
cd toolkitx
|
|
64
|
+
|
|
65
|
+
# Install with development dependencies
|
|
66
|
+
uv pip install -e ".[dev,docs]"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
### HTML to Markdown (Robust Table Support)
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from toolkitx import html_to_markdown
|
|
75
|
+
|
|
76
|
+
# Handles merged cells (colspan/rowspan) and nested tables
|
|
77
|
+
html = """
|
|
78
|
+
<table>
|
|
79
|
+
<tr><td colspan="2">Merged Header</td></tr>
|
|
80
|
+
<tr><td>Cell 1</td><td>Cell 2</td></tr>
|
|
81
|
+
<tr>
|
|
82
|
+
<td>Outer</td>
|
|
83
|
+
<td>
|
|
84
|
+
<table><tr><td>Nested</td></tr></table>
|
|
85
|
+
</td>
|
|
86
|
+
</tr>
|
|
87
|
+
</table>
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
md = html_to_markdown(html)
|
|
91
|
+
print(md)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Text Smart Truncation
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from toolkitx import truncate_text_smart
|
|
98
|
+
|
|
99
|
+
text = "Hello World. This is a long sentence that should be truncated smartly."
|
|
100
|
+
# Strips trailing punctuation automatically
|
|
101
|
+
truncated = truncate_text_smart(text, limit=12)
|
|
102
|
+
print(truncated) # Output: 'Hello World...'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Task Resilience Decorator
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from toolkitx import with_resilience
|
|
109
|
+
|
|
110
|
+
@with_resilience(qps=2.0, max_retries=3)
|
|
111
|
+
def fetch_data(url):
|
|
112
|
+
# This function will be rate-limited and retried automatically
|
|
113
|
+
pass
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
### Running Tests
|
|
119
|
+
```bash
|
|
120
|
+
# Run unit tests
|
|
121
|
+
make test
|
|
122
|
+
|
|
123
|
+
# Run documentation tests (verify examples in docstrings)
|
|
124
|
+
make test-docs
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Documentation
|
|
128
|
+
```bash
|
|
129
|
+
# Preview documentation locally
|
|
130
|
+
make docs-serve
|
|
131
|
+
|
|
132
|
+
# Build static documentation site
|
|
133
|
+
make docs-build
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Changelog
|
|
137
|
+
|
|
138
|
+
### v0.0.7 (2026-07-09)
|
|
139
|
+
- **Bug Fix**: `html_to_markdown` no longer crashes (`IndexError: list index out of range`) when expanding tables that contain empty cells (e.g. `<td rowspan="2"></td>`). Empty cells now render as zero-width placeholders while preserving colspan/rowspan expansion.
|
|
140
|
+
|
|
141
|
+
### v0.0.6 (2026-07-09)
|
|
142
|
+
- **Dependency**: Pinned `tencentcloud-sdk-python` to `<3.1.106`. The Tencent SDK removed the TMT `TextTranslate` API (incl. `TextTranslateRequest`) starting in `3.1.106`, which would break `toolkitx.lab.translator`. The text-translation engine now stays on the last compatible release.
|
|
143
|
+
|
|
144
|
+
### v0.0.5 (2026-05-30)
|
|
145
|
+
- **New Feature**: Added `html_utils` with robust `html_to_markdown` converter.
|
|
146
|
+
- **Improved**: `truncate_text_smart` now strips trailing punctuation before appending suffix.
|
|
147
|
+
- **Documentation**: Established full automated documentation system with MkDocs, Material theme, and Read the Docs integration.
|
|
148
|
+
- **Verifiable Docs**: Added `doctest` examples to all core functions and a `make test-docs` target.
|
|
149
|
+
- **Workflow**: Integrated `ruff` for linting and formatting.
|
|
150
|
+
- **Dependency Management**: Fully transitioned to `uv` and pinned `mkdocs` for stability.
|
|
151
|
+
|
|
152
|
+
### v0.0.4 (2026-03-07)
|
|
153
|
+
- Added `task_utils` module with `with_resilience` decorator and `PersistentTaskQueue`.
|
|
154
|
+
- Added `polars`, `pydantic`, and `tqdm` as dependencies.
|
toolkitx-0.0.7/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# ToolkitX
|
|
2
|
+
|
|
3
|
+
[](https://toolkitx.readthedocs.io/en/latest/?badge=latest)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
|
|
7
|
+
A personal Python toolkit for common tasks. This package provides robust utility functions to simplify common development workflows, focusing on text processing, HTML conversion, and task resilience.
|
|
8
|
+
|
|
9
|
+
📖 **Full Documentation**: [https://toolkitx.readthedocs.io/en/latest/](https://toolkitx.readthedocs.io/en/latest/)
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
* **HTML Utilities** (`toolkitx.html_utils`):
|
|
14
|
+
* `html_to_markdown`: Robust HTML to Markdown conversion. Handles complex tables (colspan/rowspan) by expansion and serializes nested tables to JSON for better LLM/Agent understanding. Automatically promotes the first row to header if missing.
|
|
15
|
+
|
|
16
|
+
* **Text Utilities** (`toolkitx.text_utils`):
|
|
17
|
+
* `truncate_text_smart`: Smartly truncates text by characters or words, attempting to preserve sentence or word boundaries with configurable tolerance.
|
|
18
|
+
* `split_text_by_word_count`: Splits long text into overlapping chunks based on word count.
|
|
19
|
+
|
|
20
|
+
* **Task Utilities** (`toolkitx.task_utils`):
|
|
21
|
+
* `with_resilience`: A decorator for API resilience with rate limiting (QPS), exponential backoff retry, and jitter.
|
|
22
|
+
* `PersistentTaskQueue`: A persistent task queue with SQLite backend, supporting concurrent processing, automatic retry, crash recovery, and graceful shutdown.
|
|
23
|
+
|
|
24
|
+
* **Experimental Translator** (`toolkitx.lab.translator`):
|
|
25
|
+
* `Translator`: A class providing translation capabilities using Baidu or Tencent translation APIs, with disk-based caching.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
We recommend using [uv](https://github.com/astral-sh/uv) for fast and reliable dependency management.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Clone the repository
|
|
33
|
+
git clone https://github.com/ider-zh/toolkitx.git
|
|
34
|
+
cd toolkitx
|
|
35
|
+
|
|
36
|
+
# Install with development dependencies
|
|
37
|
+
uv pip install -e ".[dev,docs]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### HTML to Markdown (Robust Table Support)
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from toolkitx import html_to_markdown
|
|
46
|
+
|
|
47
|
+
# Handles merged cells (colspan/rowspan) and nested tables
|
|
48
|
+
html = """
|
|
49
|
+
<table>
|
|
50
|
+
<tr><td colspan="2">Merged Header</td></tr>
|
|
51
|
+
<tr><td>Cell 1</td><td>Cell 2</td></tr>
|
|
52
|
+
<tr>
|
|
53
|
+
<td>Outer</td>
|
|
54
|
+
<td>
|
|
55
|
+
<table><tr><td>Nested</td></tr></table>
|
|
56
|
+
</td>
|
|
57
|
+
</tr>
|
|
58
|
+
</table>
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
md = html_to_markdown(html)
|
|
62
|
+
print(md)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Text Smart Truncation
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from toolkitx import truncate_text_smart
|
|
69
|
+
|
|
70
|
+
text = "Hello World. This is a long sentence that should be truncated smartly."
|
|
71
|
+
# Strips trailing punctuation automatically
|
|
72
|
+
truncated = truncate_text_smart(text, limit=12)
|
|
73
|
+
print(truncated) # Output: 'Hello World...'
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Task Resilience Decorator
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from toolkitx import with_resilience
|
|
80
|
+
|
|
81
|
+
@with_resilience(qps=2.0, max_retries=3)
|
|
82
|
+
def fetch_data(url):
|
|
83
|
+
# This function will be rate-limited and retried automatically
|
|
84
|
+
pass
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
### Running Tests
|
|
90
|
+
```bash
|
|
91
|
+
# Run unit tests
|
|
92
|
+
make test
|
|
93
|
+
|
|
94
|
+
# Run documentation tests (verify examples in docstrings)
|
|
95
|
+
make test-docs
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Documentation
|
|
99
|
+
```bash
|
|
100
|
+
# Preview documentation locally
|
|
101
|
+
make docs-serve
|
|
102
|
+
|
|
103
|
+
# Build static documentation site
|
|
104
|
+
make docs-build
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Changelog
|
|
108
|
+
|
|
109
|
+
### v0.0.7 (2026-07-09)
|
|
110
|
+
- **Bug Fix**: `html_to_markdown` no longer crashes (`IndexError: list index out of range`) when expanding tables that contain empty cells (e.g. `<td rowspan="2"></td>`). Empty cells now render as zero-width placeholders while preserving colspan/rowspan expansion.
|
|
111
|
+
|
|
112
|
+
### v0.0.6 (2026-07-09)
|
|
113
|
+
- **Dependency**: Pinned `tencentcloud-sdk-python` to `<3.1.106`. The Tencent SDK removed the TMT `TextTranslate` API (incl. `TextTranslateRequest`) starting in `3.1.106`, which would break `toolkitx.lab.translator`. The text-translation engine now stays on the last compatible release.
|
|
114
|
+
|
|
115
|
+
### v0.0.5 (2026-05-30)
|
|
116
|
+
- **New Feature**: Added `html_utils` with robust `html_to_markdown` converter.
|
|
117
|
+
- **Improved**: `truncate_text_smart` now strips trailing punctuation before appending suffix.
|
|
118
|
+
- **Documentation**: Established full automated documentation system with MkDocs, Material theme, and Read the Docs integration.
|
|
119
|
+
- **Verifiable Docs**: Added `doctest` examples to all core functions and a `make test-docs` target.
|
|
120
|
+
- **Workflow**: Integrated `ruff` for linting and formatting.
|
|
121
|
+
- **Dependency Management**: Fully transitioned to `uv` and pinned `mkdocs` for stability.
|
|
122
|
+
|
|
123
|
+
### v0.0.4 (2026-03-07)
|
|
124
|
+
- Added `task_utils` module with `with_resilience` decorator and `PersistentTaskQueue`.
|
|
125
|
+
- Added `polars`, `pydantic`, and `tqdm` as dependencies.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Welcome to ToolkitX
|
|
2
|
+
|
|
3
|
+
ToolkitX is a personal Python toolkit for common tasks, focusing on resilience, text processing, and lab tools like translators.
|
|
4
|
+
|
|
5
|
+
## Modules
|
|
6
|
+
|
|
7
|
+
- **Task Utils**: Resilience decorators and persistent task queues.
|
|
8
|
+
- **Text Utils**: Smart text truncation and word-count based splitting.
|
|
9
|
+
- **HTML Utils**: Robust HTML to Markdown conversion with advanced table support.
|
|
10
|
+
- **Lab**: Experimental tools including Baidu and Tencent translators.
|
|
11
|
+
|
|
12
|
+
## Getting Started
|
|
13
|
+
|
|
14
|
+
Check the [API Reference](reference/toolkitx/index.md) for detailed documentation of all modules.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Automated Python API Documentation Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** Establish a zero-maintenance documentation system using MkDocs and mkdocstrings that automatically generates API reference from source code.
|
|
6
|
+
|
|
7
|
+
**Architecture:**
|
|
8
|
+
- **MkDocs + Material Theme:** Modern UI for documentation.
|
|
9
|
+
- **mkdocstrings:** Extracts documentation directly from Python code and docstrings.
|
|
10
|
+
- **mkdocs-gen-files:** Automatically generates Markdown files for every module in `toolkitx/`.
|
|
11
|
+
- **mkdocs-literate-nav + mkdocs-section-index:** Automates navigation sidebar generation.
|
|
12
|
+
|
|
13
|
+
**Tech Stack:** Python, uv, MkDocs, Material for MkDocs, mkdocstrings, mkdocs-gen-files.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
### Task 1: Setup Dependencies
|
|
18
|
+
|
|
19
|
+
**Files:**
|
|
20
|
+
- Modify: `pyproject.toml`
|
|
21
|
+
|
|
22
|
+
- [ ] **Step 1: Add documentation dependencies to `pyproject.toml`**
|
|
23
|
+
|
|
24
|
+
Add `docs` optional dependencies:
|
|
25
|
+
```toml
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
dev = [
|
|
28
|
+
"pytest>=9.0.2",
|
|
29
|
+
"pytest-dotenv>=0.5.2",
|
|
30
|
+
"ruff>=0.9.0",
|
|
31
|
+
]
|
|
32
|
+
docs = [
|
|
33
|
+
"mkdocs>=1.6.0",
|
|
34
|
+
"mkdocs-material>=9.5.0",
|
|
35
|
+
"mkdocstrings[python]>=0.25.0",
|
|
36
|
+
"mkdocs-gen-files>=0.5.0",
|
|
37
|
+
"mkdocs-literate-nav>=0.6.0",
|
|
38
|
+
"mkdocs-section-index>=0.3.0",
|
|
39
|
+
]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- [ ] **Step 2: Update lockfile**
|
|
43
|
+
|
|
44
|
+
Run: `uv lock`
|
|
45
|
+
|
|
46
|
+
- [ ] **Step 3: Commit**
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git add pyproject.toml uv.lock
|
|
50
|
+
git commit -m "chore: add documentation dependencies"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Task 2: Configure MkDocs
|
|
54
|
+
|
|
55
|
+
**Files:**
|
|
56
|
+
- Create: `mkdocs.yml`
|
|
57
|
+
- Create: `docs/index.md`
|
|
58
|
+
|
|
59
|
+
- [ ] **Step 1: Create `mkdocs.yml`**
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
site_name: ToolkitX Documentation
|
|
63
|
+
site_url: https://github.com/ider-zh/toolkitx
|
|
64
|
+
repo_url: https://github.com/ider-zh/toolkitx
|
|
65
|
+
edit_uri: edit/main/docs/
|
|
66
|
+
|
|
67
|
+
theme:
|
|
68
|
+
name: material
|
|
69
|
+
palette:
|
|
70
|
+
- scheme: default
|
|
71
|
+
primary: indigo
|
|
72
|
+
accent: indigo
|
|
73
|
+
toggle:
|
|
74
|
+
icon: material/brightness-7
|
|
75
|
+
name: Switch to dark mode
|
|
76
|
+
- scheme: slate
|
|
77
|
+
primary: indigo
|
|
78
|
+
accent: indigo
|
|
79
|
+
toggle:
|
|
80
|
+
icon: material/brightness-4
|
|
81
|
+
name: Switch to light mode
|
|
82
|
+
features:
|
|
83
|
+
- navigation.tabs
|
|
84
|
+
- navigation.sections
|
|
85
|
+
- navigation.top
|
|
86
|
+
- search.suggest
|
|
87
|
+
- search.highlight
|
|
88
|
+
- content.code.copy
|
|
89
|
+
|
|
90
|
+
plugins:
|
|
91
|
+
- search
|
|
92
|
+
- gen-files:
|
|
93
|
+
scripts:
|
|
94
|
+
- scripts/gen_ref_pages.py
|
|
95
|
+
- literate-nav:
|
|
96
|
+
nav_file: SUMMARY.md
|
|
97
|
+
- section-index
|
|
98
|
+
- mkdocstrings:
|
|
99
|
+
handlers:
|
|
100
|
+
python:
|
|
101
|
+
paths: [.]
|
|
102
|
+
options:
|
|
103
|
+
docstring_style: google
|
|
104
|
+
show_source: true
|
|
105
|
+
show_root_heading: true
|
|
106
|
+
show_category_heading: true
|
|
107
|
+
|
|
108
|
+
markdown_extensions:
|
|
109
|
+
- admonition
|
|
110
|
+
- pymdownx.highlight:
|
|
111
|
+
anchor_linenums: true
|
|
112
|
+
- pymdownx.inlinehilite
|
|
113
|
+
- pymdownx.snippets
|
|
114
|
+
- pymdownx.superfences
|
|
115
|
+
- pymdownx.tabbed:
|
|
116
|
+
alternate_style: true
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- [ ] **Step 2: Create `docs/index.md`**
|
|
120
|
+
|
|
121
|
+
```markdown
|
|
122
|
+
# Welcome to ToolkitX
|
|
123
|
+
|
|
124
|
+
ToolkitX is a personal Python toolkit for common tasks, focusing on resilience, text processing, and lab tools like translators.
|
|
125
|
+
|
|
126
|
+
## Modules
|
|
127
|
+
|
|
128
|
+
- **Task Utils**: Resilience decorators and persistent task queues.
|
|
129
|
+
- **Text Utils**: Smart text truncation and word-count based splitting.
|
|
130
|
+
- **Lab**: Experimental tools including Baidu and Tencent translators.
|
|
131
|
+
|
|
132
|
+
## Getting Started
|
|
133
|
+
|
|
134
|
+
Check the [API Reference](reference/toolkitx/index.md) for detailed documentation of all modules.
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
- [ ] **Step 3: Commit**
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git add mkdocs.yml docs/index.md
|
|
141
|
+
git commit -m "chore: configure mkdocs and create index page"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Task 3: Implement Automated API Reference Generation
|
|
145
|
+
|
|
146
|
+
**Files:**
|
|
147
|
+
- Create: `scripts/gen_ref_pages.py`
|
|
148
|
+
|
|
149
|
+
- [ ] **Step 1: Create `scripts/gen_ref_pages.py`**
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
"""Generate the code reference pages and navigation."""
|
|
153
|
+
|
|
154
|
+
from pathlib import Path
|
|
155
|
+
import mkdocs_gen_files
|
|
156
|
+
|
|
157
|
+
nav = mkdocs_gen_files.Nav()
|
|
158
|
+
|
|
159
|
+
root = Path(__file__).parent.parent
|
|
160
|
+
src = root / "toolkitx"
|
|
161
|
+
|
|
162
|
+
for path in sorted(src.rglob("*.py")):
|
|
163
|
+
module_path = path.relative_to(root).with_suffix("")
|
|
164
|
+
doc_path = path.relative_to(root).with_suffix(".md")
|
|
165
|
+
full_doc_path = Path("reference", doc_path)
|
|
166
|
+
|
|
167
|
+
parts = tuple(module_path.parts)
|
|
168
|
+
|
|
169
|
+
if parts[-1] == "__init__":
|
|
170
|
+
parts = parts[:-1]
|
|
171
|
+
doc_path = doc_path.with_name("index.md")
|
|
172
|
+
full_doc_path = full_doc_path.with_name("index.md")
|
|
173
|
+
elif parts[-1] == "__main__":
|
|
174
|
+
continue
|
|
175
|
+
|
|
176
|
+
nav[parts] = doc_path.as_posix()
|
|
177
|
+
|
|
178
|
+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
|
|
179
|
+
ident = ".".join(parts)
|
|
180
|
+
fd.write(f"::: {ident}")
|
|
181
|
+
|
|
182
|
+
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root))
|
|
183
|
+
|
|
184
|
+
with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
|
|
185
|
+
nav_file.writelines(nav.build_literate_nav())
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- [ ] **Step 2: Commit**
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
mkdir -p scripts
|
|
192
|
+
git add scripts/gen_ref_pages.py
|
|
193
|
+
git commit -m "feat: add automatic api reference generation script"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Task 4: Update Makefile and Verify
|
|
197
|
+
|
|
198
|
+
**Files:**
|
|
199
|
+
- Modify: `makefile`
|
|
200
|
+
|
|
201
|
+
- [ ] **Step 1: Add documentation targets to `makefile`**
|
|
202
|
+
|
|
203
|
+
```makefile
|
|
204
|
+
docs-serve:
|
|
205
|
+
uv run --extra docs mkdocs serve
|
|
206
|
+
|
|
207
|
+
docs-build:
|
|
208
|
+
uv run --extra docs mkdocs build
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
- [ ] **Step 2: Verify local documentation server**
|
|
212
|
+
|
|
213
|
+
Run: `make docs-serve` (and check if it starts successfully, manually stop it after check)
|
|
214
|
+
|
|
215
|
+
- [ ] **Step 3: Verify build**
|
|
216
|
+
|
|
217
|
+
Run: `make docs-build`
|
|
218
|
+
Expected: `site/` directory created with HTML files.
|
|
219
|
+
|
|
220
|
+
- [ ] **Step 4: Commit**
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
git add makefile
|
|
224
|
+
git commit -m "chore: add documentation targets to makefile"
|
|
225
|
+
```
|