From e0ee59d7dc57c986cc97556ac8325332df11f287 Mon Sep 17 00:00:00 2001 From: billsioros Date: Tue, 4 Jul 2023 15:14:25 +0300 Subject: [PATCH] feat: additional `pre-commit` hooks --- .devcontainer/Dockerfile | 1 + .pre-commit-config.yaml | 18 +++ mkdocs.yml | 4 +- pyproject.toml | 55 +++++---- .../.pre-commit-config.yaml | 24 +++- {{cookiecutter.project_name}}/README.md | 1 + {{cookiecutter.project_name}}/pyproject.toml | 112 ++++++++++-------- 7 files changed, 138 insertions(+), 77 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index db1a0a99..230b1aa1 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -18,6 +18,7 @@ ENV ZSH="${HOME}/.oh-my-zsh" RUN rm -rf ${ZSH} RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" RUN sed -i 's/ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ${HOME}/.zshrc +RUN curl https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-classic.zsh > ${HOME}/.p10k.zsh # Install Powerlevel10k theme RUN git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH/themes/powerlevel10k diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75e7a29a..4d665584 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -65,6 +65,24 @@ repos: hooks: - id: check-github-workflows - id: check-renovate + - repo: https://github.com/PyCQA/docformatter + rev: v1.7.1 + hooks: + - id: docformatter + additional_dependencies: [tomli] + exclude: tests + args: [--config, pyproject.toml] + - repo: https://github.com/PyCQA/bandit + rev: 1.7.5 + hooks: + - id: bandit + additional_dependencies: ["bandit[toml]"] + args: ["-c", "pyproject.toml"] + - repo: https://github.com/tox-dev/pyproject-fmt + rev: 0.11.1 + hooks: + - id: pyproject-fmt + args: [--indent, '2'] - repo: https://github.com/python-poetry/poetry rev: 1.5.0 hooks: diff --git a/mkdocs.yml b/mkdocs.yml index 9204f6da..ad63f09c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -45,8 +45,8 @@ theme: name: Switch to light mode - media: "(prefers-color-scheme: light)" scheme: default - primary: green - accent: green + primary: teal + accent: teal toggle: icon: material/weather-sunny name: Switch to dark mode diff --git a/pyproject.toml b/pyproject.toml index a0f4f93b..a8c0ca5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,29 @@ [build-system] -requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" +requires = [ + "poetry-core>=1", +] + +[tool.black] +line-length = 99 +target-version = ["py37", "py38"] +skip-string-normalization = true +exclude = "{{cookiecutter.project_name}}" + +[tool.isort] +profile = "black" +src_paths = ["cookiecutter-pypackage", "hooks", "tests"] +line_length = 99 + +[tool.pytest.ini_options] +addopts = "-vv --color=yes" +log_cli = false +log_cli_date_format = "%Y-%m-%d %H:%M:%S" +log_cli_format = "%(asctime)s %(levelname)s %(message)s" +log_cli_level = "INFO" +python_files = "test_*.py" +python_functions = "test_*" +testpaths = "tests" [tool.poetry] name = "cookiecutter-pypackage" @@ -58,23 +81,15 @@ lint = { cmd = "poetry run ruff check src", help = "Lint your code for errors" } docs = { shell = "python -c 'import webbrowser; webbrowser.open(\"http://127.0.0.1:8000\")'; poetry run mkdocs serve", help = "Build and serve the documentation" } export = { cmd = "poetry export --without-hashes --dev -o requirements.txt" } -[tool.pytest.ini_options] -addopts = "-vv --color=yes" -log_cli = false -log_cli_date_format = "%Y-%m-%d %H:%M:%S" -log_cli_format = "%(asctime)s %(levelname)s %(message)s" -log_cli_level = "INFO" -python_files = "test_*.py" -python_functions = "test_*" -testpaths = "tests" - -[tool.isort] -profile = "black" -src_paths = ["cookiecutter-pypackage", "hooks", "tests"] -line_length = 99 +[tool.docformatter] +black = true +non-strict = true +non-cap = [ + "cookiecutter-pypackage", +] +recursive = true +in-place = true -[tool.black] -line-length = 99 -target-version = ["py37", "py38"] -skip-string-normalization = true -exclude = "{{cookiecutter.project_name}}" +[tool.bandit] +recursive = true +exclude_dirs = ["tests"] diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index dba424c3..67fba209 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -30,12 +30,6 @@ repos: - id: interrogate args: [-v, --fail-under=100] files: ^src/ - - repo: https://github.com/PyCQA/pydocstyle - rev: 6.3.0 - hooks: - - id: pydocstyle - files: ^src/ - additional_dependencies: [toml] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: @@ -89,6 +83,24 @@ repos: hooks: - id: check-github-workflows - id: check-renovate + - repo: https://github.com/PyCQA/docformatter + rev: v1.7.1 + hooks: + - id: docformatter + additional_dependencies: [tomli] + exclude: tests + args: [--config, pyproject.toml] + - repo: https://github.com/PyCQA/bandit + rev: 1.7.5 + hooks: + - id: bandit + additional_dependencies: ["bandit[toml]"] + args: ["-c", "pyproject.toml"] + - repo: https://github.com/tox-dev/pyproject-fmt + rev: 0.11.1 + hooks: + - id: pyproject-fmt + args: [--indent, '2'] - repo: https://github.com/google/yamlfmt rev: v0.9.0 hooks: diff --git a/{{cookiecutter.project_name}}/README.md b/{{cookiecutter.project_name}}/README.md index 3feb764e..40d433e9 100644 --- a/{{cookiecutter.project_name}}/README.md +++ b/{{cookiecutter.project_name}}/README.md @@ -96,6 +96,7 @@ poetry install # Install pre-commit hooks pre-commit install --install-hooks +pre-commit autoupdate ``` ## :book: Documentation diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 8250547f..24f2d3c6 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -1,6 +1,55 @@ [build-system] -requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" +requires = [ + "poetry-core>=1", +] + +[tool.black] +line-length = 99 +target-version = ["py37", "py38"] +skip-string-normalization = true + +[tool.isort] +profile = "black" +src_paths = ["src/{{cookiecutter.package_name}}", "tests"] +line_length = 99 +known_first_party = "{{cookiecutter.package_name}}" + +[tool.pytest.ini_options] +addopts = "-vv --color=yes" +log_cli = false +log_cli_date_format = "%Y-%m-%d %H:%M:%S" +log_cli_format = "%(asctime)s %(levelname)s %(message)s" +log_cli_level = "INFO" +python_files = "test_*.py" +python_functions = "test_*" +testpaths = "tests" + +[tool.coverage.paths] +source = ["src"] + +[tool.coverage.run] +branch = true +source = ["{{cookiecutter.package_name}}"] + +[tool.coverage.report] +show_missing = true +fail_under = 100 +exclude_lines = ["if self.debug:", "pragma: no cover", "raise NotImplementedError", "if __name__ == .__main__.:"] +ignore_errors = true +omit = ["tests/*"] + +[tool.mypy] +files = ["src/{{cookiecutter.package_name}}"] +warn_unused_configs = true +warn_return_any = true +ignore_missing_imports = true +pretty = true +color_output = true +show_column_numbers = true +show_error_codes = true +show_error_context = true +strict = true [tool.poetry] name = "{{cookiecutter.project_name}}" @@ -66,54 +115,6 @@ lint = { cmd = "poetry run ruff check src", help = "Lint your code for errors" } docs = { shell = "python -c 'import webbrowser; webbrowser.open(\"http://127.0.0.1:8000\")'; poetry run mkdocs serve", help = "Build and serve the documentation" } export = { cmd = "poetry export --without-hashes --dev -o requirements.txt" } -[tool.pytest.ini_options] -addopts = "-vv --color=yes" -log_cli = false -log_cli_date_format = "%Y-%m-%d %H:%M:%S" -log_cli_format = "%(asctime)s %(levelname)s %(message)s" -log_cli_level = "INFO" -python_files = "test_*.py" -python_functions = "test_*" -testpaths = "tests" - -[tool.coverage.paths] -source = ["src"] - -[tool.coverage.run] -branch = true -source = ["{{cookiecutter.package_name}}"] - -[tool.coverage.report] -show_missing = true -fail_under = 100 -exclude_lines = ["if self.debug:", "pragma: no cover", "raise NotImplementedError", "if __name__ == .__main__.:"] -ignore_errors = true -omit = ["tests/*"] - -[tool.isort] -profile = "black" -src_paths = ["src/{{cookiecutter.package_name}}", "tests"] -line_length = 99 -known_first_party = "{{cookiecutter.package_name}}" - -[tool.black] -line-length = 99 -target-version = ["py37", "py38"] -skip-string-normalization = true - -[tool.mypy] -files = ["src/{{cookiecutter.package_name}}"] -warn_unused_configs = true -warn_return_any = true -ignore_missing_imports = true -pretty = true -color_output = true -show_column_numbers = true -show_error_codes = true -show_error_context = true -strict = true - - [tool.ruff] select = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"] ignore = [] @@ -160,3 +161,16 @@ convention = "google" [tool.ruff.flake8-quotes] docstring-quotes = "double" + +[tool.docformatter] +black = true +non-strict = true +non-cap = [ + "{{cookiecutter.package_name}}", +] +recursive = true +in-place = true + +[tool.bandit] +recursive = true +exclude_dirs = ["tests"]