Skip to content

Commit 43318e8

Browse files
sofidertobar
andauthored
fix error in macOS (#2671)
kudos to Marcos Medrano who provide the code to make this fix 🎉 --------- Co-authored-by: rtobar <rtobarc@gmail.com>
1 parent 981c7cd commit 43318e8

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

scripts/check_spell.py

+43-24
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,46 @@
99

1010
import pospell
1111

12-
# Read custom dictionaries
13-
entries = set()
14-
for filename in Path("dictionaries").glob("*.txt"):
15-
with open(filename, "r") as f:
16-
entries.update(
17-
stripped_line
18-
for stripped_line in (line.strip() for line in f.readlines())
19-
if stripped_line
20-
)
21-
22-
# Write merged dictionary file
23-
output_filename = tempfile.mktemp(suffix="_merged_dict.txt")
24-
with open(output_filename, "w") as f:
25-
for e in entries:
26-
f.write(e)
27-
f.write("\n")
28-
29-
# Run pospell either against all files or the file given on the command line
30-
po_files = sys.argv[1:]
31-
if not po_files:
32-
po_files = Path(".").glob("*/*.po")
33-
34-
errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES")
35-
sys.exit(0 if errors == 0 else -1)
12+
13+
def check_spell(po_files=None):
14+
"""
15+
Check spell in the given list of po_files and log the spell errors details.
16+
17+
If no po_files are given, check spell in all files.
18+
19+
args:
20+
po_files: list of po_files paths.
21+
22+
returns:
23+
- int: spell errors count.
24+
25+
"""
26+
# Read custom dictionaries
27+
entries = set()
28+
for filename in Path("dictionaries").glob("*.txt"):
29+
with open(filename, "r") as f:
30+
entries.update(
31+
stripped_line
32+
for stripped_line in (line.strip() for line in f.readlines())
33+
if stripped_line
34+
)
35+
36+
# Write merged dictionary file
37+
output_filename = tempfile.mktemp(suffix="_merged_dict.txt")
38+
with open(output_filename, "w") as f:
39+
for e in entries:
40+
f.write(e)
41+
f.write("\n")
42+
43+
# Run pospell either against all files or the file given on the command line
44+
if not po_files:
45+
po_files = Path(".").glob("*/*.po")
46+
47+
detected_errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES")
48+
return detected_errors
49+
50+
51+
if __name__ == "__main__":
52+
po_files = sys.argv[1:]
53+
errors = check_spell(po_files)
54+
sys.exit(0 if errors == 0 else -1)

0 commit comments

Comments
 (0)