Skip to content

Commit

Permalink
Autofix some of ruff warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Jun 1, 2024
1 parent 9e8c66b commit 70d4429
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 20 deletions.
3 changes: 1 addition & 2 deletions df_translation_toolkit/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import typer

import df_translation_toolkit.convert as convert
from df_translation_toolkit import create_pot
from df_translation_toolkit import convert, create_pot

app = typer.Typer()
app.add_typer(convert.cli.app, name="convert")
Expand Down
4 changes: 2 additions & 2 deletions df_translation_toolkit/convert/objects_po_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_translations_from_tag_parts(original_parts: list[str], translation_parts

prev_original = None
prev_translation = None
for original, translation in zip(original_parts, translation_parts):
for original, translation in zip(original_parts, translation_parts, strict=False):
original: str
if all_caps(original) or original.isdecimal():
if original == "STP" and translation != original and not all_caps(translation):
Expand Down Expand Up @@ -81,7 +81,7 @@ def main(po_file: Path, csv_file: Path, encoding: str, append: bool = False, err
Convert a po file into a csv file in a specified encoding
"""

with open(po_file, "r", encoding="utf-8") as pofile:
with open(po_file, encoding="utf-8") as pofile:
mode = "a" if append else "w"
with open(csv_file, mode, newline="", encoding=encoding, errors="replace") as outfile:
with maybe_open(errors_file, "w", encoding="utf-8") as errors_file:
Expand Down
10 changes: 5 additions & 5 deletions df_translation_toolkit/create_mod/from_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def localize_directory(
with backup(file_path) as bak_name:
if object_type == "TEXT_SET":
yield from translate_plain_text_file(
bak_name, file_path, dictionaries.dictionary_textset, destination_encoding, False
bak_name, file_path, dictionaries.dictionary_textset, destination_encoding, False,
)
else:
yield from translate_single_raw_file(
bak_name, file_path, dictionaries.dictionary_object, destination_encoding
bak_name, file_path, dictionaries.dictionary_object, destination_encoding,
)


Expand Down Expand Up @@ -99,11 +99,11 @@ def get_dictionaries(translation_path: Path, language: str) -> Dictionaries:
if not po_files[po_file].is_file():
raise Exception(f"Unable to find {po_file} po file for language {language}")

with open(po_files["objects"], "r", encoding="utf-8") as pofile:
with open(po_files["objects"], encoding="utf-8") as pofile:
dictionary_object: Mapping[tuple[str, str | None], str] = {
(item.id, item.context): item.string for item in read_po(pofile)
}
with open(po_files["text_set"], "r", encoding="utf-8") as po_file:
with open(po_files["text_set"], encoding="utf-8") as po_file:
dictionary_textset: Mapping[str, str] = {item.id: item.string for item in read_po(po_file) if item.id}
return Dictionaries(language.lower(), dictionary_object, dictionary_textset)

Expand Down Expand Up @@ -138,7 +138,7 @@ def main(
template_path.rename(template_path.parent / f"{template_path.name}_translation")
logger.warning(
"All done! Consider to change info.txt file and made unique preview.png "
"before uploading to steam or sharing the mod."
"before uploading to steam or sharing the mod.",
)


Expand Down
1 change: 0 additions & 1 deletion df_translation_toolkit/create_mod/generate_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jinja2
import typer


# from cairosvg import svg2png


Expand Down
3 changes: 1 addition & 2 deletions df_translation_toolkit/parse/parse_raws.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def last_suitable(parts: Sequence[T], func: Callable[[T], bool]) -> int:
for i in range(len(parts) - 1, -1, -1):
if func(parts[i]):
return i + 1 # if the last element is suitable, then return len(s), so that s[:i] gives full list
else:
return 0 # if there aren't suitable elements, then return 0, so that s[:i] gives empty list
return 0 # if there aren't suitable elements, then return 0, so that s[:i] gives empty list


class RawFileToken(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion df_translation_toolkit/utils/fix_translated_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def fix_unicode_symbols(s: str):
"\ufeff": None,
"\u200b": None,
"—": "-", # Replace Em Dash with the standard dash (unidecode replaces it with two dash symbols)
}
},
)


Expand Down
3 changes: 1 addition & 2 deletions df_translation_toolkit/utils/po_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from collections.abc import Iterable
from dataclasses import dataclass
from typing import BinaryIO
from typing import BinaryIO, TextIO

from babel.messages import Catalog
from babel.messages.pofile import read_po, write_po
from typing import TextIO


@dataclass
Expand Down
6 changes: 3 additions & 3 deletions df_translation_toolkit/validation/validate_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def validate_tag(original_tag: str, translation_tag: str) -> Iterator[Validation
yield ValidationProblem("Too short or empty translation")
return

if not translation_tag.strip() == translation_tag:
if translation_tag.strip() != translation_tag:
yield ValidationProblem("Extra spaces at the beginning or at the end of the translation")
translation_tag = translation_tag.strip()
# No return to check issues with brackets after stripping spaces
Expand All @@ -33,7 +33,7 @@ def validate_tag(original_tag: str, translation_tag: str) -> Iterator[Validation


def validate_tag_parts(original_parts: list[str], translation_parts: list[str]) -> Iterator[ValidationProblem]:
for original, translation in zip(original_parts, translation_parts):
for original, translation in zip(original_parts, translation_parts, strict=False):
if all_caps(original) or original.isdecimal():
valid = not (original != translation and original == translation.strip())
if not valid:
Expand All @@ -46,7 +46,7 @@ def validate_tag_parts(original_parts: list[str], translation_parts: list[str])
valid = original not in {"SINGULAR", "PLURAL"} or translation in {"SINGULAR", "PLURAL"}
if not valid:
yield ValidationProblem(
"SINGULAR can be changed only to PLURAL, and PLURAL can be changed only to SINGULAR"
"SINGULAR can be changed only to PLURAL, and PLURAL can be changed only to SINGULAR",
)

if original == "STP" and translation == "STP":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parse_raws.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
| [DEFAULT_RELSIZE:2000]
| [BP:UB:body:bodies][UPPERBODY][LOWERBODY][HEAD][THOUGHT][CATEGORY:BODY][FLIER] # Duplicate entry - must be ignored
| [DEFAULT_RELSIZE:2000]
"""
""",
).strip(),
[
TranslationItem(context="BODY:BASIC_1PARTBODY", text="[BP:UB:body:bodies]"),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validation_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from df_translation_toolkit.validation.validation_models import ProblemSeverity, ValidationProblem, ValidationException
from df_translation_toolkit.validation.validation_models import ProblemSeverity, ValidationException, ValidationProblem


@pytest.mark.parametrize(
Expand Down

0 comments on commit 70d4429

Please sign in to comment.