Skip to content

Commit 160ead9

Browse files
committed
Add tox.
1 parent 4ec2ecb commit 160ead9

File tree

8 files changed

+58
-20
lines changed

8 files changed

+58
-20
lines changed

sphinxlint/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def __call__(self, parser, namespace, values, option_string=None):
5454
sort_fields.append(SortField[field_name.upper()])
5555
except KeyError:
5656
raise ValueError(
57-
f"Unsupported sort field: {field_name}, supported values are {SortField.as_supported_options()}"
57+
f"Unsupported sort field: {field_name}, "
58+
"supported values are {SortField.as_supported_options()}"
5859
) from None
5960
setattr(namespace, self.dest, sort_fields)
6061

@@ -152,8 +153,8 @@ def _check_file(todo):
152153
def sort_errors(results, sorted_by):
153154
"""Flattens and potentially sorts errors based on user prefernces"""
154155
if not sorted_by:
155-
for results in results:
156-
yield from results
156+
for result in results:
157+
yield from result
157158
return
158159
errors = list(error for errors in results for error in errors)
159160
# sorting is stable in python, so we can sort in reverse order to get the

sphinxlint/checkers.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ def check_default_role(file, lines, options=None):
118118
before_match = line[: match.start()]
119119
after_match = line[match.end() :]
120120
stripped_line = line.strip()
121-
if (stripped_line.startswith("|") and stripped_line.endswith("|") and
122-
stripped_line.count("|") >= 4 and "|" in match.group(0)):
121+
if (
122+
stripped_line.startswith("|")
123+
and stripped_line.endswith("|")
124+
and stripped_line.count("|") >= 4
125+
and "|" in match.group(0)
126+
):
123127
return # we don't handle tables yet.
124128
if re.search(rst.ROLE_TAG + "$", before_match):
125129
# It's not a default role: it starts with a tag.
@@ -267,7 +271,10 @@ def check_role_with_double_backticks(file, lines, options=None):
267271
before = paragraph[: inline_literal.start()]
268272
if re.search(rst.ROLE_TAG + "$", before):
269273
error_offset = paragraph[: inline_literal.start()].count("\n")
270-
yield paragraph_lno + error_offset, "role use a single backtick, double backtick found."
274+
yield (
275+
paragraph_lno + error_offset,
276+
"role use a single backtick, double backtick found.",
277+
)
271278
paragraph = (
272279
paragraph[: inline_literal.start()] + paragraph[inline_literal.end() :]
273280
)
@@ -288,9 +295,15 @@ def check_missing_space_before_role(file, lines, options=None):
288295
if match:
289296
error_offset = paragraph[: match.start()].count("\n")
290297
if looks_like_glued(match):
291-
yield paragraph_lno + error_offset, f"missing space before role ({match.group(0)})."
298+
yield (
299+
paragraph_lno + error_offset,
300+
f"missing space before role ({match.group(0)}).",
301+
)
292302
else:
293-
yield paragraph_lno + error_offset, f"role missing opening tag colon ({match.group(0)})."
303+
yield (
304+
paragraph_lno + error_offset,
305+
f"role missing opening tag colon ({match.group(0)}).",
306+
)
294307

295308

296309
@checker(".rst", ".po")
@@ -459,4 +472,4 @@ def check_dangling_hyphen(file, lines, options):
459472
for lno, line in enumerate(lines):
460473
stripped_line = line.rstrip("\n")
461474
if re.match(r".*[a-z]-$", stripped_line):
462-
yield lno + 1, f"Line ends with dangling hyphen"
475+
yield lno + 1, "Line ends with dangling hyphen"

sphinxlint/sphinxlint.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from collections import Counter
22
from dataclasses import dataclass
33
from os.path import splitext
4+
from pathlib import Path
5+
from typing import Optional
46

57
from sphinxlint.utils import hide_non_rst_blocks, po2rst
68

@@ -49,13 +51,12 @@ def check_text(filename, text, checkers, options=None):
4951
return errors
5052

5153

52-
def check_file(filename, checkers, options: CheckersOptions = None):
54+
def check_file(filename, checkers, options: Optional[CheckersOptions] = None):
5355
ext = splitext(filename)[1]
5456
if not any(ext in checker.suffixes for checker in checkers):
5557
return Counter()
5658
try:
57-
with open(filename, encoding="utf-8") as f:
58-
text = f.read()
59+
text = Path(filename).read_text(encoding="UTF-8")
5960
if filename.endswith(".po"):
6061
text = po2rst(text)
6162
except OSError as err:

tests/test_enable_disable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from random import choice
21
import re
2+
from random import choice
33

44
from sphinxlint.__main__ import main
55

tests/test_filter_out_literal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from sphinxlint.utils import hide_non_rst_blocks
22

3-
43
LITERAL = r"""
54
Hide non-RST Blocks
65
===================

tests/test_sphinxlint.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from pathlib import Path
22

3-
from sphinxlint.utils import paragraphs
4-
53
import pytest
64

75
from sphinxlint.__main__ import main
6+
from sphinxlint.utils import paragraphs
87

98
FIXTURE_DIR = Path(__file__).resolve().parent / "fixtures"
109

@@ -69,8 +68,8 @@ def test_sphinxlint_shall_not_pass(file, expected_errors, capsys):
6968

7069
@pytest.mark.parametrize("file", [str(FIXTURE_DIR / "paragraphs.rst")])
7170
def test_paragraphs(file):
72-
with open(file) as f:
73-
lines = f.readlines()
71+
with open(file, encoding="UTF-8") as ifile:
72+
lines = ifile.readlines()
7473
actual = paragraphs(lines)
7574
for lno, para in actual:
7675
firstpline = para.splitlines(keepends=True)[0]

tests/test_xpass_friends.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
This is useful to avoid a sphinx-lint release to break many CIs.
44
"""
55

6-
from pathlib import Path
76
import shlex
7+
from pathlib import Path
88

99
import pytest
1010

1111
from sphinxlint.__main__ import main
1212

13-
1413
FIXTURE_DIR = Path(__file__).resolve().parent / "fixtures"
1514

1615

tox.ini

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[tox]
2+
envlist = py3{8,9,10,11,12}, mypy, black, pylint
3+
isolated_build = True
4+
skip_missing_interpreters = True
5+
6+
[testenv]
7+
deps = pytest
8+
commands = pytest
9+
10+
[testenv:black]
11+
deps = black
12+
skip_install = True
13+
commands = black --check --diff sphinxlint/ tests/
14+
15+
[testenv:mypy]
16+
deps =
17+
mypy
18+
types-polib
19+
skip_install = True
20+
commands = mypy --exclude fixtures --ignore-missing-imports sphinxlint/ tests/
21+
22+
[testenv:pylint]
23+
deps =
24+
pylint
25+
pytest
26+
commands = pylint --ignore fixtures sphinxlint/ tests/ --disable missing-function-docstring,missing-module-docstring,missing-class-docstring,too-few-public-methods,too-many-return-statements --good-names=po

0 commit comments

Comments
 (0)