From 28a2c9f004ff412e3d438cee13127d61dcf2f9b9 Mon Sep 17 00:00:00 2001 From: Sofia Denner Date: Sun, 15 Oct 2023 11:49:35 -0300 Subject: [PATCH 1/4] fix error in macOS --- scripts/check_spell.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/check_spell.py b/scripts/check_spell.py index e9193665f6..a88c3bdf8e 100644 --- a/scripts/check_spell.py +++ b/scripts/check_spell.py @@ -9,6 +9,11 @@ import pospell +# fix multiprocessing error loop on MacOS +if sys.platform == "darwin": + import multiprocessing + multiprocessing.set_start_method("fork") + # Read custom dictionaries entries = set() for filename in Path("dictionaries").glob("*.txt"): From d5d41d61f55d3adef28427d8fe7824fce4969970 Mon Sep 17 00:00:00 2001 From: Sofia Denner Date: Mon, 16 Oct 2023 12:56:19 -0300 Subject: [PATCH 2/4] move check_spell to a function --- scripts/check_spell.py | 65 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/scripts/check_spell.py b/scripts/check_spell.py index a88c3bdf8e..2248a56457 100644 --- a/scripts/check_spell.py +++ b/scripts/check_spell.py @@ -9,32 +9,39 @@ import pospell -# fix multiprocessing error loop on MacOS -if sys.platform == "darwin": - import multiprocessing - multiprocessing.set_start_method("fork") - -# Read custom dictionaries -entries = set() -for filename in Path("dictionaries").glob("*.txt"): - with open(filename, "r") as f: - entries.update( - stripped_line - for stripped_line in (line.strip() for line in f.readlines()) - if stripped_line - ) - -# Write merged dictionary file -output_filename = tempfile.mktemp(suffix="_merged_dict.txt") -with open(output_filename, "w") as f: - for e in entries: - f.write(e) - f.write("\n") - -# Run pospell either against all files or the file given on the command line -po_files = sys.argv[1:] -if not po_files: - po_files = Path(".").glob("*/*.po") - -errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES") -sys.exit(0 if errors == 0 else -1) + +def check_spell(po_files=None): + # fix multiprocessing error loop on MacOS + if sys.platform == "darwin": + import multiprocessing + multiprocessing.set_start_method("fork") + + # Read custom dictionaries + entries = set() + for filename in Path("dictionaries").glob("*.txt"): + with open(filename, "r") as f: + entries.update( + stripped_line + for stripped_line in (line.strip() for line in f.readlines()) + if stripped_line + ) + + # Write merged dictionary file + output_filename = tempfile.mktemp(suffix="_merged_dict.txt") + with open(output_filename, "w") as f: + for e in entries: + f.write(e) + f.write("\n") + + # Run pospell either against all files or the file given on the command line + if not po_files: + po_files = Path(".").glob("*/*.po") + + detected_errors = pospell.spell_check(po_files, personal_dict=output_filename, language="es_ES") + return detected_errors + + +if __name__ == "__main__": + po_files = sys.argv[1:] + errors = check_spell(po_files) + sys.exit(0 if errors == 0 else -1) From 4c30f11901353a9a864baf86f2e4e463e08d2b42 Mon Sep 17 00:00:00 2001 From: Sofia Denner Date: Mon, 16 Oct 2023 13:09:50 -0300 Subject: [PATCH 3/4] remove multiprocessing hack and add docstring --- scripts/check_spell.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/check_spell.py b/scripts/check_spell.py index 2248a56457..b052ea912b 100644 --- a/scripts/check_spell.py +++ b/scripts/check_spell.py @@ -11,11 +11,18 @@ def check_spell(po_files=None): - # fix multiprocessing error loop on MacOS - if sys.platform == "darwin": - import multiprocessing - multiprocessing.set_start_method("fork") + """ + Check spell in the given list of po_files and log the spell errors details. + If not po_files given, check spell in all files. + + args: + po_files: list of po_files paths. + + returns: + - int: spell errors count. + + """ # Read custom dictionaries entries = set() for filename in Path("dictionaries").glob("*.txt"): From 1a5960624a2d886f7ba71a4456042a6b1c1040c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Denner?= Date: Mon, 16 Oct 2023 22:14:56 -0300 Subject: [PATCH 4/4] Update scripts/check_spell.py Co-authored-by: rtobar --- scripts/check_spell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_spell.py b/scripts/check_spell.py index b052ea912b..daf5feb3b6 100644 --- a/scripts/check_spell.py +++ b/scripts/check_spell.py @@ -14,7 +14,7 @@ def check_spell(po_files=None): """ Check spell in the given list of po_files and log the spell errors details. - If not po_files given, check spell in all files. + If no po_files are given, check spell in all files. args: po_files: list of po_files paths.