Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8424d07

Browse files
authored
Update merge.py
1 parent886a336 commit8424d07

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

‎merge.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
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
22
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.
37
"""
48

59
importre
610
importshutil
7-
frompathlibimportPath
811
importargparse
912
importsubprocess
13+
frompathlibimportPath
1014
fromsubprocessimportPIPE
1115
fromtqdmimporttqdm
1216

@@ -80,9 +84,7 @@ def update_makefile(cpython_repo: Path) -> None:
8084
used to generate the `po` files.
8185
"""
8286
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()
8688
makefile=re.sub(
8789
"^CPYTHON_CURRENT_COMMIT :=.*$",
8890
f"CPYTHON_CURRENT_COMMIT :={head}",
@@ -93,6 +95,23 @@ def update_makefile(cpython_repo: Path) -> None:
9395
run("git","add","Makefile")
9496

9597

98+
defgit_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= [lineforlineinmodified_filesifline.endswith(".po")]
106+
forfileinmodified_po_files:
107+
diff=run("git","diff","-U0",file,stdout=PIPE).stdout
108+
iflen(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+
96115
defmain():
97116
args=parse_args()
98117
setup_repo(args.cpython_repo,args.branch)
@@ -101,21 +120,16 @@ def main():
101120
cwd=args.cpython_repo/"Doc",
102121
)
103122
pot_path=args.cpython_repo/"pot"
104-
upstream= {
105-
file.relative_to(pot_path).with_suffix(".po")
106-
forfileinpot_path.glob("**/*.pot")
107-
}
108-
downstream= {
109-
Path(po)
110-
forpoinrun("git","ls-files","*.po",stdout=PIPE).stdout.splitlines()
111-
}
123+
upstream= {file.relative_to(pot_path).with_suffix(".po")forfileinpot_path.glob("**/*.pot")}
124+
downstream= {Path(po)forpoinrun("git","ls-files","*.po",stdout=PIPE).stdout.splitlines()}
112125
copy_new_files(upstream-downstream,pot_path=pot_path)
113126
update_known_files(upstream&downstream,pot_path=pot_path)
114127
remove_old_files(downstream-upstream)
115128
clean_paths((upstream-downstream)| (upstream&downstream))
116129
shutil.rmtree(pot_path)
117-
run("powrap","-m")
130+
run("powrap","*.po","*/*.po")
118131
update_makefile(args.cpython_repo)
132+
git_add_relevant_files()
119133

120134

121135
if__name__=="__main__":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp