diff --git a/Makefile b/Makefile index acfd30d..096c1b0 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,22 @@ .PHONY: install install: - @pip install -r requirements/dev.txt + pip install -r requirements/dev.txt -r requirements/prod.txt .PHONY: venv venv: - @python3 -m venv .venv + python3 -m venv .venv -.PHONY: fix -fix: - @echo "==> fixing black" - @black --line-length 120 src/ - - @echo "==> fixing isort" - @isort src/ +.PHONY: black +black: + black --line-length 120 src -.PHONY: check -check: - @echo "==> checking isort" - @isort --check-only --diff src +.PHONY: ruff +ruff: + ruff check src --fix - @echo "==> checking black" - @black --check --diff --line-length 120 src +.PHONY: mypy +mypy: + mypy src - @echo "==> checking flake8" - @flake8 src - - @echo "==> checking mypy" - @mypy src \ No newline at end of file +.PHONY: fix +fix: black ruff mypy diff --git a/pyproject.toml b/pyproject.toml index fa7093a..f692138 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ [build-system] requires = ["setuptools>=42"] -build-backend = "setuptools.build_meta" \ No newline at end of file +build-backend = "setuptools.build_meta" + +[tool.ruff] +line-length = 120 \ No newline at end of file diff --git a/requirements/dev.txt b/requirements/dev.txt index eab6ea7..dc7720b 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,7 +1,5 @@ -mypy -flake8 -black -isort -build -twine -python-docx \ No newline at end of file +mypy==1.2.0 +ruff==0.0.265 +black==23.3.0 +build==0.10.0 +twine==4.0.2 \ No newline at end of file diff --git a/requirements/prod.txt b/requirements/prod.txt new file mode 100644 index 0000000..e692a3e --- /dev/null +++ b/requirements/prod.txt @@ -0,0 +1 @@ +python-docx>=0.8.11 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 2cea52a..7bc6f94 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,7 +20,4 @@ install_requires = python-docx [options.packages.find] -where = src - -[flake8] -max-line-length=120 \ No newline at end of file +where = src \ No newline at end of file diff --git a/src/python_docx_replace/__init__.py b/src/python_docx_replace/__init__.py index b00bd2b..a2d431f 100644 --- a/src/python_docx_replace/__init__.py +++ b/src/python_docx_replace/__init__.py @@ -1,8 +1,6 @@ import re -from typing import Any - -from python_docx_replace.exceptions import (EndTagNotFound, InitialTagNotFound, - TableIndexNotFound) +from typing import Any, List +from python_docx_replace.exceptions import EndTagNotFound, InitialTagNotFound, TableIndexNotFound from python_docx_replace.paragraph import Paragraph __all__ = ["docx_replace", "docx_blocks", "docx_remove_table"] @@ -91,12 +89,12 @@ def docx_remove_table(doc: Any, index: int) -> None: raise TableIndexNotFound(index, len(doc.tables)) -def docx_get_keys(doc: Any) -> set: +def docx_get_keys(doc: Any) -> List[str]: """ Search for all keys in the Word document and return a list of unique elements ATTENTION: The required format for the keys inside the Word document is: ${key} - + For a document with the following content: "Hello ${name}, is your phone ${phone}?" Result example: ["name", "phone"] """ diff --git a/src/python_docx_replace/block_handler.py b/src/python_docx_replace/block_handler.py index 2b36e9e..4ec5099 100644 --- a/src/python_docx_replace/block_handler.py +++ b/src/python_docx_replace/block_handler.py @@ -37,7 +37,7 @@ def replace(self, initial: str, end: str, keep_block: bool) -> None: if not runs_to_change.get(run_index): runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)] - run_to_change: Dict = runs_to_change.get(run_index) + run_to_change: Dict = runs_to_change.get(run_index) # type: ignore[assignment] if ( (not keep_block) 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: if not runs_to_change.get(run_index): runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)] - run_to_change: Dict = runs_to_change.get(run_index) + run_to_change: Dict = runs_to_change.get(run_index) # type: ignore[assignment] if (not keep_block) or (index in range(key_index, key_index_plus_key_length)): run_to_change[run_char_index] = "" @@ -81,7 +81,7 @@ def clear_key_and_before(self, key: str, keep_block: bool) -> None: if not runs_to_change.get(run_index): runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)] - run_to_change: Dict = runs_to_change.get(run_index) + run_to_change: Dict = runs_to_change.get(run_index) # type: ignore[assignment] if (not keep_block) or (index in range(key_index, key_index_plus_key_length)): run_to_change[run_char_index] = "" diff --git a/src/python_docx_replace/key_changer.py b/src/python_docx_replace/key_changer.py index 8b67275..ebd5abf 100644 --- a/src/python_docx_replace/key_changer.py +++ b/src/python_docx_replace/key_changer.py @@ -33,7 +33,7 @@ def replace(self) -> None: if not self.runs_to_change.get(run_index): self.runs_to_change[run_index] = [char for char_index, char in enumerate(run.text)] - run_to_change: Dict = self.runs_to_change.get(run_index) + run_to_change: Dict = self.runs_to_change.get(run_index) # type: ignore[assignment] if index == index_to_replace: run_to_change[run_char_index] = self.value else: