import_translation: read the input file outside the event loop (ruff ASYNC230/SIM115)

This commit is contained in:
2026-09-20 23:47:28 +00:00
parent bc1e8a8357
commit 42609a54c1
+8 -3
View File
@@ -22,6 +22,7 @@ target language base tag (e.g. fi), FILE.md the translated Markdown.
import argparse
import asyncio
import sys
from pathlib import Path
from kanta import Kanta
@@ -30,7 +31,7 @@ from pagerite.i18n import base_tag, primary_lang
from pagerite.translate import TransResult, align_article, store_results
async def main() -> None:
def main() -> None:
p = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
@@ -43,9 +44,13 @@ async def main() -> None:
help="kanta database (default: localhost/content.kantadb)",
)
args = p.parse_args()
translated = Path(args.file).read_text()
asyncio.run(import_translation(args, translated))
async def import_translation(args: argparse.Namespace, translated: str) -> None:
path = args.path.strip("/")
lang = base_tag(args.lang)
translated = open(args.file).read()
data = Data()
kanta = Kanta(args.db, data, migrations="pagerite.migrations")
@@ -77,4 +82,4 @@ async def main() -> None:
if __name__ == "__main__":
asyncio.run(main())
main()