1
- """Tool to merge cpython pot files to python-docs-fr po files for a
1
+ """Tool to merge cpython pot files to python-docs-tr po files for a
2
2
given branch.
3
+
4
+ A CPython clone present in the venv/ directory is required if the --cpython_repo is not specified.
5
+
6
+ This script is run automatically by the GitHub Actions workflow every first day of the month.
3
7
"""
4
8
5
9
import re
6
10
import shutil
7
- from pathlib import Path
8
11
import argparse
9
12
import subprocess
13
+ from pathlib import Path
10
14
from subprocess import PIPE
11
15
from tqdm import tqdm
12
16
@@ -80,9 +84,7 @@ def update_makefile(cpython_repo: Path) -> None:
80
84
used to generate the `po` files.
81
85
"""
82
86
makefile = Path ("Makefile" ).read_text (encoding = "UTF-8" )
83
- head = run (
84
- "git" , "-C" , cpython_repo , "rev-parse" , "HEAD" , stdout = PIPE
85
- ).stdout .strip ()
87
+ head = run ("git" , "-C" , cpython_repo , "rev-parse" , "HEAD" , stdout = PIPE ).stdout .strip ()
86
88
makefile = re .sub (
87
89
"^CPYTHON_CURRENT_COMMIT :=.*$" ,
88
90
f"CPYTHON_CURRENT_COMMIT := { head } " ,
@@ -93,6 +95,23 @@ def update_makefile(cpython_repo: Path) -> None:
93
95
run ("git" , "add" , "Makefile" )
94
96
95
97
98
+ def git_add_relevant_files ():
99
+ """Add only files with relevant modifications.
100
+
101
+ This only add files with actual modifications, not just metadata
102
+ modifications, to avoid noise in history.
103
+ """
104
+ modified_files = run ("git" , "ls-files" , "-m" , stdout = PIPE ).stdout .split ("\n " )
105
+ modified_po_files = [line for line in modified_files if line .endswith (".po" )]
106
+ for file in modified_po_files :
107
+ diff = run ("git" , "diff" , "-U0" , file , stdout = PIPE ).stdout
108
+ if len (diff .split ("\n " )) > 8 :
109
+ run ("git" , "add" , file )
110
+ else :
111
+ run ("git" , "checkout" , "--" , file )
112
+ run ("rm" , "-f" , "whatsnew/changelog.po" ) # We don't translate this file.
113
+
114
+
96
115
def main ():
97
116
args = parse_args ()
98
117
setup_repo (args .cpython_repo , args .branch )
@@ -101,21 +120,16 @@ def main():
101
120
cwd = args .cpython_repo / "Doc" ,
102
121
)
103
122
pot_path = args .cpython_repo / "pot"
104
- upstream = {
105
- file .relative_to (pot_path ).with_suffix (".po" )
106
- for file in pot_path .glob ("**/*.pot" )
107
- }
108
- downstream = {
109
- Path (po )
110
- for po in run ("git" , "ls-files" , "*.po" , stdout = PIPE ).stdout .splitlines ()
111
- }
123
+ upstream = {file .relative_to (pot_path ).with_suffix (".po" ) for file in pot_path .glob ("**/*.pot" )}
124
+ downstream = {Path (po ) for po in run ("git" , "ls-files" , "*.po" , stdout = PIPE ).stdout .splitlines ()}
112
125
copy_new_files (upstream - downstream , pot_path = pot_path )
113
126
update_known_files (upstream & downstream , pot_path = pot_path )
114
127
remove_old_files (downstream - upstream )
115
128
clean_paths ((upstream - downstream ) | (upstream & downstream ))
116
129
shutil .rmtree (pot_path )
117
- run ("powrap" , "-m " )
130
+ run ("powrap" , "*.po" , "*/*.po " )
118
131
update_makefile (args .cpython_repo )
132
+ git_add_relevant_files ()
119
133
120
134
121
135
if __name__ == "__main__" :
0 commit comments