diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 99b75b7335..a4a5b9d037 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -119,10 +119,10 @@ jobs: - name: Run Unit Tests run: | echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> contrib/container/docker.dev.env - docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --disable-pty + docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --disable-pty --translations - name: Run Migration Tests run: | - docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --migrations + docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --migrations --translations - name: Clean up test folder run: | rm -rf InvenTree/_testfolder diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index bcf585be54..a4a6f7bb37 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -305,7 +305,7 @@ jobs: - name: Check Migration Files run: python3 .github/scripts/check_migration_files.py - name: Coverage Tests - run: invoke dev.test --coverage + run: invoke dev.test --coverage --translations - name: Upload coverage reports to Codecov uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # pin@v5.1.2 if: always() @@ -357,7 +357,7 @@ jobs: dev-install: true update: true - name: Run Tests - run: invoke dev.test + run: invoke dev.test --translations - name: Data Export Test uses: ./.github/actions/migration @@ -404,7 +404,7 @@ jobs: dev-install: true update: true - name: Run Tests - run: invoke dev.test + run: invoke dev.test --translations - name: Data Export Test uses: ./.github/actions/migration @@ -446,7 +446,7 @@ jobs: dev-install: true update: true - name: Run Tests - run: invoke dev.test --migrations --report --coverage + run: invoke dev.test --migrations --report --coverage --translations - name: Upload coverage reports to Codecov uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # pin@v5.1.2 if: always() diff --git a/src/backend/InvenTree/script/translation_stats.py b/src/backend/InvenTree/script/translation_stats.py deleted file mode 100644 index 29c1b7eac3..0000000000 --- a/src/backend/InvenTree/script/translation_stats.py +++ /dev/null @@ -1,80 +0,0 @@ -"""This script calculates translation coverage for various languages.""" - -import json -import os -import sys - - -def calculate_coverage(filename): - """Calculate translation coverage for a .po file.""" - with open(filename, encoding='utf-8') as f: - lines = f.readlines() - - lines_count = 0 - lines_covered = 0 - lines_uncovered = 0 - - for line in lines: - if line.startswith('msgid '): - lines_count += 1 - - elif line.startswith('msgstr'): - if line.startswith(('msgstr ""', "msgstr ''")): - lines_uncovered += 1 - else: - lines_covered += 1 - - # Return stats for the file - return (lines_count, lines_covered, lines_uncovered) - - -if __name__ == '__main__': - MY_DIR = os.path.dirname(os.path.realpath(__file__)) - LC_DIR = os.path.abspath(os.path.join(MY_DIR, '..', 'locale')) - STAT_FILE = os.path.abspath( - os.path.join(MY_DIR, '..', 'InvenTree/locale_stats.json') - ) - - locales = {} - locales_perc = {} - - verbose = '-v' in sys.argv - - for locale in os.listdir(LC_DIR): - path = os.path.join(LC_DIR, locale) - if os.path.exists(path) and os.path.isdir(path): - locale_file = os.path.join(path, 'LC_MESSAGES', 'django.po') - - if os.path.exists(locale_file) and os.path.isfile(locale_file): - locales[locale] = locale_file - - if verbose: - print('-' * 16) - - percentages = [] - - for locale in locales: - locale_file = locales[locale] - stats = calculate_coverage(locale_file) - - (total, covered, uncovered) = stats - - percentage = int(covered / total * 100) if total > 0 else 0 - - if verbose: - print(f'| {locale.ljust(4, " ")} : {str(percentage).rjust(4, " ")}% |') - - locales_perc[locale] = percentage - - percentages.append(percentage) - - if verbose: - print('-' * 16) - - # write locale stats - with open(STAT_FILE, 'w', encoding='utf-8') as target: - json.dump(locales_perc, target) - - avg = int(sum(percentages) / len(percentages)) if len(percentages) > 0 else 0 - - print(f'InvenTree translation coverage: {avg}%') diff --git a/tasks.py b/tasks.py index 0aa3789735..1aa89a7436 100644 --- a/tasks.py +++ b/tasks.py @@ -416,23 +416,6 @@ def static(c, frontend=False, clear=True, skip_plugins=False): @task -def translate_stats(c): - """Collect translation stats. - - The file generated from this is needed for the UI. - """ - # Recompile the translation files (.mo) - # We do not run 'invoke dev.translate' here, as that will touch the source (.po) files too! - try: - manage(c, 'compilemessages', pty=True) - except Exception: - warning('WARNING: Translation files could not be compiled:') - - path = managePyDir().joinpath('script', 'translation_stats.py') - run(c, f'python3 {path}') - - -@task(post=[translate_stats]) def translate(c, ignore_static=False, no_frontend=False): """Rebuild translation source files. Advanced use only! @@ -562,7 +545,7 @@ def showmigrations(c, app=''): @task( - post=[clean_settings, translate_stats], + post=[clean_settings], help={ 'skip_backup': 'Skip database backup step (advanced users)', 'frontend': 'Force frontend compilation/download step (ignores INVENTREE_DOCKER)', @@ -592,7 +575,6 @@ def update( - frontend_compile or frontend_download (optional) - static (optional) - clean_settings - - translate_stats """ info('Updating InvenTree installation...') @@ -917,7 +899,7 @@ def worker(c): manage(c, 'qcluster', pty=True) -@task(post=[translate_stats, static, server]) +@task(post=[static, server]) def test_translations(c): """Add a fictional language to test if each component is ready for translations.""" import django @@ -995,10 +977,24 @@ def test_translations(c): } ) def test( - c, disable_pty=False, runtest='', migrations=False, report=False, coverage=False + c, + disable_pty=False, + runtest='', + migrations=False, + report=False, + coverage=False, + translations=False, ): """Run unit-tests for InvenTree codebase. + Arguments: + disable_pty (bool): Disable PTY (default = False) + runtest (str): Specify which tests to run, in format ... (default = '') + migrations (bool): Run migration unit tests (default = False) + report (bool): Display a report of slow tests (default = False) + coverage (bool): Run code coverage analysis (requires coverage package) (default = False) + translations (bool): Compile translations before running tests (default = False) + To run only certain test, use the argument --runtest. This can filter all the way down to: ... @@ -1010,6 +1006,12 @@ def test( # Run sanity check on the django install manage(c, 'check') + if translations: + try: + manage(c, 'compilemessages', pty=True) + except Exception: + warning('Failed to compile translations') + pty = not disable_pty _apps = ' '.join(apps()) @@ -1527,7 +1529,6 @@ internal = Collection( rebuild_models, rebuild_thumbnails, showmigrations, - translate_stats, ) ns = Collection(