|
9 | 9 |
|
10 | 10 | import pospell
|
11 | 11 |
|
12 |
| -# fix multiprocessing error loop on MacOS |
13 |
| -if sys.platform == "darwin": |
14 |
| - import multiprocessing |
15 |
| - multiprocessing.set_start_method("fork") |
16 |
| - |
17 |
| -# Read custom dictionaries |
18 |
| -entries = set() |
19 |
| -for filename in Path("dictionaries").glob("*.txt"): |
20 |
| - with open(filename, "r") as f: |
21 |
| - entries.update( |
22 |
| - stripped_line |
23 |
| - for stripped_line in (line.strip() for line in f.readlines()) |
24 |
| - if stripped_line |
25 |
| - ) |
26 |
| - |
27 |
| -# Write merged dictionary file |
28 |
| -output_filename = tempfile.mktemp(suffix="_merged_dict.txt") |
29 |
| -with open(output_filename, "w") as f: |
30 |
| - for e in entries: |
31 |
| - f.write(e) |
32 |
| - f.write("\n") |
33 |
| - |
34 |
| -# Run pospell either against all files or the file given on the command line |
35 |
| -po_files = sys.argv[1:] |
36 |
| -if not po_files: |
37 |
| - po_files = Path(".").glob("*/*.po") |
38 |
| - |
39 |
| -errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES") |
40 |
| -sys.exit(0 if errors == 0 else -1) |
| 12 | + |
| 13 | +def check_spell(po_files=None): |
| 14 | + # fix multiprocessing error loop on MacOS |
| 15 | + if sys.platform == "darwin": |
| 16 | + import multiprocessing |
| 17 | + multiprocessing.set_start_method("fork") |
| 18 | + |
| 19 | + # Read custom dictionaries |
| 20 | + entries = set() |
| 21 | + for filename in Path("dictionaries").glob("*.txt"): |
| 22 | + with open(filename, "r") as f: |
| 23 | + entries.update( |
| 24 | + stripped_line |
| 25 | + for stripped_line in (line.strip() for line in f.readlines()) |
| 26 | + if stripped_line |
| 27 | + ) |
| 28 | + |
| 29 | + # Write merged dictionary file |
| 30 | + output_filename = tempfile.mktemp(suffix="_merged_dict.txt") |
| 31 | + with open(output_filename, "w") as f: |
| 32 | + for e in entries: |
| 33 | + f.write(e) |
| 34 | + f.write("\n") |
| 35 | + |
| 36 | + # Run pospell either against all files or the file given on the command line |
| 37 | + if not po_files: |
| 38 | + po_files = Path(".").glob("*/*.po") |
| 39 | + |
| 40 | + detected_errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES") |
| 41 | + return detected_errors |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + po_files = sys.argv[1:] |
| 46 | + errors = check_spell(po_files) |
| 47 | + sys.exit(0 if errors == 0 else -1) |
0 commit comments