Skip to content

Commit fa0d4fe

Browse files
authored
Agregar script para crear dict.txt (#1059)
Usuarios en Windows, que no utilizan Git bash no pueden generar el archivo `dict.txt`, pues no tienen acceso al comando 'awk'. Si bien, la construcción de toda la documentación no es necesaria, este paso es importante incluso cuando se quiere hacer la verificación pospell a un archivo determinado, pues necesitamos el diccionario general que incluye todas las variaciones de 'dictionaries/' y 'dict'.
1 parent e12bd93 commit fa0d4fe

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

.overrides/faq.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pospell. Pospell puede ser instalada en tu entorno de Python empleando pip
2626
Una vez instalado, para chequear el fichero .po sobre el que estás trabajando,
2727
ejecuta desde el directorio principal del repo::
2828

29-
awk 1 dict dictionaries/*.txt > dict.txt
30-
pospell -p dict.txt -l es_AR -l es_ES path/tu_fichero.po
29+
python scripts/create_dict.py # para crear el archivo 'dict.txt'
30+
pospell -p dict.txt -l es_ES path/tu_fichero.po
3131

3232
pospell emplea la herramienta de diccionarios hunspell. Si pospell falla dando
3333
como error que no tiene hunspell instalado, lo puedes instalar así:

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ repos:
77
hooks:
88
- id: merge-dicts
99
name: merge-dicts
10-
entry: ./scripts/merge-dicts.sh
11-
language: script
10+
entry: python ./scripts/create_dict.py
11+
language: python
1212
# This one requires package ``hunspell-es_es`` in Archlinux
1313
- repo: https://github.com/JulienPalard/pospell
1414
rev: v1.0.5

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ install:
1010
- powrap --version
1111
script:
1212
- powrap --check --quiet **/*.po
13-
- awk 1 dict dictionaries/*.txt > dict.txt
13+
- python scripts/create_dict.py
1414
- pospell -p dict.txt -l es_AR -l es_ES **/*.po
1515
- pip install -q -r requirements.txt
1616
- PYTHONWARNINGS=ignore::FutureWarning sphinx-build -j auto -W --keep-going -b html -d cpython/Doc/_build/doctree -D language=es . cpython/Doc/_build/html

Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ progress: venv
8989

9090
.PHONY: spell
9191
spell: venv
92-
# 'cat' tenia el problema que algunos archivos no tenían una nueva línea al final
93-
# 'awk 1' agregará una nueva línea en caso que falte.
94-
awk 1 dict dictionaries/*.txt > dict.txt
92+
$(VENV)/bin/python scripts/create_dict.py
9593
$(VENV)/bin/pospell -p dict.txt -l es_ES **/*.po
9694

9795

scripts/create_dict.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from pathlib import Path
2+
3+
"""
4+
Script to generate the 'dict.txt' dictionary based
5+
on the custom dictionaries under the 'dictionaries/' directory,
6+
but also considering the old words from the 'dict' file.
7+
8+
This was done with:
9+
awk 1 dict dictionaries/*.txt > dict.txt
10+
but the problem was that windows users, not using Git bash
11+
have the problem that 'awk' is not a valid command, so this
12+
enable them to use the script instead.
13+
"""
14+
15+
entries = set()
16+
17+
# Read custom dictionaries
18+
for filename in Path("dictionaries").glob("*.txt"):
19+
with open(filename, "r") as f:
20+
lines = [i.rstrip() for i in f.readlines()]
21+
if lines:
22+
entries.update(set(lines))
23+
del lines
24+
25+
# Remove empty string, from empty lines
26+
entries.remove("")
27+
28+
# Read main 'dict'
29+
with open("dict", "r") as f:
30+
entries.update(set(i.rstrip() for i in f.readlines()))
31+
32+
# Write the 'dict.txt' file
33+
with open("dict.txt", "w") as f:
34+
for e in entries:
35+
f.write(e)
36+
f.write("\n")
37+
print("Created 'dict.txt'")

scripts/merge-dicts.sh

-2
This file was deleted.

0 commit comments

Comments
 (0)