Skip to content

Commit db1adaa

Browse files
authored
Move __doc__ crate to crates/doc (RustPython#6234)
* Add `__doc__` crate * Base auto-generate ci * Add dummy files * Update docs * Set codegen-units to 1 for doc db * Mark `*.inc.rs` as auto generated * Disable doctest * Reset docs
1 parent 9ce8586 commit db1adaa

File tree

15 files changed

+9702
-33
lines changed

15 files changed

+9702
-33
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vm/src/stdlib/ast/gen.rs linguist-generated -merge
55
Lib/*.py text working-tree-encoding=UTF-8 eol=LF
66
**/*.rs text working-tree-encoding=UTF-8 eol=LF
77
*.pck binary
8+
crates/rustpython_doc_db/src/*.inc.rs linguist-generated=true

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
RUST_BACKTRACE: full
114114
name: Run rust tests
115115
runs-on: ${{ matrix.os }}
116-
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 30 }}
116+
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 35 }}
117117
strategy:
118118
matrix:
119119
os: [macos-latest, ubuntu-latest, windows-latest]
@@ -239,7 +239,7 @@ jobs:
239239
RUST_BACKTRACE: full
240240
name: Run snippets and cpython tests
241241
runs-on: ${{ matrix.os }}
242-
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 30 }}
242+
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 35 }}
243243
strategy:
244244
matrix:
245245
os: [macos-latest, ubuntu-latest, windows-latest]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Update doc DB
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
python-version:
10+
description: Target python version to generate doc db for
11+
type: string
12+
default: "3.13.9"
13+
14+
defaults:
15+
run:
16+
shell: bash
17+
working-directory: ./crates/rustpython-doc
18+
19+
jobs:
20+
generate:
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
matrix:
24+
os:
25+
- ubuntu-latest
26+
- windows-latest
27+
- macos-latest
28+
steps:
29+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
30+
with:
31+
persist-credentials: false
32+
sparse-checkout: |
33+
crates/rustpython-doc
34+
35+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
36+
with:
37+
python-version: ${{ inputs.python-version }}
38+
39+
- name: Generate docs
40+
run: python ./generate.py
41+
42+
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
43+
with:
44+
name: doc-db-${{ inputs.python-version }}-${{ matrix.os }}
45+
path: "crates/rustpython-doc/generated/*.json"
46+
if-no-files-found: error
47+
retention-days: 7
48+
overwrite: true
49+
50+
merge:
51+
runs-on: ubuntu-latest
52+
needs: generate
53+
steps:
54+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
55+
with:
56+
persist-credentials: false
57+
sparse-checkout: |
58+
crates/rustpython-doc
59+
60+
- name: Download generated doc DBs
61+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
62+
with:
63+
pattern: "doc-db-${{ inputs.python-version }}-**"
64+
path: crates/rustpython-doc/generated/
65+
merge-multiple: true
66+
67+
- name: Transform JSON
68+
run: |
69+
# Merge all artifacts
70+
jq -s "add" --sort-keys generated/*.json > generated/merged.json
71+
72+
# Format merged json for the phf macro
73+
jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' generated/merged.json > generated/raw_entries.txt
74+
75+
OUTPUT_FILE='src/data.inc.rs'
76+
77+
echo -n '' > $OUTPUT_FILE
78+
79+
echo '// This file was auto-generated by `.github/workflows/update-doc-db.yml`.' >> $OUTPUT_FILE
80+
echo "// CPython version: ${{ inputs.python-version }}" >> $OUTPUT_FILE
81+
echo '// spell-checker: disable' >> $OUTPUT_FILE
82+
83+
echo '' >> $OUTPUT_FILE
84+
85+
echo "pub static DB: phf::Map<&'static str, &'static str> = phf::phf_map! {" >> $OUTPUT_FILE
86+
cat generated/raw_entries.txt >> $OUTPUT_FILE
87+
echo '};' >> $OUTPUT_FILE
88+
89+
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
90+
with:
91+
name: doc-db-${{ inputs.python-version }}
92+
path: "crates/rustpython-doc/src/data.inc.rs"
93+
if-no-files-found: error
94+
retention-days: 7
95+
overwrite: true

Cargo.lock

Lines changed: 60 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ opt-level = 3
7373
# https://github.com/rust-lang/rust/issues/92869
7474
# lto = "thin"
7575

76+
# Doesn't change often
77+
[profile.release.package.rustpython-doc]
78+
codegen-units = 1
79+
7680
[profile.bench]
7781
lto = "thin"
7882
codegen-units = 1
@@ -132,6 +136,7 @@ members = [
132136
"derive-impl",
133137
"wtf8",
134138
"wasm/lib",
139+
"crates/*",
135140
]
136141

137142
[workspace.package]
@@ -156,13 +161,14 @@ rustpython-pylib = { path = "pylib", version = "0.4.0" }
156161
rustpython-stdlib = { path = "stdlib", default-features = false, version = "0.4.0" }
157162
rustpython-sre_engine = { path = "vm/sre_engine", version = "0.4.0" }
158163
rustpython-wtf8 = { path = "wtf8", version = "0.4.0" }
159-
rustpython-doc = { git = "https://github.com/RustPython/__doc__", tag = "0.3.0", version = "0.3.0" }
164+
rustpython-doc = { path = "crates/doc", version = "0.4.0" }
160165

161166
ruff_python_parser = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
162167
ruff_python_ast = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
163168
ruff_text_size = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
164169
ruff_source_file = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
165170

171+
phf = { version = "0.13.1", default-features = false, features = ["macros"]}
166172
ahash = "0.8.12"
167173
ascii = "1.1"
168174
bitflags = "2.9.4"

crates/doc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generated/

crates/doc/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "rustpython-doc"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
repository.workspace = true
8+
license-file = "LICENSE"
9+
10+
[dependencies]
11+
phf = { workspace = true }
12+
13+
[lib]
14+
doctest = false # Crashes when true
15+
16+
[lints]
17+
workspace = true

0 commit comments

Comments
 (0)