Skip to content

Commit 2604808

Browse files
committed
Use RTD instead of re-inventing the wheel
1 parent b0bd50f commit 2604808

5 files changed

Lines changed: 82 additions & 255 deletions

File tree

.github/workflows/build-and-deploy.yml

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ name: Build and Deploy to GitHub Pages
22

33
on:
44
schedule:
5-
- cron: '0 2 * * *'
5+
- cron: '0 2 * * *'
66
push:
77
branches:
88
- 3.14
99
workflow_dispatch:
1010

1111
permissions:
12-
contents: write
12+
contents: read
13+
pages: write
14+
id-token: write
1315

1416
concurrency:
1517
group: "pages"
@@ -24,41 +26,52 @@ jobs:
2426
with:
2527
repository: python/cpython
2628
ref: v3.14.6
27-
29+
2830
- name: Set up Python
2931
uses: actions/setup-python@v4
3032
with:
3133
python-version: '3.12'
32-
34+
3335
- name: Setup virtual environment
3436
run: make venv
3537
working-directory: ./Doc
36-
38+
3739
- name: Checkout translation files
3840
uses: actions/checkout@v4
3941
with:
4042
path: Doc/locales/fa/LC_MESSAGES
4143

42-
- name: Install gettext
43-
run: sudo apt-get install -y gettext
44+
- name: Strip stray fuzzy markers
45+
run: python3 Doc/locales/fa/LC_MESSAGES/scripts/strip_fuzzy.py $(find Doc/locales/fa/LC_MESSAGES -name "*.po" -not -path "*/.git/*")
4446

4547
- name: Compile .po files to .mo
4648
run: |
47-
find Doc/locales/fa/LC_MESSAGES -name "*.po" | while read f; do
49+
find Doc/locales/fa/LC_MESSAGES -name "*.po" -not -path "*/.git/*" | while read f; do
4850
msgfmt "$f" -o "${f%.po}.mo"
4951
done
5052
5153
- name: Setup problem matcher
5254
uses: sphinx-doc/github-problem-matcher@v1.1
53-
55+
5456
- name: Build documentation
5557
run: make -e SPHINXOPTS="--color -D language='fa' -D gettext_allow_fuzzy_translations=1 --keep-going" html
5658
working-directory: ./Doc
57-
58-
- name: Deploy to gh-pages
59-
uses: peaceiris/actions-gh-pages@v4
59+
60+
- name: Setup Pages
61+
uses: actions/configure-pages@v4
62+
63+
- name: Upload artifact
64+
uses: actions/upload-pages-artifact@v3
6065
with:
61-
github_token: ${{ secrets.GITHUB_TOKEN }}
62-
publish_dir: Doc/build/html
63-
keep_files: true
64-
enable_jekyll: false
66+
path: Doc/build/html
67+
68+
deploy:
69+
environment:
70+
name: github-pages
71+
url: ${{ steps.deployment.outputs.page_url }}
72+
runs-on: ubuntu-latest
73+
needs: build
74+
steps:
75+
- name: Deploy to GitHub Pages
76+
id: deployment
77+
uses: actions/deploy-pages@v4

.github/workflows/build-docs-preview.yml

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

.github/workflows/comment-docs-preview.yml

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

.readthedocs.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-24.04
5+
tools:
6+
python: "3.12"
7+
8+
commands:
9+
- git clone --depth 1 --branch v3.14.6 https://github.com/python/cpython venv/cpython
10+
- pip install -r venv/cpython/Doc/requirements.txt
11+
- mkdir -p venv/cpython/Doc/locales/fa/LC_MESSAGES
12+
- cp --parents *.po venv/cpython/Doc/locales/fa/LC_MESSAGES/
13+
- find */ -name "*.po" -not -path "venv/*" | xargs -I{} cp --parents {} venv/cpython/Doc/locales/fa/LC_MESSAGES/
14+
- find venv/cpython/Doc/locales/fa/LC_MESSAGES -name "*.po" | xargs python3 scripts/strip_fuzzy.py
15+
- find venv/cpython/Doc/locales/fa/LC_MESSAGES -name "*.po" | while read f; do python venv/cpython/Tools/i18n/msgfmt.py -o "${f%.po}.mo" "$f"; done
16+
- python -m sphinx -T -j auto -b html
17+
-d $READTHEDOCS_OUTPUT/doctrees
18+
-D language=fa
19+
-D locale_dirs=locales
20+
-D gettext_compact=0
21+
-D gettext_allow_fuzzy_translations=1
22+
-D html_theme_options.is_rtl=1
23+
venv/cpython/Doc
24+
$READTHEDOCS_OUTPUT/html

scripts/strip_fuzzy.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
"""Remove '#, fuzzy' marker lines from .po files.
3+
4+
CPython's Tools/i18n/msgfmt.py treats a stray fuzzy flag on the file
5+
header as applying to every entry in the file, silently producing an
6+
empty .mo catalog. Since our translations are complete (not actually
7+
rough drafts), we strip the marker before compiling.
8+
"""
9+
import sys
10+
11+
12+
def strip_fuzzy(path: str) -> None:
13+
with open(path, encoding="utf-8") as f:
14+
lines = f.readlines()
15+
16+
kept = [line for line in lines if not line.lstrip().startswith("#, fuzzy")]
17+
18+
if kept != lines:
19+
with open(path, "w", encoding="utf-8") as f:
20+
f.writelines(kept)
21+
22+
23+
def main() -> None:
24+
for path in sys.argv[1:]:
25+
strip_fuzzy(path)
26+
27+
28+
if __name__ == "__main__":
29+
main()

0 commit comments

Comments
 (0)