Skip to content

Commit e1d831e

Browse files
authored
add linters (#16)
1 parent 5aa58df commit e1d831e

File tree

8 files changed

+32
-42
lines changed

8 files changed

+32
-42
lines changed

Makefile

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
.PHONY: install
22
install:
3-
@pip install -r requirements/dev.txt
3+
pip install -r requirements/dev.txt -r requirements/prod.txt
44

55
.PHONY: venv
66
venv:
7-
@python3 -m venv .venv
7+
python3 -m venv .venv
88

9-
.PHONY: fix
10-
fix:
11-
@echo "==> fixing black"
12-
@black --line-length 120 src/
13-
14-
@echo "==> fixing isort"
15-
@isort src/
9+
.PHONY: black
10+
black:
11+
black --line-length 120 src
1612

17-
.PHONY: check
18-
check:
19-
@echo "==> checking isort"
20-
@isort --check-only --diff src
13+
.PHONY: ruff
14+
ruff:
15+
ruff check src --fix
2116

22-
@echo "==> checking black"
23-
@black --check --diff --line-length 120 src
17+
.PHONY: mypy
18+
mypy:
19+
mypy src
2420

25-
@echo "==> checking flake8"
26-
@flake8 src
27-
28-
@echo "==> checking mypy"
29-
@mypy src
21+
.PHONY: fix
22+
fix: black ruff mypy

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[build-system]
22
requires = ["setuptools>=42"]
3-
build-backend = "setuptools.build_meta"
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.ruff]
6+
line-length = 120

requirements/dev.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
mypy
2-
flake8
3-
black
4-
isort
5-
build
6-
twine
7-
python-docx
1+
mypy==1.2.0
2+
ruff==0.0.265
3+
black==23.3.0
4+
build==0.10.0
5+
twine==4.0.2

requirements/prod.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-docx>=0.8.11

setup.cfg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ install_requires =
2020
python-docx
2121

2222
[options.packages.find]
23-
where = src
24-
25-
[flake8]
26-
max-line-length=120
23+
where = src

src/python_docx_replace/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import re
2-
from typing import Any
3-
4-
from python_docx_replace.exceptions import (EndTagNotFound, InitialTagNotFound,
5-
TableIndexNotFound)
2+
from typing import Any, List
3+
from python_docx_replace.exceptions import EndTagNotFound, InitialTagNotFound, TableIndexNotFound
64
from python_docx_replace.paragraph import Paragraph
75

86
__all__ = ["docx_replace", "docx_blocks", "docx_remove_table"]
@@ -91,12 +89,12 @@ def docx_remove_table(doc: Any, index: int) -> None:
9189
raise TableIndexNotFound(index, len(doc.tables))
9290

9391

94-
def docx_get_keys(doc: Any) -> set:
92+
def docx_get_keys(doc: Any) -> List[str]:
9593
"""
9694
Search for all keys in the Word document and return a list of unique elements
9795
9896
ATTENTION: The required format for the keys inside the Word document is: ${key}
99-
97+
10098
For a document with the following content: "Hello ${name}, is your phone ${phone}?"
10199
Result example: ["name", "phone"]
102100
"""

src/python_docx_replace/block_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def replace(self, initial: str, end: str, keep_block: bool) -> None:
3737
if not runs_to_change.get(run_index):
3838
runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)]
3939

40-
run_to_change: Dict = runs_to_change.get(run_index)
40+
run_to_change: Dict = runs_to_change.get(run_index) # type: ignore[assignment]
4141
if (
4242
(not keep_block)
4343
or (index in range(initial_index, initial_index_plus_key_length))
@@ -61,7 +61,7 @@ def clear_key_and_after(self, key: str, keep_block: bool) -> None:
6161
if not runs_to_change.get(run_index):
6262
runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)]
6363

64-
run_to_change: Dict = runs_to_change.get(run_index)
64+
run_to_change: Dict = runs_to_change.get(run_index) # type: ignore[assignment]
6565
if (not keep_block) or (index in range(key_index, key_index_plus_key_length)):
6666
run_to_change[run_char_index] = ""
6767

@@ -81,7 +81,7 @@ def clear_key_and_before(self, key: str, keep_block: bool) -> None:
8181
if not runs_to_change.get(run_index):
8282
runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)]
8383

84-
run_to_change: Dict = runs_to_change.get(run_index)
84+
run_to_change: Dict = runs_to_change.get(run_index) # type: ignore[assignment]
8585
if (not keep_block) or (index in range(key_index, key_index_plus_key_length)):
8686
run_to_change[run_char_index] = ""
8787

src/python_docx_replace/key_changer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def replace(self) -> None:
3333
if not self.runs_to_change.get(run_index):
3434
self.runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)]
3535

36-
run_to_change: Dict = self.runs_to_change.get(run_index)
36+
run_to_change: Dict = self.runs_to_change.get(run_index) # type: ignore[assignment]
3737
if index == index_to_replace:
3838
run_to_change[run_char_index] = self.value
3939
else:

0 commit comments

Comments
 (0)