diff --git a/.overrides/faq.rst b/.overrides/faq.rst index a816dbb1ed..78bb6e8acc 100644 --- a/.overrides/faq.rst +++ b/.overrides/faq.rst @@ -26,8 +26,8 @@ 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:: - awk 1 dict dictionaries/*.txt > dict.txt - pospell -p dict.txt -l es_AR -l es_ES path/tu_fichero.po + python scripts/create_dict.py # para crear el archivo 'dict.txt' + pospell -p dict.txt -l es_ES 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 e12a13d92f..c7efaa4324 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,8 +7,8 @@ repos: hooks: - id: merge-dicts name: merge-dicts - entry: ./scripts/merge-dicts.sh - language: script + entry: python ./scripts/create_dict.py + language: python # This one requires package ``hunspell-es_es`` in Archlinux - repo: https://github.com/JulienPalard/pospell rev: v1.0.5 diff --git a/.travis.yml b/.travis.yml index d4b73e2897..caef7bfecb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: - powrap --version script: - powrap --check --quiet **/*.po - - awk 1 dict dictionaries/*.txt > dict.txt + - python scripts/create_dict.py - pospell -p dict.txt -l es_AR -l es_ES **/*.po - pip install -q -r requirements.txt - 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/Makefile b/Makefile index af4788b25f..beda468e0e 100644 --- a/Makefile +++ b/Makefile @@ -89,9 +89,7 @@ progress: venv .PHONY: spell spell: venv - # 'cat' tenia el problema que algunos archivos no tenían una nueva línea al final - # 'awk 1' agregará una nueva línea en caso que falte. - awk 1 dict dictionaries/*.txt > dict.txt + $(VENV)/bin/python scripts/create_dict.py $(VENV)/bin/pospell -p dict.txt -l es_ES **/*.po diff --git a/scripts/create_dict.py b/scripts/create_dict.py new file mode 100644 index 0000000000..882e92e106 --- /dev/null +++ b/scripts/create_dict.py @@ -0,0 +1,37 @@ +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("") + +# Read main 'dict' +with open("dict", "r") as f: + entries.update(set(i.rstrip() for i in f.readlines())) + +# 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'") diff --git a/scripts/merge-dicts.sh b/scripts/merge-dicts.sh deleted file mode 100755 index b96943aeff..0000000000 --- a/scripts/merge-dicts.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -awk 1 dict dictionaries/*.txt > dict.txt