Skip to content

Commit d5d41d6

Browse files
committed
move check_spell to a function
1 parent 28a2c9f commit d5d41d6

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

scripts/check_spell.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,39 @@
99

1010
import pospell
1111

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

Comments
 (0)