From f575086d7e2f79c053c794cb7ab1e47f0df0ad5b Mon Sep 17 00:00:00 2001 From: egeakman Date: Tue, 2 May 2023 15:26:51 +0300 Subject: [PATCH 1/2] added a script for calculating progress, translated includes/wasm-notavail.po, applied black + isort --- .pre-commit-config.yaml | 2 +- includes/wasm-notavail.po | 9 ++-- merge.py | 14 ++++-- scripts/format_check.py | 17 +++++-- scripts/progress.py | 100 ++++++++++++++++++++++++++++++++++++++ scripts/translate.py | 20 ++++++-- 6 files changed, 149 insertions(+), 13 deletions(-) create mode 100644 scripts/progress.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 236103264..cfe1db644 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,7 +27,7 @@ repos: hooks: - id: black name: Run black on Python files - args: ["--line-length=140", "--target-version=py311"] + args: ["--target-version=py311"] files: \.py$ - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/includes/wasm-notavail.po b/includes/wasm-notavail.po index d3d36b376..0146f28fb 100644 --- a/includes/wasm-notavail.po +++ b/includes/wasm-notavail.po @@ -2,23 +2,23 @@ # Copyright (C) 2001-2023, Python Software Foundation # This file is distributed under the same license as the Python package. # -#, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.11\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-03-01 00:18+0000\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2023-05-02 12:49+0300\n" "Last-Translator: \n" "Language-Team: TURKISH \n" "Language: tr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 3.2.2\n" #: includes/wasm-notavail.rst:3 msgid ":ref:`Availability `: not Emscripten, not WASI." -msgstr "" +msgstr ":ref:`Kullanılabilirlik `: Emscripten değil, WASI değil." #: includes/wasm-notavail.rst:5 msgid "" @@ -26,3 +26,6 @@ msgid "" "``wasm32-emscripten`` and ``wasm32-wasi``. See :ref:`wasm-availability` for " "more information." msgstr "" +"Bu modül WebAssembly platformları olan ``wasm32-emscripten`` ve ``wasm32-" +"wasi`` üzerinde çalışmaz veya kullanılamaz. Daha fazla bilgi için :ref:`wasm-" +"availability` sayfasına bakın." diff --git a/merge.py b/merge.py index 7db4c0b76..7fe7d63be 100644 --- a/merge.py +++ b/merge.py @@ -85,7 +85,9 @@ def update_makefile(cpython_repo: Path) -> None: used to generate the `po` files. """ makefile = Path("Makefile").read_text(encoding="UTF-8") - head = run("git", "-C", cpython_repo, "rev-parse", "HEAD", stdout=PIPE).stdout.strip() + head = run( + "git", "-C", cpython_repo, "rev-parse", "HEAD", stdout=PIPE + ).stdout.strip() makefile = re.sub( "^CPYTHON_CURRENT_COMMIT :=.*$", f"CPYTHON_CURRENT_COMMIT := {head}", @@ -121,8 +123,14 @@ def main(): cwd=args.cpython_repo / "Doc", ) pot_path = args.cpython_repo / "pot" - upstream = {file.relative_to(pot_path).with_suffix(".po") for file in pot_path.glob("**/*.pot")} - downstream = {Path(po) for po in run("git", "ls-files", "*.po", stdout=PIPE).stdout.splitlines()} + upstream = { + file.relative_to(pot_path).with_suffix(".po") + for file in pot_path.glob("**/*.pot") + } + downstream = { + Path(po) + for po in run("git", "ls-files", "*.po", stdout=PIPE).stdout.splitlines() + } copy_new_files(upstream - downstream, pot_path=pot_path) update_known_files(upstream & downstream, pot_path=pot_path) remove_old_files(downstream - upstream) diff --git a/scripts/format_check.py b/scripts/format_check.py index 3f4957749..29ffb08e1 100644 --- a/scripts/format_check.py +++ b/scripts/format_check.py @@ -8,7 +8,12 @@ import polib parser = argparse.ArgumentParser() -parser.add_argument("subject", nargs="?", default=None, help="Subject to check (file or directory)") +parser.add_argument( + "path", + nargs="?", + default=None, + help="Path to the .po file or directory containing .po files", +) parser.add_argument("-t", "--threshold", type=int, default=85) args = parser.parse_args() @@ -28,7 +33,11 @@ elif os.path.isfile(args.subject): is_file = True - subject = args.subject if os.path.isabs(args.subject) else os.path.join(subject, args.subject) + subject = ( + args.subject + if os.path.isabs(args.subject) + else os.path.join(subject, args.subject) + ) else: print("Invalid subject, showing all files.") @@ -56,7 +65,9 @@ def main(subject): wordsid = [word for word in entry.msgid.split() if has_delimiters(word)] if has_delimiters(entry.msgstr): - wordsstr = [word for word in entry.msgstr.split() if has_delimiters(word)] + wordsstr = [ + word for word in entry.msgstr.split() if has_delimiters(word) + ] if len(wordsid) != len(wordsstr): key = pofilename diff --git a/scripts/progress.py b/scripts/progress.py new file mode 100644 index 000000000..1fb56c04b --- /dev/null +++ b/scripts/progress.py @@ -0,0 +1,100 @@ +import os +from argparse import ArgumentParser +from functools import lru_cache +from subprocess import CalledProcessError, check_output + +import polib + +parser = ArgumentParser() +parser.add_argument( + "path", + nargs="?", + default=None, + help="Path to the .po file or directory containing .po files", +) +parser.add_argument( + "--no-cache", action="store_true", default=False, help="Don't use cache" +) +args = parser.parse_args() + + +def main(): + global git_root + total_progress = False + git_root = get_git_root() + + if args.no_cache: + progress.cache_clear() + get_git_root.cache_clear() + + if args.path is None: + print("No path specified, showing total progress...") + args.path = os.path.abspath(git_root).replace("\\", "/") + total_progress = True + + else: + args.path = os.path.abspath(args.path).replace("\\", "/") + + if os.path.isfile(args.path): + paths = [args.path] + + elif os.path.isdir(args.path): + paths = [] + for root, _, files in os.walk(args.path): + paths.extend( + os.path.join(root, file) for file in files if file.endswith(".po") + ) + paths = map(lambda x: x.replace("\\", "/"), paths) + + else: + print("Invalid path") + return -1 + + try: + progress(tuple(paths), total_progress) + return 0 + except Exception as e: + print(f"Error: {e}") + return -1 + + +@lru_cache(maxsize=512) +def progress(paths, total_progress=False): + total = 0 + translated = 0 + previous = "/" + is_root = True + for path in paths: + pofile = polib.pofile(path) + total += len(pofile) - len(pofile.obsolete_entries()) + translated += len(pofile.translated_entries()) + path = path.replace(f"{git_root}", "") + if is_root and len(path.split("/")) == 2: + print() + print("PYTHON-DOCS-TR") + print("-" * 14) + is_root = False + if (previous.split("/")[1] != path.split("/")[1]) and len(path.split("/")) > 2: + print() + print(path.split("/")[1].upper()) + print("-" * len(path.split("/")[1].upper())) + previous = path + print(f"{path}: {pofile.percent_translated()}%") + + dir_path = args.path.replace(f"{git_root}", "/").replace("//", "/") + total_progress_of = "/" if total_progress else dir_path + print() + print( + f"Total progress of {total_progress_of}: {round(translated / total * 100, 2)}%" + ) if len(paths) > 1 else None + + +@lru_cache(maxsize=1) +def get_git_root(): + return os.path.abspath( + check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip() + ).replace("\\", "/") + + +if __name__ == "__main__": + main() diff --git a/scripts/translate.py b/scripts/translate.py index 77a94543f..d21a8b860 100644 --- a/scripts/translate.py +++ b/scripts/translate.py @@ -9,7 +9,13 @@ parser = ArgumentParser() parser.add_argument("filename", help="File to translate") -parser.add_argument("-t", "--translator", choices=["google", "deepl"], default="deepl", help="Translator to use") +parser.add_argument( + "-t", + "--translator", + choices=["google", "deepl"], + default="deepl", + help="Translator to use", +) parser.add_argument( "-a", "--api-key", @@ -18,7 +24,13 @@ ) parser.add_argument("-v", "--verbose", action="store_true", help="Verbose mode") parser.add_argument("-d", "--debug", action="store_true", help="Debug mode") -parser.add_argument("-s", "--skip-translated-entries", choices=[True, False], default=True, help="Skip already translated entries") +parser.add_argument( + "-s", + "--skip-translated-entries", + choices=[True, False], + default=True, + help="Skip already translated entries", +) args = parser.parse_args() @@ -117,7 +129,9 @@ def undo_sphinx_directives_protection(placeholders: dict, translated_text: str) if args.translator.lower() == "google": translator = GoogleTranslator(source="en", target="tr") elif args.translator.lower() == "deepl": - translator = DeeplTranslator(api_key=args.api_key, source="en", target="tr", use_free_api=True) + translator = DeeplTranslator( + api_key=args.api_key, source="en", target="tr", use_free_api=True + ) else: raise ValueError("Invalid translator") From 689d6b85dfabcc47cd34ed8124c2b77c373fbe7a Mon Sep 17 00:00:00 2001 From: Ege Akman Date: Tue, 2 May 2023 15:31:42 +0300 Subject: [PATCH 2/2] Update scripts/progress.py --- scripts/progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/progress.py b/scripts/progress.py index 1fb56c04b..c203be3a9 100644 --- a/scripts/progress.py +++ b/scripts/progress.py @@ -1,7 +1,7 @@ import os from argparse import ArgumentParser from functools import lru_cache -from subprocess import CalledProcessError, check_output +from subprocess import check_output import polib pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy