From 7b2992ab3f2818ccef90a011fd8698e3ea6b81f0 Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Wed, 24 Nov 2021 10:41:11 -0500 Subject: [PATCH] Add po/ to the linters --- .flake8 | 1 + .github/workflows/main.yml | 4 ++-- po/update-translations.py | 36 +++++++++++++++++++++++++++--------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.flake8 b/.flake8 index 35abd39..9656ec8 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,7 @@ [flake8] builtins = _ max-line-length = 100 +show-source = true # Temporary exclude = src/diffuse/main.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5abdfa8..1be2757 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,10 +22,10 @@ jobs: - run: pip install -r requirements.txt - name: Flake8 - run: flake8 src/ + run: flake8 src/ po/ - name: MyPy - run: mypy src/ + run: mypy src/ po/ meson-build-test: runs-on: ubuntu-latest diff --git a/po/update-translations.py b/po/update-translations.py index 235a1e5..306c20a 100755 --- a/po/update-translations.py +++ b/po/update-translations.py @@ -20,17 +20,18 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import argparse -import glob import os import subprocess import shutil import tempfile + def check_translation(filename): - subprocess.run(["msgfmt", "-c", "-v", filename]) + subprocess.run(['msgfmt', '-c', '-v', filename]) + def update_translation(filename): - print(f"Updating translation file '{filename}'...") + print(f'Updating translation file "{filename}"...') # Get language lang = os.path.splitext(filename)[0] @@ -40,17 +41,34 @@ def update_translation(filename): shutil.move(filename, tmpfile) # Create a new .po file for this language - emptypofile = os.path.join(tmpdir, f"{lang}.empty.po") - subprocess.run(["msginit", "--no-wrap", "--no-translator", "-l", lang, "-o", emptypofile, "-i", "diffuse.pot"]) + emptypofile = os.path.join(tmpdir, f'{lang}.empty.po') + subprocess.run([ + 'msginit', + '--no-wrap', + '--no-translator', + '-l', + lang, + '-o', + emptypofile, + '-i', + 'diffuse.pot']) # Merge with the old translation - subprocess.run(["msgmerge", "-q", "--no-wrap", tmpfile, emptypofile, "-o", filename]) + subprocess.run([ + 'msgmerge', + '-q', + '--no-wrap', + tmpfile, + emptypofile, + '-o', + filename]) # Validate translation - print(f"Validate {filename}:") + print(f'Validate "{filename}":') check_translation(filename) - print(f"Update done.") + print('Update done.') + # Setup argument parser parser = argparse.ArgumentParser(description='Update translation files (.po).') @@ -68,7 +86,7 @@ po_files.sort() if args.check_only: for file in po_files: - print(f"Validate {file}:") + print(f'Validate "{file}":') check_translation(file) exit(0)