Skip to content

Commit b30686d

Browse files
committed
Fix tx config recreation, move files
1 parent 3692f9c commit b30686d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+195
-407
lines changed

.tx/config

+150-149
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

library/email_util.po

-222
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

manage_translation.py

+45-36
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
from argparse import ArgumentParser
1515
import os
16+
from contextlib import chdir
1617
from dataclasses import dataclass
1718
from difflib import SequenceMatcher
1819
from itertools import combinations
1920
from pathlib import Path
20-
from re import match
2121
from subprocess import call
2222
import sys
23-
from textwrap import dedent
23+
from tempfile import TemporaryDirectory
2424
from typing import Self, Generator, Iterable
2525
from warnings import warn
2626

@@ -48,46 +48,55 @@ def fetch():
4848

4949

5050
PROJECT_SLUG = 'python-newest'
51+
VERSION = '3.12'
5152

5253

5354
def recreate_tx_config():
5455
"""
5556
Regenerate Transifex client config for all resources.
5657
"""
57-
resources = _get_resources()
58-
with open('.tx/config', 'w') as config:
59-
config.write('[main]\nhost = https://www.transifex.com\n')
60-
for resource in resources:
61-
slug = resource.slug
62-
file_filter = _denormalize_resource_name(slug)
63-
64-
config.write(
65-
dedent(
66-
f'''
67-
[o:python-doc:p:{PROJECT_SLUG}:r:{slug}]
68-
file_filter = {file_filter}
69-
source_file = pot/{file_filter}t
70-
type = PO
71-
minimum_perc = 0
72-
'''
73-
)
74-
)
75-
76-
77-
def _denormalize_resource_name(slug):
78-
"""
79-
Reversion of transifex.normalize_resource_name in sphinx-intl
80-
https://github.com/sphinx-doc/sphinx-intl/blob/c327016e394903966ab966fe49f58bcaa70588af/sphinx_intl/transifex.py#L45-L56
81-
"""
82-
name = {'glossary_': 'glossary'}.get(slug, slug)
83-
if '--' in slug:
84-
directory, file_name = name.split('--')
85-
if match(r'\d+_\d+', file_name): # whatsnew
86-
file_name = file_name.replace('_', '.')
87-
file_filter = f'{directory}/{file_name}.po'
88-
else:
89-
file_filter = f'{name}.po'
90-
return file_filter
58+
with TemporaryDirectory() as directory:
59+
with chdir(directory):
60+
_clone_cpython_repo(VERSION)
61+
_build_gettext()
62+
with chdir(Path(directory) / 'cpython/Doc/locales'):
63+
_create_txconfig()
64+
_update_txconfig_resources()
65+
with open('.tx/config', 'r') as file:
66+
contents = file.read()
67+
contents = contents.replace('./<lang>/LC_MESSAGES/', '')
68+
with open('.tx/config', 'w') as file:
69+
file.write(contents)
70+
71+
72+
def _clone_cpython_repo(version: str):
73+
if (status := call(
74+
f'git clone -b {version} --single-branch https://github.com/python/cpython.git --depth 1', shell=True
75+
)) != 0:
76+
exit(status)
77+
78+
79+
def _build_gettext():
80+
if (status := call(
81+
"make -C cpython/Doc/ "
82+
"ALLSPHINXOPTS='-E -b gettext -D gettext_compact=0 -d build/.doctrees . locales/pot' build",
83+
shell=True,
84+
)) != 0:
85+
exit(status)
86+
87+
88+
def _create_txconfig():
89+
if (status := call('sphinx-intl create-txconfig', shell=True)) != 0:
90+
exit(status)
91+
92+
93+
def _update_txconfig_resources():
94+
if (status := call(
95+
f'sphinx-intl update-txconfig-resources --transifex-organization-name python-doc '
96+
f'--transifex-project-name={PROJECT_SLUG} --locale-dir . --pot-dir pot',
97+
shell=True,
98+
)) != 0:
99+
exit(status)
91100

92101

93102
@dataclass

0 commit comments

Comments
 (0)