@@ -35,8 +35,8 @@ def fetch():
35
35
"""
36
36
Fetch translations from Transifex, remove source lines.
37
37
"""
38
- if (code := call (" tx --version" , shell = True )) != 0 :
39
- sys .stderr .write (" The Transifex client app is required.\n " )
38
+ if (code := call (' tx --version' , shell = True )) != 0 :
39
+ sys .stderr .write (' The Transifex client app is required.\n ' )
40
40
exit (code )
41
41
lang = LANGUAGE
42
42
_call (f'tx pull -l { lang } --minimum-perc=1 --force --skip' )
@@ -71,12 +71,14 @@ def recreate_tx_config():
71
71
file .write (contents )
72
72
warn_about_files_to_delete ()
73
73
74
+
74
75
def warn_about_files_to_delete ():
75
76
files = list (_get_files_to_delete ())
76
77
if not files :
77
78
return
78
79
warn (f'Found { len (files )} file(s) to delete: { ", " .join (files )} .' )
79
80
81
+
80
82
def _get_files_to_delete ():
81
83
with open ('.tx/config' ) as config_file :
82
84
config = config_file .read ()
@@ -86,11 +88,13 @@ def _get_files_to_delete():
86
88
87
89
88
90
def _clone_cpython_repo (version : str ):
89
- _call (f'git clone -b { version } --single-branch https://github.com/python/cpython.git --depth 1' )
91
+ _call (
92
+ f'git clone -b { version } --single-branch https://github.com/python/cpython.git --depth 1'
93
+ )
90
94
91
95
92
96
def _build_gettext ():
93
- _call (" make -C cpython/Doc/ gettext" )
97
+ _call (' make -C cpython/Doc/ gettext' )
94
98
95
99
96
100
def _create_txconfig ():
@@ -115,7 +119,9 @@ class ResourceLanguageStatistics:
115
119
@classmethod
116
120
def from_api_entry (cls , data : transifex_api .ResourceLanguageStats ) -> Self :
117
121
return cls (
118
- name = data .id .removeprefix (f'o:python-doc:p:{ PROJECT_SLUG } :r:' ).removesuffix (f':l:{ LANGUAGE } ' ),
122
+ name = data .id .removeprefix (f'o:python-doc:p:{ PROJECT_SLUG } :r:' ).removesuffix (
123
+ f':l:{ LANGUAGE } '
124
+ ),
119
125
total_words = data .attributes ['total_words' ],
120
126
translated_words = data .attributes ['translated_words' ],
121
127
total_strings = data .attributes ['total_strings' ],
@@ -161,21 +167,23 @@ def get_number_of_translators():
161
167
def _fetch_translators () -> Generator [str , None , None ]:
162
168
for file in Path ().rglob ('*.po' ):
163
169
header = pofile (file ).header .splitlines ()
164
- for translator_record in header [header .index ('Translators:' ) + 1 :]:
170
+ for translator_record in header [header .index ('Translators:' ) + 1 :]:
165
171
translator , _year = translator_record .split (', ' )
166
172
yield translator
167
173
168
174
169
175
def _remove_bot (translators : set [str ]) -> None :
170
- translators .remove (" Transifex Bot <>" )
176
+ translators .remove (' Transifex Bot <>' )
171
177
172
178
173
179
def _eliminate_aliases (translators : set [str ]) -> set [str ]:
174
180
unique = set ()
175
181
for name in translators :
176
182
for match in unique :
177
- if (ratio := SequenceMatcher (lambda x : x in '<>@' , name , match ).ratio ()) > 0.64 :
178
- info (f"{ name } and { match } are similar ({ ratio :.3f} ). Deduplicating." )
183
+ if (
184
+ ratio := SequenceMatcher (lambda x : x in '<>@' , name , match ).ratio ()
185
+ ) > 0.64 :
186
+ info (f'{ name } and { match } are similar ({ ratio :.3f} ). Deduplicating.' )
179
187
break
180
188
else :
181
189
unique .add (name )
@@ -184,10 +192,12 @@ def _eliminate_aliases(translators: set[str]) -> set[str]:
184
192
185
193
def language_switcher (entry : ResourceLanguageStatistics ) -> bool :
186
194
language_switcher_resources_prefixes = ('bugs' , 'tutorial' , 'library--functions' )
187
- return any (entry .name .startswith (prefix ) for prefix in language_switcher_resources_prefixes )
195
+ return any (
196
+ entry .name .startswith (prefix ) for prefix in language_switcher_resources_prefixes
197
+ )
188
198
189
199
190
- if __name__ == " __main__" :
200
+ if __name__ == ' __main__' :
191
201
RUNNABLE_SCRIPTS = ('fetch' , 'recreate_tx_config' , 'warn_about_files_to_delete' )
192
202
193
203
parser = ArgumentParser ()
0 commit comments