• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dfint / df-gettext-toolkit / 5871136315

pending completion
5871136315

push

github

insolor
Upgrade style of the type annotations using ruff

157 of 404 branches covered (38.86%)

Branch coverage included in aggregate %.

53 of 53 new or added lines in 18 files covered. (100.0%)

369 of 876 relevant lines covered (42.12%)

1.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/df_gettext_toolkit/create_pot/from_plain_text.py
1
import sys
×
2
from collections.abc import Iterable, Iterator, Sequence
×
3
from pathlib import Path
×
4

5
import typer
×
6

7
from df_gettext_toolkit.parse.parse_plain_text import parse_plain_text_file
×
8
from df_gettext_toolkit.utils.po_utils import TranslationItem, save_pot
×
9

10

11
def extract_translatables_from_file(file, file_path, join_paragraphs, keys):
×
12
    for text_block, is_translatable, line_number in parse_plain_text_file(file, join_paragraphs):
×
13
        if is_translatable:
×
14
            if text_block in keys:
×
15
                print("Key already exists:", repr(text_block), file=sys.stderr)
×
16
            else:
17
                keys.add(text_block)
×
18
                yield TranslationItem(text=text_block.rstrip("\n"), source_file=file_path.name, line_number=line_number)
×
19

20

21
def extract_translatables(files: Iterable[Path], join_paragraphs: bool) -> Iterator[TranslationItem]:
×
22
    keys = set()
×
23
    for file_path in files:
×
24
        if file_path.is_file():
×
25
            print(file_path, file=sys.stderr)
×
26
            with file_path.open() as file:
×
27
                yield from extract_translatables_from_file(file, file_path, join_paragraphs, keys)
×
28

29

30
def create_pot_file(pot_file: typer.FileBinaryWrite, files: Sequence[Path], join_paragraphs: bool):
×
31
    save_pot(
×
32
        pot_file,
33
        extract_translatables(files, join_paragraphs),
34
    )
35

36

37
def main(path: Path, pot_file: typer.FileBinaryWrite, split: bool = True):
×
38
    files = (file for file in path.rglob("*.txt") if file.is_file())
×
39
    create_pot_file(pot_file, sorted(files), not split)
×
40

41

42
if __name__ == "__main__":
43
    typer.run(main)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc