Skip to content

Commit 90717e5

Browse files
doc db to include types.* (RustPython#6391)
* Add types.* for doc/generate.py * udpate-doc-db workflow * Update doc DB for CPython 3.13.9 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent c71c78c commit 90717e5

File tree

3 files changed

+591
-15
lines changed

3 files changed

+591
-15
lines changed

.github/workflows/update-doc-db.yml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Update doc DB
22

33
permissions:
4-
contents: read
4+
contents: write
55

66
on:
77
workflow_dispatch:
@@ -10,11 +10,14 @@ on:
1010
description: Target python version to generate doc db for
1111
type: string
1212
default: "3.13.9"
13+
ref:
14+
description: Branch to commit to (leave empty for current branch)
15+
type: string
16+
default: ""
1317

1418
defaults:
1519
run:
1620
shell: bash
17-
working-directory: ./crates/rustpython-doc
1821

1922
jobs:
2023
generate:
@@ -30,19 +33,19 @@ jobs:
3033
with:
3134
persist-credentials: false
3235
sparse-checkout: |
33-
crates/rustpython-doc
36+
crates/doc
3437
3538
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
3639
with:
3740
python-version: ${{ inputs.python-version }}
3841

3942
- name: Generate docs
40-
run: python ./generate.py
43+
run: python crates/doc/generate.py
4144

4245
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
4346
with:
4447
name: doc-db-${{ inputs.python-version }}-${{ matrix.os }}
45-
path: "crates/rustpython-doc/generated/*.json"
48+
path: "crates/doc/generated/*.json"
4649
if-no-files-found: error
4750
retention-days: 7
4851
overwrite: true
@@ -53,26 +56,25 @@ jobs:
5356
steps:
5457
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5558
with:
56-
persist-credentials: false
57-
sparse-checkout: |
58-
crates/rustpython-doc
59+
ref: ${{ inputs.ref || github.ref }}
60+
token: ${{ secrets.AUTO_COMMIT_PAT }}
5961

6062
- name: Download generated doc DBs
6163
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
6264
with:
6365
pattern: "doc-db-${{ inputs.python-version }}-**"
64-
path: crates/rustpython-doc/generated/
66+
path: crates/doc/generated/
6567
merge-multiple: true
6668

6769
- name: Transform JSON
6870
run: |
6971
# Merge all artifacts
70-
jq -s "add" --sort-keys generated/*.json > generated/merged.json
72+
jq -s "add" --sort-keys crates/doc/generated/*.json > crates/doc/generated/merged.json
7173
7274
# Format merged json for the phf macro
73-
jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' generated/merged.json > generated/raw_entries.txt
75+
jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' crates/doc/generated/merged.json > crates/doc/generated/raw_entries.txt
7476
75-
OUTPUT_FILE='src/data.inc.rs'
77+
OUTPUT_FILE='crates/doc/src/data.inc.rs'
7678
7779
echo -n '' > $OUTPUT_FILE
7880
@@ -83,13 +85,24 @@ jobs:
8385
echo '' >> $OUTPUT_FILE
8486
8587
echo "pub static DB: phf::Map<&'static str, &'static str> = phf::phf_map! {" >> $OUTPUT_FILE
86-
cat generated/raw_entries.txt >> $OUTPUT_FILE
88+
cat crates/doc/generated/raw_entries.txt >> $OUTPUT_FILE
8789
echo '};' >> $OUTPUT_FILE
8890
8991
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
9092
with:
9193
name: doc-db-${{ inputs.python-version }}
92-
path: "crates/rustpython-doc/src/data.inc.rs"
94+
path: "crates/doc/src/data.inc.rs"
9395
if-no-files-found: error
9496
retention-days: 7
9597
overwrite: true
98+
99+
- name: Commit and push (non-main branches only)
100+
if: github.ref != 'refs/heads/main' && inputs.ref != 'main'
101+
run: |
102+
git config user.name "github-actions[bot]"
103+
git config user.email "github-actions[bot]@users.noreply.github.com"
104+
if [ -n "$(git status --porcelain)" ]; then
105+
git add crates/doc/src/data.inc.rs
106+
git commit -m "Update doc DB for CPython ${{ inputs.python-version }}"
107+
git push
108+
fi

crates/doc/generate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ def find_doc_entries() -> "Iterable[DocEntry]":
194194
type(str().__iter__()),
195195
type(tuple().__iter__()),
196196
]
197+
198+
# Add types from the types module (e.g., ModuleType, FunctionType, etc.)
199+
for name in dir(types):
200+
if name.startswith("_"):
201+
continue
202+
obj = getattr(types, name)
203+
if isinstance(obj, type):
204+
builtin_types.append(obj)
205+
197206
for typ in builtin_types:
198207
parts = ("builtins", typ.__name__)
199208
yield DocEntry(parts, pydoc._getowndoc(typ))
@@ -204,7 +213,7 @@ def main():
204213
docs = {
205214
entry.key: entry.doc
206215
for entry in find_doc_entries()
207-
if entry.raw_doc is not None
216+
if entry.raw_doc is not None and isinstance(entry.raw_doc, str)
208217
}
209218
dumped = json.dumps(docs, sort_keys=True, indent=4)
210219
OUTPUT_FILE.write_text(dumped)

0 commit comments

Comments
 (0)