• 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/csv_bisect/csv_bisect.py
1
import shutil
×
2
from pathlib import Path
×
3

4
from df_gettext_toolkit.utils import csv_utils
×
5
from df_gettext_toolkit.utils.backup import backup
×
6

7

8
def split_left(start, end):
×
9
    mid = (start + end) // 2
×
10
    return start, mid
×
11

12

13
def split_right(start, end):
×
14
    mid = (start + end) // 2
×
15
    return mid, end
×
16

17

18
def bisect(file_path: Path, encoding: str, data: list[list[str]]):
×
19
    def _bisect(start: int, end: int, bad: bool = False) -> bool:
×
20
        """
21
        returns:
22
        - True -> found
23
        - False -> not found
24
        """
25
        if start >= end:
×
26
            print("Empty slice, step back")
×
27
            return False
×
28

29
        print(f"From {start} to {end} (in total {end - start})")
×
30
        csv_utils.write_csv(file_path, encoding, data[start:end])
×
31

32
        if bad:
×
33
            confirmed = True
×
34
        else:
35
            confirmed = input("Is it bad (Y/N)? ").upper() == "Y"
×
36

37
        if not confirmed:
×
38
            return False
×
39

40
        if start == end - 1:
×
41
            print(f"Found string, line number {start+1}:")
×
42
            print(data[start])
×
43

44
            confirmed = input("Exclude from csv (Y/N)? ").upper() == "Y"
×
45
            if confirmed:
×
46
                csv_utils.write_csv(file_path, encoding, data[:start] + data[start + 1 :])
×
47

48
            return True
×
49

50
        print("Trying left half")
×
51
        result = _bisect(*split_left(start, end))
×
52
        if result:
×
53
            return result
×
54

55
        print("Trying right half")
×
56
        return _bisect(*split_right(start, end), bad=True)
×
57

58
    _bisect(0, len(data), bad=True)
×
59

60

61
def main(csv_file: Path, encoding: str):
×
62
    assert csv_file.is_file(), f"{csv_file.name} is not a file"
×
63

64
    try:
×
65
        with backup(csv_file, overwrite=True) as backup_path:
×
66
            data = list(csv_utils.read_csv(backup_path, encoding))
×
67
            bisect(csv_file, encoding, data)
×
68
    finally:
69
        confirmed = input("Restore from backup (Y/N)? ").upper() == "Y"
×
70
        if confirmed:
×
71
            shutil.copy(backup_path, csv_file)
×
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