From 5f1c49dc997688aabb1b7a4e15a2c88d230f3719 Mon Sep 17 00:00:00 2001 From: Nicolas Grosjean Date: Fri, 27 Sep 2024 16:36:40 +0200 Subject: [PATCH] Use poetry in CI --- .github/workflows/flake8_test_coverage.yml | 27 ++--- README.md | 110 +++++++++--------- compile_update_paratranz.py | 2 +- copy_on_other_languages/README.txt | 2 +- paradox_localization_utils/__init__.py | 1 + .../add_missing_lines.py | 6 +- .../apply_diff.py | 2 +- .../apply_diff_all.py | 26 +++-- .../copy_on_other_languages.py | 0 .../download_paratranz.py | 0 .../extract_existing_translation.py | 6 +- .../extract_paratranz_translation.py | 2 +- .../get_duplicates_key.py | 2 +- .../read_localization_file.py | 0 .../update_paratranz.py | 6 +- .../update_source.py | 0 {src => paradox_localization_utils}/utils.py | 0 pyproject.toml | 2 +- tests/test_apply_diff.py | 2 +- tests/test_apply_diff_all.py | 10 +- tests/test_copy_on_other_languages.py | 2 +- tests/test_extract_existing_translation.py | 2 +- tests/test_extract_paratranz_translation.py | 5 +- tests/test_read_localization_file.py | 6 +- tests/test_update_paratranz.py | 8 +- 25 files changed, 131 insertions(+), 98 deletions(-) create mode 100644 paradox_localization_utils/__init__.py rename {src => paradox_localization_utils}/add_missing_lines.py (96%) rename {src => paradox_localization_utils}/apply_diff.py (97%) rename {src => paradox_localization_utils}/apply_diff_all.py (92%) rename {src => paradox_localization_utils}/copy_on_other_languages.py (100%) rename {src => paradox_localization_utils}/download_paratranz.py (100%) rename {src => paradox_localization_utils}/extract_existing_translation.py (97%) rename {src => paradox_localization_utils}/extract_paratranz_translation.py (96%) rename {src => paradox_localization_utils}/get_duplicates_key.py (92%) rename {src => paradox_localization_utils}/read_localization_file.py (100%) rename {src => paradox_localization_utils}/update_paratranz.py (97%) rename {src => paradox_localization_utils}/update_source.py (100%) rename {src => paradox_localization_utils}/utils.py (100%) diff --git a/.github/workflows/flake8_test_coverage.yml b/.github/workflows/flake8_test_coverage.yml index e14950e..3823ca4 100644 --- a/.github/workflows/flake8_test_coverage.yml +++ b/.github/workflows/flake8_test_coverage.yml @@ -8,32 +8,29 @@ on: branches: [ master ] jobs: - build: - + ci: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python 3.10 - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: "3.10" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pytest coverage genbadge[all] - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Install poetry + uses: abatilo/actions-poetry@v3 + - name: Install the project dependencies + run: poetry install - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings - flake8 . --count --exit-zero --max-line-length=119 --statistics + poetry run flake8 . --count --exit-zero --max-line-length=119 --statistics - name: Coverage with pytest run: | - coverage run --omit "tests/*.py" -m pytest ./tests/ --junitxml=./report.xml -s - coverage report - coverage xml + poetry run coverage run --omit "tests/*.py" -m pytest ./tests/ --junitxml=./report.xml -s + poetry run coverage report + poetry run coverage xml # genbadge tests -i ./report.xml -s -o ./tests.svg # genbadge coverage -i ./coverage.xml -s -o ./coverage.svg # - name: Setup node diff --git a/README.md b/README.md index 42feb8b..6165c34 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ # Paradox localization utils -> A set of tools to manipulate Paradox localization files particularly for translating +> A set of tools to manipulate Paradox localization files particularly for translating ## Terms -* Source: It refers to the source language of your translation -* Destination (shorten dest): It refers to the destination language of your translation +- Source: It refers to the source language of your translation +- Destination (shorten dest): It refers to the destination language of your translation Example : If I translate from English to French, the source directory refers to the directory of English localisation files. @@ -27,7 +27,7 @@ poetry install -Install pre-commit +Install pre-commit ```shell pre-commit install @@ -49,7 +49,7 @@ Activate the conda environment activate paradox_loc ``` -Install Levenshtein package (only needed for *apply_diff_all*) +Install Levenshtein package (only needed for _apply_diff_all_) ```shell conda install python-levenshtein @@ -61,7 +61,7 @@ OR pip install python-levenshtein ``` -Install pandas package (only needed for *extract_existing_translation*) +Install pandas package (only needed for _extract_existing_translation_) ```shell pip install pandas @@ -71,7 +71,7 @@ pip install pandas -Install pre-commit +Install pre-commit ```shell pip install pre-commit @@ -86,13 +86,13 @@ pre-commit install > It also copy in the parent of the target directory an extract of the source localization and all files in target_dir. ```shell -python src/update_source.py +python paradox_localization_utils/update_source.py ``` Example to update the English files of the HoI4 mod Kaiserreich ```shell -python src/update_source.py <...>\Steam\steamapps\workshop\content\394360\1521695605 <...>\GitHub\Traduction-FR-Kaiserreich\Traduction-FR-Kaiserreich english +python paradox_localization_utils/update_source.py <...>\Steam\steamapps\workshop\content\394360\1521695605 <...>\GitHub\Traduction-FR-Kaiserreich\Traduction-FR-Kaiserreich english ``` ### Update Paratranz @@ -104,13 +104,13 @@ Get your Paratranz API token in the settings tab of your Paratranz profile. Get the Paratranz project id by open the project and see the number in the url. ```shell -python src/update_paratranz.py +python paradox_localization_utils/update_paratranz.py ``` Example to update the RICE project (translation from English) on Paratranz ```shell -python src/update_paratranz.py 2617 <...>\GitHub\RICE-for-CK3\RICE\localization english +python paradox_localization_utils/update_paratranz.py 2617 <...>\GitHub\RICE-for-CK3\RICE\localization english ``` To compile the code, run the following command @@ -130,7 +130,7 @@ Get your Paratranz API token in the settings tab of your Paratranz profile. Get the Paratranz project id by open the project and see the number in the url. ```shell -python src/download_paratranz.py +python paradox_localization_utils/download_paratranz.py ``` ### Add missing lines @@ -140,28 +140,27 @@ python src/download_paratranz.py +python paradox_localization_utils/add_missing_lines.py ``` Example to add in French files missing lines from English files ```shell -python src/add_missing_lines.py "<...>\game\localization\english" "<...>\game\localization\french" +python paradox_localization_utils/add_missing_lines.py "<...>\game\localization\english" "<...>\game\localization\french" ``` #### For EUIV, HoI4 or Stellaris ```shell -python src/add_missing_lines.py -source_lang -dest_lang +python paradox_localization_utils/add_missing_lines.py -source_lang -dest_lang ``` Example to add in French files missing lines from English files ```shell -python src/add_missing_lines.py "<...>\localisation" "<...>\localisation" -source_lang english -dest_lang french +python paradox_localization_utils/add_missing_lines.py "<...>\localisation" "<...>\localisation" -source_lang english -dest_lang french ``` - ### Apply diff all > Apply the differences between an old source version and a current source version to your current destination files. @@ -169,32 +168,32 @@ python src/add_missing_lines.py "<...>\localisation" "<...>\localisation" -sourc #### For Imperator Rome and sooner, and new EUIV, HoI4 or Stellaris localisation format (a subdirectory for each language) ```shell -python src/apply_diff_all.py +python paradox_localization_utils/apply_diff_all.py ``` -* contains the localisation of the old source version -* contains the localisation of the new source version -* contains the localisation of the old destination version +- contains the localisation of the old source version +- contains the localisation of the new source version +- contains the localisation of the old destination version Example to apply in French files the modifications done in English ```shell -python src/apply_diff_all.py "<...>\V1\localisation\english" "<...>\V2\localisation\english" -dest_dir "<...>\V1\localisation\french" +python paradox_localization_utils/apply_diff_all.py "<...>\V1\localisation\english" "<...>\V2\localisation\english" -dest_dir "<...>\V1\localisation\french" ``` #### For old EUIV, HoI4 or Stellaris localisation format (all files in the same directory) ```shell -python src/apply_diff_all.py -source_lang -dest_lang +python paradox_localization_utils/apply_diff_all.py -source_lang -dest_lang ``` -* contains the localisation of the old source version -* contains the localisation of both new source version and old destination version +- contains the localisation of the old source version +- contains the localisation of both new source version and old destination version Example to apply in French files the modifications done in English ```shell -python src/apply_diff_all.py "<...>\V1\localisation" "<...>\V2\localisation" -source_lang english -dest_lang french +python paradox_localization_utils/apply_diff_all.py "<...>\V1\localisation" "<...>\V2\localisation" -source_lang english -dest_lang french ``` #### Both format @@ -206,7 +205,7 @@ The new and edited lines contains `:9 "`. If there is less than 10 modifications (according Levenshtein distance), the destination text is kept. -All the lines to translate are exported in to_translate/file_to_translate_.yml. +All the lines to translate are exported in to*translate/file_to_translate*.yml. We can also add the following parameter to the command line -keys_to_ignore , to simply copy-paste lines with these keys. @@ -217,24 +216,25 @@ It is useful when you have keys like spellcheck_ignore in the source files. > Extract existing translation from another game or mod to apply to your translation #### Limits + The target is EUIV or sooner whereas the source can be CK2/Vic2 or EUIV and sooner. #### Usage ```shell -python src/extract_existing_translation.py -source_col_ck2 -dest_col_ck2 +python paradox_localization_utils/extract_existing_translation.py -source_col_ck2 -dest_col_ck2 ``` Example to add in French CK3 files some texts from CK2 files. ```shell -python src/extract_existing_translation.py "<...>\CK2\localisation" "<...>\CK2\localisation" "<...>\CK3\localization\english" "<...>\CK3\localization\french" english french -source_col_ck2 1 -dest_col_ck2 2 +python paradox_localization_utils/extract_existing_translation.py "<...>\CK2\localisation" "<...>\CK2\localisation" "<...>\CK3\localization\english" "<...>\CK3\localization\french" english french -source_col_ck2 1 -dest_col_ck2 2 ``` Example to add in French HoI IV mod files some texts from Vanilla files. ```shell -python src/extract_existing_translation.py "<...>\Steam\steamapps\common\Hearts of Iron IV\localisation" "<...>\Steam\steamapps\common\Hearts of Iron IV\localisation" "<...>\mod\localisation" "<...>\mod\localisation" english french +python paradox_localization_utils/extract_existing_translation.py "<...>\Steam\steamapps\common\Hearts of Iron IV\localisation" "<...>\Steam\steamapps\common\Hearts of Iron IV\localisation" "<...>\mod\localisation" "<...>\mod\localisation" english french ``` ### Extract Paratranz translation @@ -242,18 +242,19 @@ python src/extract_existing_translation.py "<...>\Steam\steamapps\common\Hearts > Extract translations from JSON files downloaded from [Paratranz](https://paratranz.cn) to apply to your translation. #### Limits + This script only works for EUIV and sooner. #### Usage ```shell -python src/extract_paratranz_translation.py +python paradox_localization_utils/extract_paratranz_translation.py ``` Example to extract french reviewed translations ```shell -python src/extract_paratranz_translation.py "<...>\paratranz" "<...>\localisation" french +python paradox_localization_utils/extract_paratranz_translation.py "<...>\paratranz" "<...>\localisation" french ``` By default it extracts only reviewed translation. @@ -262,7 +263,7 @@ If you want to extract not reviewed translation, add `-extract_not_review` to th Example to extract french translations (reviewed or not) ```shell -python src/extract_paratranz_translation.py "<...>\paratranz" "<...>\localisation" french -extract_not_review +python paradox_localization_utils/extract_paratranz_translation.py "<...>\paratranz" "<...>\localisation" french -extract_not_review ``` ### Copy localization in other languages @@ -270,67 +271,69 @@ python src/extract_paratranz_translation.py "<...>\paratranz" "<...>\localisatio > Copy the localization of a language in other languages to allow to run your game/mod with this language with source texts instead of keys. #### Limits + It works only for Imperator Rome and sooner. #### Basic Usage [Windows only] + The usage is explicated in this [Steam guide](https://steamcommunity.com/sharedfiles/filedetails/?id=2342385980). #### Developer Usage ```shell -python src/copy_on_other_languages.py ... +python paradox_localization_utils/copy_on_other_languages.py ... ``` -Example to add some languages to available only in English and French (the added languages will have English text). +Example to add some languages to available only in English and French (the added languages will have English text). ```shell -python src/copy_on_other_languages.py "<...>\MyMod\localisation" english korean german russian simp_chinese spanish +python paradox_localization_utils/copy_on_other_languages.py "<...>\MyMod\localisation" english korean german russian simp_chinese spanish ``` To compile it (after running once `pip install cx_Freeze`), use the following command ```shell -cxfreeze -c src/copy_on_other_languages.py +cxfreeze -c paradox_localization_utils/copy_on_other_languages.py ``` - + ### Get duplicates keys > Get the list of duplicated keys in the localization to avoid localization erased by others. - + #### Limits - + The duplicated keys are searched in English localisation files only. - + #### Usage - + To get the full list of duplicated keys run the following command ```shell -python src/get_duplicates_key.py "<...>\MyMod\localisation" +python paradox_localization_utils/get_duplicates_key.py "<...>\MyMod\localisation" ``` - + To get only the list of duplicated keys which already cause a bug -(the value is not the same for each duplication), add *-only_different_value* to the command. - - +(the value is not the same for each duplication), add _-only_different_value_ to the command. + ### [DEPRECATED] Apply diff for EUIV and sooner ```shell -python src/apply_diff.py +python paradox_localization_utils/apply_diff.py ``` The destination file is override so don't hesitate to have a backup before running this. The new and edited lines contains `:9 "` Optionnal parameters : -* ```-space_prefix ``` : Prefix (generally spaces) before key in files -* ```-keep_edited``` : Keep destination value in case of edition. -The default behavior replace the destination value by the new source value. + +- `-space_prefix ` : Prefix (generally spaces) before key in files +- `-keep_edited` : Keep destination value in case of edition. + The default behavior replace the destination value by the new source value. Example to apply the English update from 0.11.1 to 0.11.2 to Russia file in French: ```shell -python src/apply_diff.py <...>\0.11.1\localisation\KR_Russia_l_english.yml <...>\0.11.2\localisation\KR_Russia_l_english.yml <...>\Translation_FR\localisation\KR_Russia_l_french.yml -space_prefix " " -keep_edited +python paradox_localization_utils/apply_diff.py <...>\0.11.1\localisation\KR_Russia_l_english.yml <...>\0.11.2\localisation\KR_Russia_l_english.yml <...>\Translation_FR\localisation\KR_Russia_l_french.yml -space_prefix " " -keep_edited ``` After running this, the new and edited lines need to be fixed by hand by seeking `:9 "` @@ -343,8 +346,7 @@ Run the tests with pytest pytest ``` -If some tests fails with error `ModuleNotFoundError: No module named 'src'`, run the following command in the root directory. - +If some tests fails with error `ModuleNotFoundError: No module named 'paradox_localization_utils'`, run the following command in the root directory. On Windows: diff --git a/compile_update_paratranz.py b/compile_update_paratranz.py index f5cc9ac..b433981 100644 --- a/compile_update_paratranz.py +++ b/compile_update_paratranz.py @@ -7,5 +7,5 @@ version="0.1", description="Update translation on Paratranz", options={"build_exe": build_exe_options}, - executables=[Executable("src/update_paratranz.py")], + executables=[Executable("paradox_localization_utils/update_paratranz.py")], ) diff --git a/copy_on_other_languages/README.txt b/copy_on_other_languages/README.txt index cf0d08d..72896c7 100644 --- a/copy_on_other_languages/README.txt +++ b/copy_on_other_languages/README.txt @@ -1,5 +1,5 @@ Usage guide : https://steamcommunity.com/sharedfiles/filedetails/?id=2342385980 -Source code : https://github.com/NicolasGrosjean/Paradox_localization_utils/blob/master/src/copy_on_other_languages.py +Source code : https://github.com/NicolasGrosjean/Paradox_localization_utils/blob/master/paradox_localization_utils/copy_on_other_languages.py Licence MIT : https://github.com/NicolasGrosjean/Paradox_localization_utils/blob/master/Licence.md \ No newline at end of file diff --git a/paradox_localization_utils/__init__.py b/paradox_localization_utils/__init__.py new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/paradox_localization_utils/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/add_missing_lines.py b/paradox_localization_utils/add_missing_lines.py similarity index 96% rename from src/add_missing_lines.py rename to paradox_localization_utils/add_missing_lines.py index 814bd9d..ca7c335 100644 --- a/src/add_missing_lines.py +++ b/paradox_localization_utils/add_missing_lines.py @@ -4,7 +4,11 @@ import sys sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) -from src.read_localization_file import file_to_keys_and_lines, get_key_value_and_version, BadLocalizationException +from paradox_localization_utils.read_localization_file import ( + file_to_keys_and_lines, + get_key_value_and_version, + BadLocalizationException, +) def get_args(): diff --git a/src/apply_diff.py b/paradox_localization_utils/apply_diff.py similarity index 97% rename from src/apply_diff.py rename to paradox_localization_utils/apply_diff.py index 9013b72..8066400 100644 --- a/src/apply_diff.py +++ b/paradox_localization_utils/apply_diff.py @@ -4,7 +4,7 @@ import sys sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) -from src.read_localization_file import ( +from paradox_localization_utils.read_localization_file import ( file_to_keys_and_lines, get_key_value_and_version, BadLocalizationException, diff --git a/src/apply_diff_all.py b/paradox_localization_utils/apply_diff_all.py similarity index 92% rename from src/apply_diff_all.py rename to paradox_localization_utils/apply_diff_all.py index e8d6b80..f55e1bb 100644 --- a/src/apply_diff_all.py +++ b/paradox_localization_utils/apply_diff_all.py @@ -5,7 +5,7 @@ import sys sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) -from src.read_localization_file import ( +from paradox_localization_utils.read_localization_file import ( file_to_keys_and_lines, get_key_value_and_version, BadLocalizationException, @@ -110,7 +110,9 @@ def apply_diff_one_file( # OR translation if already translated elsewhere write_new_line_or_get_existing_translation(f, key, dest_text, existing_translations, None) if value not in existing_translations: - lines_to_update_old_source.append(" " + key + ':9 "' + old_source_values[key]["value"] + '"\n') + lines_to_update_old_source.append( + " " + key + ':9 "' + old_source_values[key]["value"] + '"\n' + ) lines_to_update_source.append(" " + key + ':9 "' + value + '"\n') lines_to_update_dest.append(" " + key + ':9 "' + dest_text + '"\n') else: @@ -131,11 +133,13 @@ def apply_diff_one_file( first_line = False -def apply_diff_all(old_dir, current_src_dir, current_dest_dir, source_lang, dest_lang, keys_to_ignore): +def apply_diff_all( + old_dir, current_paradox_localization_utils_dir, current_dest_dir, source_lang, dest_lang, keys_to_ignore +): """ Apply diff for all files :param old_dir: Directory with source Paradox files for previous version - :param current_src_dir: Directory with source Paradox files for new version + :param current_paradox_localization_utils_dir: Directory with source Paradox files for new version :param current_dest_dir: Directory with destination Paradox files for new version :param source_lang: Source language :param dest_lang: Destination language @@ -176,17 +180,17 @@ def apply_diff_all(old_dir, current_src_dir, current_dest_dir, source_lang, dest lines_to_update_source = [f"\ufeffl_{source_lang}:\n"] lines_to_update_dest = [f"\ufeffl_{dest_lang}:\n"] # Apply diff with current source texts - for root, _, files in os.walk(current_src_dir): + for root, _, files in os.walk(current_paradox_localization_utils_dir): for file in files: if file.endswith(source_lang + ".yml"): abs_path = os.path.abspath(os.path.join(root, file)) - rel_path = abs_path[: abs_path.find("_l_")].replace(current_src_dir, "") + rel_path = abs_path[: abs_path.find("_l_")].replace(current_paradox_localization_utils_dir, "") if rel_path in rel_to_dest_abs_path: dest_file_path = rel_to_dest_abs_path[rel_path] else: - dest_file_path = abs_path.replace(current_src_dir, current_dest_dir).replace( - source_lang + ".yml", dest_lang + ".yml" - ) + dest_file_path = abs_path.replace( + current_paradox_localization_utils_dir, current_dest_dir + ).replace(source_lang + ".yml", dest_lang + ".yml") apply_diff_one_file( abs_path, dest_file_path, @@ -207,13 +211,13 @@ def apply_diff_all(old_dir, current_src_dir, current_dest_dir, source_lang, dest os.path.join(current_dest_dir, "..", DIR_TO_TRANSLATE), os.path.join(current_dest_dir, "..", DIR_TO_UPDATE), os.path.join(current_dest_dir, "..", DIR_TO_UPDATE), - os.path.join(current_dest_dir, "..", DIR_TO_UPDATE) + os.path.join(current_dest_dir, "..", DIR_TO_UPDATE), ] file_names = [ f"{FILE_TO_TRANSLATE_PREFIX}_l_{source_lang}.yml", f"{FILE_TO_UPDATE_OLD_SOURCE_PREFIX}_l_{source_lang}.yml", f"{FILE_TO_UPDATE_SOURCE_PREFIX}_l_{source_lang}.yml", - f"{FILE_TO_UPDATE_DEST_PREFIX}_l_{dest_lang}.yml" + f"{FILE_TO_UPDATE_DEST_PREFIX}_l_{dest_lang}.yml", ] for i in range(len(lines_to_export)): if len(lines_to_export[i]) > 0: diff --git a/src/copy_on_other_languages.py b/paradox_localization_utils/copy_on_other_languages.py similarity index 100% rename from src/copy_on_other_languages.py rename to paradox_localization_utils/copy_on_other_languages.py diff --git a/src/download_paratranz.py b/paradox_localization_utils/download_paratranz.py similarity index 100% rename from src/download_paratranz.py rename to paradox_localization_utils/download_paratranz.py diff --git a/src/extract_existing_translation.py b/paradox_localization_utils/extract_existing_translation.py similarity index 97% rename from src/extract_existing_translation.py rename to paradox_localization_utils/extract_existing_translation.py index debeb78..3e072f6 100644 --- a/src/extract_existing_translation.py +++ b/paradox_localization_utils/extract_existing_translation.py @@ -5,7 +5,11 @@ import sys sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) -from src.read_localization_file import file_to_keys_and_values, get_key_value_and_version, BadLocalizationException +from paradox_localization_utils.read_localization_file import ( + file_to_keys_and_values, + get_key_value_and_version, + BadLocalizationException, +) def get_args(): diff --git a/src/extract_paratranz_translation.py b/paradox_localization_utils/extract_paratranz_translation.py similarity index 96% rename from src/extract_paratranz_translation.py rename to paradox_localization_utils/extract_paratranz_translation.py index bed4c2a..d3ed7bb 100644 --- a/src/extract_paratranz_translation.py +++ b/paradox_localization_utils/extract_paratranz_translation.py @@ -5,7 +5,7 @@ import sys sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) -from src.read_localization_file import get_key_value_and_version, BadLocalizationException +from paradox_localization_utils.read_localization_file import get_key_value_and_version, BadLocalizationException def get_args(): diff --git a/src/get_duplicates_key.py b/paradox_localization_utils/get_duplicates_key.py similarity index 92% rename from src/get_duplicates_key.py rename to paradox_localization_utils/get_duplicates_key.py index 10ab3be..3be584a 100644 --- a/src/get_duplicates_key.py +++ b/paradox_localization_utils/get_duplicates_key.py @@ -4,7 +4,7 @@ import sys sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) -from src.read_localization_file import get_key_value_and_version, BadLocalizationException +from paradox_localization_utils.read_localization_file import get_key_value_and_version, BadLocalizationException def get_args(): diff --git a/src/read_localization_file.py b/paradox_localization_utils/read_localization_file.py similarity index 100% rename from src/read_localization_file.py rename to paradox_localization_utils/read_localization_file.py diff --git a/src/update_paratranz.py b/paradox_localization_utils/update_paratranz.py similarity index 97% rename from src/update_paratranz.py rename to paradox_localization_utils/update_paratranz.py index 1a1e0aa..1ba442b 100644 --- a/src/update_paratranz.py +++ b/paradox_localization_utils/update_paratranz.py @@ -4,7 +4,7 @@ import requests import time -from src.utils import compute_time, manage_request_error +from paradox_localization_utils.utils import compute_time, manage_request_error def get_args(): @@ -47,12 +47,14 @@ def create_or_update_files(project_id: int, token: str, loc_dir: str, language: print(file) print(f"Total time of the execution: {compute_time(start)}") + def __assert_localisation_directory_format(loc_dir: str, language: str): if not os.path.isdir(loc_dir): raise ValueError(f"Directory {loc_dir} does not exist") if not os.path.isdir(os.path.join(loc_dir, language)): raise ValueError(f"Directory {os.path.join(loc_dir, language)} does not exist") + def get_project_files(project_id: int) -> dict[str, int]: r = requests.get(f"https://paratranz.cn/api/projects/{project_id}/files") manage_request_error(r) @@ -69,7 +71,7 @@ def create_or_update_file( files_with_errors: list, sleeping_before_retry: int = 2, ): - file_relative_path = file_path.replace(f"{loc_dir}\\{language}\\", "") + file_relative_path = file_path.replace(f"{loc_dir}\\{language}\\", "").replace(f"{loc_dir}/{language}/", "") paratranz_path = os.path.dirname(file_relative_path) if file_path.endswith(f"{language}.yml"): try: diff --git a/src/update_source.py b/paradox_localization_utils/update_source.py similarity index 100% rename from src/update_source.py rename to paradox_localization_utils/update_source.py diff --git a/src/utils.py b/paradox_localization_utils/utils.py similarity index 100% rename from src/utils.py rename to paradox_localization_utils/utils.py diff --git a/pyproject.toml b/pyproject.toml index b11a91e..9c0f5b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ line-length = 119 [tool.poetry] -name = "paradox-localization-utils" +name = "paradox_localization_utils" version = "0.1.0" description = "Utilitaries on Paradox localisation files" authors = ["NicolasGrosjean "] diff --git a/tests/test_apply_diff.py b/tests/test_apply_diff.py index 3784fc9..ce08699 100644 --- a/tests/test_apply_diff.py +++ b/tests/test_apply_diff.py @@ -3,7 +3,7 @@ import os import shutil -from src.apply_diff import apply_diff +from paradox_localization_utils.apply_diff import apply_diff from tests.utils import get_data_dir diff --git a/tests/test_apply_diff_all.py b/tests/test_apply_diff_all.py index c874b1f..0f26613 100644 --- a/tests/test_apply_diff_all.py +++ b/tests/test_apply_diff_all.py @@ -4,7 +4,15 @@ import shutil from tests.utils import get_data_dir -from src.apply_diff_all import DIR_TO_TRANSLATE, DIR_TO_UPDATE, FILE_TO_TRANSLATE_PREFIX, FILE_TO_UPDATE_DEST_PREFIX, FILE_TO_UPDATE_OLD_SOURCE_PREFIX, FILE_TO_UPDATE_SOURCE_PREFIX, apply_diff_all_old_formats +from paradox_localization_utils.apply_diff_all import ( + DIR_TO_TRANSLATE, + DIR_TO_UPDATE, + FILE_TO_TRANSLATE_PREFIX, + FILE_TO_UPDATE_DEST_PREFIX, + FILE_TO_UPDATE_OLD_SOURCE_PREFIX, + FILE_TO_UPDATE_SOURCE_PREFIX, + apply_diff_all_old_formats, +) class TestApplyDiffAll(unittest.TestCase): diff --git a/tests/test_copy_on_other_languages.py b/tests/test_copy_on_other_languages.py index 46234c1..dc05f63 100644 --- a/tests/test_copy_on_other_languages.py +++ b/tests/test_copy_on_other_languages.py @@ -2,7 +2,7 @@ import shutil import unittest -from src.copy_on_other_languages import copy_on_other_languages +from paradox_localization_utils.copy_on_other_languages import copy_on_other_languages from tests.utils import get_data_dir diff --git a/tests/test_extract_existing_translation.py b/tests/test_extract_existing_translation.py index 969c885..bb4df29 100644 --- a/tests/test_extract_existing_translation.py +++ b/tests/test_extract_existing_translation.py @@ -2,7 +2,7 @@ import shutil import unittest -from src.extract_existing_translation import extract_existing_translation +from paradox_localization_utils.extract_existing_translation import extract_existing_translation from tests.utils import get_data_dir diff --git a/tests/test_extract_paratranz_translation.py b/tests/test_extract_paratranz_translation.py index 706523e..35f04f0 100644 --- a/tests/test_extract_paratranz_translation.py +++ b/tests/test_extract_paratranz_translation.py @@ -2,7 +2,10 @@ import shutil import unittest -from src.extract_paratranz_translation import extract_paratranz_localisation, extract_paratranz_localisation_dir +from paradox_localization_utils.extract_paratranz_translation import ( + extract_paratranz_localisation, + extract_paratranz_localisation_dir, +) from tests.utils import get_data_dir diff --git a/tests/test_read_localization_file.py b/tests/test_read_localization_file.py index 168ee22..551bf90 100644 --- a/tests/test_read_localization_file.py +++ b/tests/test_read_localization_file.py @@ -1,7 +1,11 @@ import unittest import os -from src.read_localization_file import get_key_value_and_version, BadLocalizationException, file_to_keys_and_values +from paradox_localization_utils.read_localization_file import ( + get_key_value_and_version, + BadLocalizationException, + file_to_keys_and_values, +) from tests.utils import get_data_dir diff --git a/tests/test_update_paratranz.py b/tests/test_update_paratranz.py index a20c057..a80a4d8 100644 --- a/tests/test_update_paratranz.py +++ b/tests/test_update_paratranz.py @@ -5,7 +5,11 @@ import requests import responses -from src.update_paratranz import create_or_update_file, create_or_update_files, get_project_files +from paradox_localization_utils.update_paratranz import ( + create_or_update_file, + create_or_update_files, + get_project_files, +) from tests.utils import generate_random_str @@ -139,7 +143,7 @@ def raise_error_first_call(url: str, headers: dict, filepath: str, paratranz_pat first_call = False raise requests.HTTPError() - mocker.patch("src.update_paratranz.__post_file_to_paratranz", new=raise_error_first_call) + mocker.patch("paradox_localization_utils.update_paratranz.__post_file_to_paratranz", new=raise_error_first_call) current_files = dict() files_with_errors = [] create_or_update_file(token, project_id, tmp_path, language, str(empty_file), current_files, files_with_errors)