Compare commits

...

8 Commits
v1.2 ... main

Author SHA1 Message Date
333540f9a8 Make explicit that French is the default language used
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-11-20 11:09:20 +00:00
87d1a3e26f
Missing hunspell in CI.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-11-20 12:02:55 +01:00
f1a9ae321f
Hello woodpekcer.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-11-20 12:00:45 +01:00
c26878af0b
Bump min Python version to 3.7.
Because I do no longer have a 3.6 on my machine to test it.
2023-11-20 11:58:57 +01:00
b164f089d6
Explicitly fail if dict is missing. 2023-11-20 11:58:43 +01:00
8b753bde26
FIX: Discrepancy between docutils rst and sphinx rst
:rfc: don't allow aliases in docutils implementation.

See: https://sourceforge.net/p/docutils/feature-requests/75/
2023-07-21 09:08:12 +02:00
a626a2f3fb
Bump Python versions used in tests. 2023-07-19 10:46:15 +02:00
07d854dcec
docutils is migrationg to argparse. 2023-07-19 10:46:04 +02:00
6 changed files with 39 additions and 84 deletions

1
.github/FUNDING.yml vendored
View File

@ -1 +0,0 @@
github: JulienPalard

View File

@ -1,44 +0,0 @@
---
name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
name: Run tox
runs-on: ubuntu-latest
strategy:
matrix:
tox:
- py_version: '3.6'
env: py36
- py_version: '3.7'
env: py37
- py_version: '3.8'
env: py38,flake8,mypy,black,pylint,pydocstyle,coverage
- py_version: '3.9'
env: py39
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.tox.py_version }}
- uses: actions/cache@v2
with:
path: .tox
key: ${{ matrix.tox.python-version }}-${{ hashFiles('tox.ini') }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y hunspell
- name: Install tox
run: python3 -m pip install tox
- name: Run tox
run: tox -q -p all -e ${{ matrix.tox.env }}

10
.woodpecker.yml Normal file
View File

@ -0,0 +1,10 @@
---
pipeline:
test:
image: python
commands:
- apt-get update
- apt-get install -y hunspell
- python3 -m pip install tox
- tox run

View File

@ -1,33 +1,34 @@
"""pospell is a spellcheckers for po files containing reStructuedText."""
import io
from string import digits
from unicodedata import category
import collections
import functools
import io
import logging
import multiprocessing
import os
import subprocess
import sys
from typing import List, Tuple
from contextlib import redirect_stderr
from itertools import chain
from pathlib import Path
from shutil import which
from string import digits
from typing import List, Tuple
from unicodedata import category
import docutils.frontend
import docutils.nodes
import docutils.parsers.rst
import polib
import regex
from docutils.parsers.rst import roles
from docutils.utils import new_document
from sphinxlint import rst
import regex
__version__ = "1.2"
__version__ = "1.3"
DEFAULT_DROP_CAPITALIZED = {"fr": True, "fr_FR": True}
Error = Tuple[str, int, str]
input_line = collections.namedtuple("input_line", "filename line text")
@ -138,30 +139,13 @@ def strip_rst(line):
if line.endswith("::"):
# Drop :: at the end, it would cause Literal block expected
line = line[:-2]
line = rst.NORMAL_ROLE_RE.sub("", line)
settings = docutils.frontend.get_default_settings()
settings.pep_references = None
settings.rfc_references = None
settings.pep_base_url = "http://www.python.org/dev/peps/"
settings.pep_file_url_template = "pep-%04d"
parser = docutils.parsers.rst.Parser()
settings = docutils.frontend.Values(
{
"report_level": 2,
"halt_level": 4,
"exit_status_level": 5,
"debug": None,
"warning_stream": None,
"error_encoding": "utf-8",
"error_encoding_error_handler": "backslashreplace",
"language_code": "en",
"id_prefix": "",
"auto_id_prefix": "id",
"pep_references": None,
"pep_base_url": "http://www.python.org/dev/peps/",
"pep_file_url_template": "pep-%04d",
"rfc_references": None,
"rfc_base_url": "http://tools.ietf.org/html/",
"tab_width": 8,
"trim_footnote_reference_space": None,
"syntax_highlight": "long",
"line_length_limit": 10000,
}
)
stderr_stringio = io.StringIO()
with redirect_stderr(stderr_stringio):
document = new_document("<rst-doc>", settings=settings)
@ -261,7 +245,7 @@ def parse_args():
type=str,
default="fr",
help="Language to check, you'll have to install the corresponding "
"hunspell dictionary, on Debian see apt list 'hunspell-*'.",
"hunspell dictionary, on Debian see apt list 'hunspell-*' (defaults to 'fr').",
)
parser.add_argument(
"--glob",
@ -301,7 +285,7 @@ def parse_args():
version="%(prog)s " + __version__ + " using hunspell: " + HUNSPELL_VERSION,
)
parser.add_argument("--debug", action="store_true")
parser.add_argument("-p", "--personal-dict", type=str)
parser.add_argument("-p", "--personal-dict", type=Path)
parser.add_argument(
"--modified", "-m", action="store_true", help="Use git to find modified files."
)
@ -313,6 +297,9 @@ def parse_args():
help="Number of files to check in paralel, defaults to all available CPUs",
)
args = parser.parse_args()
if args.personal_dict is not None and not args.personal_dict.exists():
print(f"Error: dictionary {str(args.personal_dict)!r} not found.")
sys.exit(1)
if args.drop_capitalized and args.no_drop_capitalized:
print("Error: don't provide both --drop-capitalized AND --no-drop-capitalized.")
parser.print_help()
@ -340,7 +327,7 @@ def look_like_a_word(word):
return True
def run_hunspell(language, personal_dict, input_lines):
def run_hunspell(language, personal_dict, input_lines) -> List[Error]:
"""Run hunspell over the given input lines."""
personal_dict_arg = ["-p", personal_dict] if personal_dict else []
try:
@ -350,7 +337,7 @@ def run_hunspell(language, personal_dict, input_lines):
input=quote_for_hunspell(text for _, _, text in input_lines),
)
except subprocess.CalledProcessError:
return -1
return []
return parse_hunspell_output(input_lines, output.splitlines())
@ -413,7 +400,7 @@ def spell_check(
return len(errors)
def parse_hunspell_output(inputs, outputs) -> List[Tuple[str, int, str]]:
def parse_hunspell_output(inputs, outputs) -> List[Error]:
"""Parse `hunspell -a` output and collect all errors."""
# skip first line of hunspell output (it's the banner)
outputs = iter(outputs[1:])

View File

@ -24,11 +24,12 @@ classifiers = [
"Natural Language :: English",
"Programming Language :: Python :: 3",
]
requires-python = ">= 3.6"
requires-python = ">= 3.7"
dependencies = [
"polib",
"docutils>=0.16",
"docutils>=0.18",
"regex",
"sphinx-lint>=0.6.8",
]
dynamic = [
"version",
@ -55,3 +56,5 @@ include-package-data = false
[tool.setuptools.dynamic.version]
attr = "pospell.__version__"
[tool.black]

View File

@ -23,7 +23,7 @@ exclude_lines =
[tox]
envlist = py36, py37, py38, py39, flake8, mypy, black, pylint, pydocstyle, coverage
envlist = py37, py38, py39, py310, py311, py312, flake8, mypy, black, pylint, pydocstyle, coverage
isolated_build = True
skip_missing_interpreters = True
@ -36,7 +36,7 @@ setenv =
COVERAGE_FILE={toxworkdir}/.coverage.{envname}
[testenv:coverage]
depends = py36, py37, py38, py39
depends = py37, py38, py39, py310, py312
parallel_show_output = True
deps = coverage
skip_install = True