Skip to content

Commit

Permalink
Add Black and Ruff to pre-commit configuration.
Browse files Browse the repository at this point in the history
Ensure tools are run in the correct order during linting.

Add pyproject-fmt to linting.

Ensure that Black has the proper target-version.

Remove unnecessary dependencies from lint/ci environments.

Add pyproject-fmt to Credits.

Use autodiscovery for Black and Ruff instead of hardcoded paths.
  • Loading branch information
kpfleming committed Aug 4, 2023
1 parent 7433655 commit 0a62e2e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ repos:
rev: "0.13.0"
hooks:
- id: pyproject-fmt
# Ruff must be run before Black, so Black can reformat fixes made by Ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.282
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: "23.7.0"
hooks:
- id: black
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ global open source software community, in addition to Python
itself. I've listed many of them below, but if I've overlooked any
please do not be offended :-)

* [Black](https://github.com/psf/black)
* [Hatch-Fancy-PyPI-Readme](https://github.com/hynek/hatch-fancy-pypi-readme)
* [Hatch](https://github.com/pypa/hatch)
* [Mypy](https://github.com/python/mypy)
* [Pytest](https://github.com/pytest-dev/pytest)
* [Ruff](https://github.com/astral-sh/ruff)
* [Towncrier](https://github.com/twisted/towncrier)
* [Black](https://pypi.org/project/black)
* [Hatch-Fancy-PyPI-Readme](https://pypi.org/project/hatch-fancy-pypi-readme)
* [Hatch](https://pypi.org/project/hatch)
* [Mypy](https://pypi.org/project/mypy)
* [pyproject-fmt](https://pypi.org/project/pyproject-fmt)
* [Pytest](https://pypi.org/project/pytest)
* [Ruff](https://pypi.org/project/ruff)
* [Towncrier](https://pypi.org/project/towncrier)
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,29 @@ dependencies = [
"black",
"ruff",
"mypy",
"pytest", # needed for type-checking tests
"pyproject-fmt",
]

[tool.hatch.envs.lint.scripts]
lint = [
"black --preview src tests",
"ruff check --fix -- src tests",
"ruff check --fix --show-fixes .",
"black --preview .",
"mypy --package jinjanator_plugin_ansible",
"mypy tests",
"shellcheck workflow-support/*.sh",
"pyproject-fmt pyproject.toml",
]
lint-action = [
"black --check --diff --preview src tests",
"ruff check --format=github -- src tests",
"ruff check --format=github .",
"black --check --diff --preview .",
"mypy --package jinjanator_plugin_ansible",
"mypy tests",
"shellcheck workflow-support/*.sh",
"pyproject-fmt --check pyproject.toml",
]

[tool.hatch.envs.ci]
dependencies = [
"attrs",
"coverage[toml]",
"pytest",
"pytest-cov",
Expand Down Expand Up @@ -172,6 +173,7 @@ replacement = "[#\\1](https://github.com/kpfleming/jinjanator-plugin-ansible/iss

[tool.black]
line-length = 90
target-version = ["py39"]

[tool.ruff]
src = ["src", "tests"]
Expand Down

0 comments on commit 0a62e2e

Please sign in to comment.