• 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

12.16
/df_gettext_toolkit/parse/parse_plain_text.py
1
from collections.abc import Iterable
3✔
2
from typing import NamedTuple
3✔
3

4

5
def skip_tags(s):
3✔
6
    opened = 0
×
7
    for char in s:
×
8
        if char == "[":
×
9
            opened += 1
×
10
        elif char == "]":
×
11
            opened -= 1
×
12
        elif opened == 0:
×
13
            yield char
×
14

15

16
class PlainTextFileToken(NamedTuple):
3✔
17
    test: str
3✔
18
    is_translatable: bool
3✔
19
    line_number: int
3✔
20

21

22
def parse_plain_text_file(lines: Iterable[str], join_paragraphs=True, start_line=1) -> Iterable[PlainTextFileToken]:
3✔
23
    def local_is_translatable(s):
×
24
        return any(char.islower() for char in skip_tags(s))
×
25

26
    lines = iter(lines)
×
27

28
    paragraph: list[str] = []
×
29

30
    # FIXME: join_paragraphs must only affect on paragraph joining, not line skipping
31
    # so the first line must be skipped before the text is fed to the function
32
    if join_paragraphs:
×
33
        # The first line contains file name, skip it
34
        yield PlainTextFileToken(next(lines), False, start_line)
×
35
        start_line += 1
×
36

37
    paragraph_start_line = start_line
×
38

39
    for line_number, line in enumerate(lines, start_line):
×
40
        if join_paragraphs:
×
41
            if local_is_translatable(line):
×
42
                if line.startswith("[") and not (paragraph and paragraph[-1][-1].isalpha()):
×
43
                    if paragraph:
×
44
                        yield PlainTextFileToken(join_paragraph(paragraph), True, paragraph_start_line)
×
45
                        paragraph = []
×
46
                        paragraph_start_line = line_number
×
47

48
                    if line.rstrip().endswith("]"):
×
49
                        yield PlainTextFileToken(line, True, line_number)
×
50
                    else:
51
                        paragraph.append(line)
×
52
                else:
53
                    paragraph.append(line)
×
54
            else:
55
                if paragraph:
×
56
                    yield PlainTextFileToken(join_paragraph(paragraph), True, paragraph_start_line)
×
57
                    paragraph = []
×
58
                    paragraph_start_line = line_number
×
59

60
                yield PlainTextFileToken(line, False, line_number)  # Not translatable line
×
61
        else:
62
            yield PlainTextFileToken(line, local_is_translatable(line), line_number)
×
63

64
    if paragraph:
×
65
        yield PlainTextFileToken(join_paragraph(paragraph), True, paragraph_start_line)
×
66

67

68
def join_paragraph(paragraph):
3✔
69
    return "\n".join(paragraph)
×
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