-
Notifications
You must be signed in to change notification settings - Fork 3
Add sample workflows #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rffontenelle
merged 8 commits into
python-docs-translations:main
from
StanFromIreland:add-sample-workflows
May 17, 2025
Merged
Add sample workflows #130
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f8ea56
Add sample workflows
StanFromIreland 5ba0a5f
Bump to daily
StanFromIreland 89db032
Add TX workflow
StanFromIreland fa6ffc3
cleanup
StanFromIreland 53f1817
Changes
StanFromIreland 03f0a64
Clean up unused stuff
StanFromIreland d015f17
git rm files
StanFromIreland c592eb7
Bump py version and style
StanFromIreland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Linting Workflow | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
push: | ||
branches: | ||
- '*' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: [ '3.14' ] | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/setup-python@master | ||
with: | ||
python-version: 3 | ||
- run: pip install sphinx-lint | ||
- uses: actions/checkout@master | ||
with: | ||
ref: ${{ matrix.version }} | ||
- uses: rffontenelle/[email protected] | ||
StanFromIreland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- run: sphinx-lint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Test Build Workflow | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
push: | ||
branches: | ||
- '*' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-translation: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: [ '3.14' ] | ||
format: [ html, latex ] | ||
steps: | ||
- uses: actions/setup-python@master | ||
with: | ||
python-version: 3.12 # pinned for Sphinx 3.4.3 to build 3.10 | ||
- uses: actions/checkout@master | ||
with: | ||
repository: python/cpython | ||
ref: ${{ matrix.version }} | ||
- run: make venv | ||
working-directory: ./Doc | ||
- uses: actions/checkout@master | ||
with: | ||
ref: ${{ matrix.version }} | ||
path: Doc/locales/XX/LC_MESSAGES | ||
StanFromIreland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- run: git pull | ||
working-directory: ./Doc/locales/XX/LC_MESSAGES | ||
- uses: sphinx-doc/[email protected] | ||
- run: make -e SPHINXOPTS="--color -D language='XX' -W --keep-going" ${{ matrix.format }} | ||
StanFromIreland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
working-directory: ./Doc | ||
- uses: actions/upload-artifact@master | ||
if: success() || failure() | ||
with: | ||
name: build-${{ matrix.version }}-${{ matrix.format }} | ||
path: Doc/build/${{ matrix.format }} | ||
|
||
output-pdf: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
version: [ '3.14' ] | ||
needs: [ 'build-translation' ] | ||
steps: | ||
- uses: actions/download-artifact@master | ||
with: | ||
name: build-${{ matrix.version }}-latex | ||
- run: sudo apt-get update | ||
- run: sudo apt-get install -y latexmk texlive-xetex fonts-freefont-otf xindy | ||
- run: make | ||
- uses: actions/upload-artifact@master | ||
with: | ||
name: build-${{ matrix.version }}-pdf | ||
path: . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Pull Translations from Transifex | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
push: | ||
branches: | ||
- '*' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update-translation: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: [ '3.14' ] | ||
steps: | ||
- uses: styfle/cancel-workflow-action@main | ||
with: | ||
access_token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/setup-python@master | ||
with: | ||
python-version: 3 | ||
- name: Install Dependencies | ||
run: | | ||
sudo apt-get install -y gettext | ||
pip install requests cogapp polib transifex-python sphinx-intl blurb six | ||
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash | ||
working-directory: /usr/local/bin | ||
- uses: actions/checkout@master | ||
with: | ||
ref: ${{ matrix.version }} | ||
fetch-depth: 0 | ||
- run: curl https://raw.githubusercontent.com/python-docs-translations/transifex-automation/master/sample-workflows/transifex-util.py | ||
- run: ./manage_translation.py recreate_tx_config --language XX --project-slug python-newest --version 3.13 | ||
env: | ||
TX_TOKEN: ${{ secrets.TX_TOKEN }} | ||
- run: ./manage_translation.py fetch --language XX --project-slug python-newest --version 3.13 | ||
env: | ||
TX_TOKEN: ${{ secrets.TX_TOKEN }} | ||
- run: ./manage_translation.py delete_obsolete_files --language XX --project-slug python-newest --version 3.13 | ||
- name: Set up Git | ||
run: | | ||
git config --local user.email [email protected] | ||
git config --local user.name "GitHub Action's update-translation job" | ||
- name: Filter files | ||
run: | | ||
! git diff -I'^"POT-Creation-Date: ' \ | ||
-I'^"Language-Team: ' \ | ||
-I'^# ' -I'^"Last-Translator: ' \ | ||
--exit-code \ | ||
&& echo "SIGNIFICANT_CHANGES=1" >> $GITHUB_ENV || exit 0 | ||
- run: git add . | ||
StanFromIreland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- run: git commit -m 'Update translation from Transifex' | ||
if: env.SIGNIFICANT_CHANGES | ||
- uses: ad-m/github-push-action@master | ||
if: env.SIGNIFICANT_CHANGES | ||
with: | ||
branch: ${{ matrix.version }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/usr/bin/env python | ||
# | ||
# This python file contains utility scripts to manage Python docs translation | ||
# on Transifex. | ||
# | ||
# Inspired by django-docs-translations script by claudep. | ||
import configparser | ||
from argparse import ArgumentParser | ||
import os | ||
from contextlib import chdir | ||
from pathlib import Path | ||
from subprocess import call | ||
import sys | ||
from tempfile import TemporaryDirectory | ||
|
||
from polib import pofile | ||
from transifex.api import transifex_api | ||
|
||
|
||
def fetch(): | ||
""" | ||
Fetch translations from Transifex, remove source lines. | ||
""" | ||
if (code := call("tx --version", shell=True)) != 0: | ||
sys.stderr.write("The Transifex client app is required.\n") | ||
exit(code) | ||
lang = LANGUAGE | ||
_call(f'tx pull -l {lang} --minimum-perc=1 --force --skip') | ||
for file in Path().rglob('*.po'): | ||
_call(f'msgcat --no-location -o {file} {file}') | ||
|
||
def _call(command: str): | ||
if (return_code := call(command, shell=True)) != 0: | ||
exit(return_code) | ||
|
||
def recreate_tx_config(): | ||
""" | ||
Regenerate Transifex client config for all resources. | ||
""" | ||
with TemporaryDirectory() as directory: | ||
with chdir(directory): | ||
_clone_cpython_repo(VERSION) | ||
_build_gettext() | ||
with chdir(Path(directory) / 'cpython/Doc/build'): | ||
_create_txconfig() | ||
_update_txconfig_resources() | ||
with open('.tx/config', 'r') as file: | ||
contents = file.read() | ||
contents = contents.replace('./<lang>/LC_MESSAGES/', '') | ||
with open('.tx/config', 'w') as file: | ||
file.write(contents) | ||
|
||
def delete_obsolete_files(): | ||
files_to_delete = list(_get_files_to_delete()) | ||
if not files_to_delete: | ||
return | ||
else: | ||
for file in files_to_delete: | ||
print(f"Removing {file}") | ||
os.remove(file) | ||
StanFromIreland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_call(f'git rm --quiet "{file}"') | ||
|
||
def _get_files_to_delete(): | ||
with open('.tx/config') as config_file: | ||
config = config_file.read() | ||
for file in Path().rglob('*.po'): | ||
if os.fsdecode(file) not in config: | ||
yield os.fsdecode(file) | ||
|
||
def _clone_cpython_repo(version: str): | ||
_call(f'git clone -b {version} --single-branch https://github.com/python/cpython.git --depth 1') | ||
|
||
def _build_gettext(): | ||
_call("make -C cpython/Doc/ gettext") | ||
|
||
def _create_txconfig(): | ||
_call('sphinx-intl create-txconfig') | ||
|
||
def _update_txconfig_resources(): | ||
_call( | ||
f'sphinx-intl update-txconfig-resources --transifex-organization-name python-doc ' | ||
f'--transifex-project-name {PROJECT_SLUG} --locale-dir . --pot-dir gettext' | ||
) | ||
|
||
def _get_tx_token() -> str: | ||
if os.path.exists('.tx/api-key'): | ||
with open('.tx/api-key') as f: | ||
return f.read() | ||
|
||
config = configparser.ConfigParser() | ||
config.read(os.path.expanduser("~/.transifexrc")) | ||
try: | ||
return config["https://www.transifex.com"]["token"] | ||
except KeyError: | ||
pass | ||
|
||
return os.getenv('TX_TOKEN', '') | ||
|
||
if __name__ == "__main__": | ||
RUNNABLE_SCRIPTS = ('fetch', 'recreate_tx_config', 'delete_obsolete_files') | ||
|
||
parser = ArgumentParser() | ||
parser.add_argument('cmd', choices=RUNNABLE_SCRIPTS) | ||
parser.add_argument('--language', required=True) | ||
parser.add_argument('--project-slug', required=True) | ||
parser.add_argument('--version', required=True) | ||
|
||
options = parser.parse_args() | ||
|
||
LANGUAGE = options.language | ||
PROJECT_SLUG = options.project_slug | ||
VERSION = options.version | ||
|
||
globals()[options.cmd]() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.