Skip to content

Commit c19aca3

Browse files
authored
Add files via upload
1 parent 42e1f74 commit c19aca3

File tree

4 files changed

+280
-0
lines changed

4 files changed

+280
-0
lines changed

.github/workflows/po-lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Linting Workflow
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
push:
7+
branches:
8+
- '*'
9+
workflow_dispatch:
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
version: [ '3.14' ]
18+
continue-on-error: true
19+
steps:
20+
- uses: actions/setup-python@master
21+
with:
22+
python-version: 3
23+
- run: pip install sphinx-lint
24+
- uses: actions/checkout@master
25+
with:
26+
ref: ${{ matrix.version }}
27+
- uses: rffontenelle/[email protected]
28+
- run: sphinx-lint

.github/workflows/test-build.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Test Build Workflow
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
push:
7+
branches:
8+
- '*'
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-translation:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
version: [ '3.14' ]
18+
format: [ html, latex, epub ]
19+
steps:
20+
- uses: actions/setup-python@master
21+
with:
22+
python-version: 3.12 # pinned for Sphinx 3.4.3 to build 3.10
23+
- uses: actions/checkout@master
24+
with:
25+
repository: python/cpython
26+
ref: ${{ matrix.version }}
27+
- run: make venv
28+
working-directory: ./Doc
29+
- uses: actions/checkout@master
30+
with:
31+
ref: ${{ matrix.version }}
32+
path: Doc/locales/XX/LC_MESSAGES
33+
- run: git pull
34+
working-directory: ./Doc/locales/XX/LC_MESSAGES
35+
- uses: sphinx-doc/[email protected]
36+
- run: make -e SPHINXOPTS="--color -D language='XX' -W --keep-going" ${{ matrix.format }}
37+
working-directory: ./Doc
38+
- uses: actions/upload-artifact@master
39+
if: success() || failure()
40+
with:
41+
name: build-${{ matrix.version }}-${{ matrix.format }}
42+
path: Doc/build/${{ matrix.format }}
43+
44+
output-pdf:
45+
runs-on: ubuntu-latest
46+
strategy:
47+
matrix:
48+
version: [ '3.14' ]
49+
needs: [ 'build-translation' ]
50+
steps:
51+
- uses: actions/download-artifact@master
52+
with:
53+
name: build-${{ matrix.version }}-latex
54+
- run: sudo apt-get update
55+
- run: sudo apt-get install -y latexmk texlive-xetex fonts-freefont-otf xindy
56+
- run: make
57+
- uses: actions/upload-artifact@master
58+
with:
59+
name: build-${{ matrix.version }}-pdf
60+
path: ./*.pdf
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Pull Translations from Transifex
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update-translation:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
version: [ '3.14' ]
17+
steps:
18+
- uses: styfle/cancel-workflow-action@main
19+
with:
20+
access_token: ${{ secrets.GITHUB_TOKEN }}
21+
- uses: actions/setup-python@master
22+
with:
23+
python-version: 3
24+
- name: Install Dependencies
25+
run: |
26+
sudo apt-get install -y gettext
27+
pip install requests cogapp polib transifex-python sphinx-intl blurb six
28+
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
29+
working-directory: /usr/local/bin
30+
- uses: actions/checkout@master
31+
with:
32+
ref: ${{ matrix.version }}
33+
fetch-depth: 0
34+
- run: curl -O https://raw.githubusercontent.com/python-docs-translations/transifex-automations/master/sample-workflows/transifex-util.py
35+
- run: chmod +x transifex-util.py
36+
- run: ./transifex-util.py recreate_tx_config --language XX --project-slug python-newest --version ${{ matrix.version }}
37+
env:
38+
TX_TOKEN: ${{ secrets.TX_TOKEN }}
39+
- run: ./transifex-util.py fetch --language XX --project-slug python-newest --version ${{ matrix.version }}
40+
env:
41+
TX_TOKEN: ${{ secrets.TX_TOKEN }}
42+
- run: ./transifex-util.py delete_obsolete_files --language XX --project-slug python-newest --version ${{ matrix.version }}
43+
- name: Set up Git
44+
run: |
45+
git config --local user.email [email protected]
46+
git config --local user.name "GitHub Action's update-translation job"
47+
- name: Filter files
48+
run: |
49+
! git diff -I'^"POT-Creation-Date: ' \
50+
-I'^"Language-Team: ' \
51+
-I'^# ' -I'^"Last-Translator: ' \
52+
--exit-code \
53+
&& echo "SIGNIFICANT_CHANGES=1" >> $GITHUB_ENV || exit 0
54+
- run: git add . ':!transifex-util.py'
55+
- run: git commit -m 'Update translation from Transifex'
56+
if: env.SIGNIFICANT_CHANGES
57+
- uses: ad-m/github-push-action@master
58+
if: env.SIGNIFICANT_CHANGES
59+
with:
60+
branch: ${{ matrix.version }}
61+
github_token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env python
2+
#
3+
# This python file contains utility functions to manage a Python docs translation
4+
# with Transifex.
5+
#
6+
# This file is maintained at: https://github.com/python-docs-translations/transifex-automations/blob/main/sample-workflows/transifex-util.py
7+
8+
import configparser
9+
from argparse import ArgumentParser
10+
import os
11+
from contextlib import chdir
12+
from pathlib import Path
13+
from subprocess import call
14+
import sys
15+
from tempfile import TemporaryDirectory
16+
17+
18+
def fetch():
19+
"""
20+
Fetch translations from Transifex, remove source lines.
21+
"""
22+
if (code := call("tx --version", shell=True)) != 0:
23+
sys.stderr.write("The Transifex client app is required.\n")
24+
exit(code)
25+
lang = LANGUAGE
26+
if PULL_OPTIONS:
27+
_call(f"tx pull -l {lang} --force {PULL_OPTIONS}") # XXX Do we pull everything?
28+
else:
29+
_call(f"tx pull -l {lang} --force")
30+
for file in Path().rglob("*.po"):
31+
_call(f"msgcat --no-location -o {file} {file}")
32+
33+
34+
def _call(command: str):
35+
if (return_code := call(command, shell=True)) != 0:
36+
exit(return_code)
37+
38+
39+
def recreate_tx_config():
40+
"""
41+
Regenerate Transifex client config for all resources.
42+
"""
43+
with TemporaryDirectory() as directory:
44+
with chdir(directory):
45+
_clone_cpython_repo(VERSION)
46+
_build_gettext()
47+
with chdir(Path(directory) / "cpython/Doc/build"):
48+
_create_txconfig()
49+
_update_txconfig_resources()
50+
with open(".tx/config", "r") as file:
51+
contents = file.read()
52+
contents = contents.replace("./<lang>/LC_MESSAGES/", "")
53+
54+
os.makedirs(".tx", exist_ok=True)
55+
with open(".tx/config", "w") as file:
56+
file.write(contents)
57+
58+
59+
def delete_obsolete_files():
60+
files_to_delete = list(_get_files_to_delete())
61+
if not files_to_delete:
62+
return
63+
else:
64+
for file in files_to_delete:
65+
print(f"Removing {file}")
66+
os.remove(file)
67+
_call(f'git rm --quiet "{file}"')
68+
69+
70+
def _get_files_to_delete():
71+
with open(".tx/config") as config_file:
72+
config = config_file.read()
73+
for file in Path().rglob("*.po"):
74+
if os.fsdecode(file) not in config:
75+
yield os.fsdecode(file)
76+
77+
78+
def _clone_cpython_repo(version: str):
79+
_call(
80+
f"git clone -b {version} --single-branch https://github.com/python/cpython.git --depth 1"
81+
)
82+
83+
84+
def _build_gettext():
85+
_call("make -C cpython/Doc/ gettext")
86+
87+
88+
def _create_txconfig():
89+
_call("sphinx-intl create-txconfig")
90+
91+
92+
def _update_txconfig_resources():
93+
_call(
94+
f"sphinx-intl update-txconfig-resources --transifex-organization-name python-doc "
95+
f"--transifex-project-name {PROJECT_SLUG} --locale-dir . --pot-dir gettext"
96+
)
97+
98+
99+
def _get_tx_token() -> str:
100+
if os.path.exists(".tx/api-key"):
101+
with open(".tx/api-key") as f:
102+
return f.read()
103+
104+
config = configparser.ConfigParser()
105+
config.read(os.path.expanduser("~/.transifexrc"))
106+
try:
107+
return config["https://www.transifex.com"]["token"]
108+
except KeyError:
109+
pass
110+
111+
return os.getenv("TX_TOKEN", "")
112+
113+
114+
if __name__ == "__main__":
115+
RUNNABLE_SCRIPTS = ("fetch", "recreate_tx_config", "delete_obsolete_files")
116+
117+
parser = ArgumentParser()
118+
parser.add_argument("cmd", choices=RUNNABLE_SCRIPTS)
119+
parser.add_argument("--language", required=True)
120+
parser.add_argument("--project-slug", required=True)
121+
parser.add_argument("--version", required=True)
122+
parser.add_argument("--pull-options", required=False)
123+
124+
options = parser.parse_args()
125+
126+
LANGUAGE = options.language
127+
PROJECT_SLUG = options.project_slug
128+
VERSION = options.version
129+
PULL_OPTIONS = options.pull_options
130+
131+
globals()[options.cmd]()

0 commit comments

Comments
 (0)