diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eb4981e8fa..ce3f782041 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,7 +31,6 @@ jobs: run: powrap --check --quiet **/*.po - name: Pospell run: | - python scripts/create_dict.py - pospell -p dict.txt -l es_ES **/*.po + python scripts/check_spell.py - name: Construir documentación run: PYTHONWARNINGS=ignore::FutureWarning sphinx-build -j auto -W --keep-going -b html -d cpython/Doc/_build/doctree -D language=es . cpython/Doc/_build/html diff --git a/.overrides/faq.rst b/.overrides/faq.rst index 06d2d44267..b68a494914 100644 --- a/.overrides/faq.rst +++ b/.overrides/faq.rst @@ -26,8 +26,7 @@ pospell. Pospell puede ser instalada en tu entorno de Python empleando pip Una vez instalado, para chequear el fichero .po sobre el que estás trabajando, ejecuta desde el directorio principal del repo:: - python scripts/create_dict.py # para crear el archivo 'dict.txt' - pospell -p dict.txt -l es_ES path/tu_fichero.po + python scripts/check_spell.py path/tu_fichero.po pospell emplea la herramienta de diccionarios hunspell. Si pospell falla dando como error que no tiene hunspell instalado, lo puedes instalar así: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ed6e250ad1..1d5d78b9e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,13 +5,9 @@ repos: - id: powrap - repo: local hooks: - - id: merge-dicts - name: merge-dicts - entry: python ./scripts/create_dict.py + - id: check-spell + name: Check spelling + entry: python ./scripts/check_spell.py language: python -# This one requires package ``hunspell-es_es`` in Archlinux -- repo: https://github.com/AFPy/pospell - rev: v1.1 - hooks: - - id: pospell - args: ['--personal-dict', 'dict.txt', '--language', 'es_ES', '--language', 'es_AR'] + additional_dependencies: ['pospell>=1.1'] + files: \.po$ diff --git a/Makefile b/Makefile index becb1f77b5..d59324f1ee 100644 --- a/Makefile +++ b/Makefile @@ -89,8 +89,7 @@ progress: venv .PHONY: spell spell: venv - $(VENV)/bin/python scripts/create_dict.py - $(VENV)/bin/pospell -p dict.txt -l es_ES **/*.po + $(VENV)/bin/python scripts/check_spell.py .PHONY: wrap diff --git a/scripts/check_spell.py b/scripts/check_spell.py new file mode 100644 index 0000000000..e9193665f6 --- /dev/null +++ b/scripts/check_spell.py @@ -0,0 +1,35 @@ +""" +Script to check the spelling of one, many or all .po files based +on the custom dictionaries under the 'dictionaries/' directory. +""" + +from pathlib import Path +import sys +import tempfile + +import pospell + +# 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) diff --git a/scripts/create_dict.py b/scripts/create_dict.py deleted file mode 100644 index 5d95ea4a8a..0000000000 --- a/scripts/create_dict.py +++ /dev/null @@ -1,33 +0,0 @@ -from pathlib import Path - -""" -Script to generate the 'dict.txt' dictionary based -on the custom dictionaries under the 'dictionaries/' directory, -but also considering the old words from the 'dict' file. - -This was done with: - awk 1 dict dictionaries/*.txt > dict.txt -but the problem was that windows users, not using Git bash -have the problem that 'awk' is not a valid command, so this -enable them to use the script instead. -""" - -entries = set() - -# Read custom dictionaries -for filename in Path("dictionaries").glob("*.txt"): - with open(filename, "r") as f: - lines = [i.rstrip() for i in f.readlines()] - if lines: - entries.update(set(lines)) - del lines - -# Remove empty string, from empty lines -entries.remove("") - -# Write the 'dict.txt' file -with open("dict.txt", "w") as f: - for e in entries: - f.write(e) - f.write("\n") -print("Created 'dict.txt'")