From 54e1dd6ba20a01e7b3fea8b8e74988875fab049b Mon Sep 17 00:00:00 2001 From: Ivan Bicalho Date: Sat, 6 May 2023 18:07:34 -0300 Subject: [PATCH] add linters --- Makefile | 33 ++++++++++-------------- pyproject.toml | 5 +++- requirements/dev.txt | 12 ++++----- requirements/prod.txt | 1 + setup.cfg | 5 +--- src/python_docx_replace/__init__.py | 1 - src/python_docx_replace/block_handler.py | 6 ++--- src/python_docx_replace/key_changer.py | 2 +- 8 files changed, 28 insertions(+), 37 deletions(-) create mode 100644 requirements/prod.txt 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 5782386..595cda2 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 63afccd..93eb051 100644 --- a/src/python_docx_replace/__init__.py +++ b/src/python_docx_replace/__init__.py @@ -1,5 +1,4 @@ from typing import Any - from python_docx_replace.exceptions import EndTagNotFound, InitialTagNotFound, TableIndexNotFound from python_docx_replace.paragraph import Paragraph 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: