From 6c546b534836ed3aef76474af33239d89a8eb790 Mon Sep 17 00:00:00 2001 From: Florian Maas Date: Thu, 14 Dec 2023 14:30:19 +0100 Subject: [PATCH] Replace `black` with `ruff format` (#101) * use ruff as formatter * remove black config --- README.md | 1 - docs/features/linting.md | 17 +---------------- docs/features/makefile.md | 2 +- docs/index.md | 7 +++++-- .../.pre-commit-config.yaml | 11 ++++------- {{cookiecutter.project_name}}/pyproject.toml | 8 +++----- 6 files changed, 14 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f846a99..45aa642 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ This is a modern Cookiecutter template that can be used to initiate a Python pro - CI/CD with [GitHub Actions](https://github.com/features/actions) - Pre-commit hooks with [pre-commit](https://pre-commit.com/) - Code quality with: - - [black](https://pypi.org/project/black/) - [ruff](https://github.com/charliermarsh/ruff) - [mypy](https://mypy.readthedocs.io/en/stable/) - [deptry](https://github.com/fpgmaas/deptry/) diff --git a/docs/features/linting.md b/docs/features/linting.md index 2135402..b0ae670 100644 --- a/docs/features/linting.md +++ b/docs/features/linting.md @@ -10,24 +10,9 @@ Note that this requires the pre-commit hooks to be installed. This command will run the following tools: -## black - -[black](https://pypi.org/project/black/) is used to format the code, and it is configured through `pyproject.toml`: - -```toml -[tool.black] -line-length = 120 -include = '\.pyi?$' -target-version = ['py39'] -fast = true -``` - -To exclude directories or files, add an `exclude` argument to `pre-commit-config.yaml`. Note that adding an `exclude` argument to `pyproject.toml` -will not work, see also [here](https://stackoverflow.com/a/61046953/8037249). - ## ruff -[ruff](https://github.com/charliermarsh/ruff) is used to check the code style, and it is configured through `pyproject.toml`: +[ruff](https://github.com/charliermarsh/ruff) is used to lint and format the code, and it is configured through `pyproject.toml`: ``` [tool.ruff] diff --git a/docs/features/makefile.md b/docs/features/makefile.md index 9caba0f..959457d 100644 --- a/docs/features/makefile.md +++ b/docs/features/makefile.md @@ -7,7 +7,7 @@ available: ``` install Install the poetry environment and install the pre-commit hooks -check Lint and check code by running black, ruff, mypy and deptry. +check Lint and check code by running ruff, mypy and deptry. test Test the code with pytest build Build wheel file using poetry clean-build clean build artifacts diff --git a/docs/index.md b/docs/index.md index f5ca395..4e8b605 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,13 +20,16 @@ This is a modern Cookiecutter template that can be used to initiate a Python pro - [Poetry](https://python-poetry.org/) for dependency management - CI/CD with [GitHub Actions](https://github.com/features/actions) - Pre-commit hooks with [pre-commit](https://pre-commit.com/) -- Code quality with [black](https://pypi.org/project/black/), [ruff](https://github.com/charliermarsh/ruff), [mypy](https://mypy.readthedocs.io/en/stable/), and [deptry](https://github.com/fpgmaas/deptry/) +- Code quality with: + - [ruff](https://github.com/charliermarsh/ruff) + - [mypy](https://mypy.readthedocs.io/en/stable/) + - [deptry](https://github.com/fpgmaas/deptry/) + - [prettier](https://prettier.io/) - Publishing to [Pypi](https://pypi.org) or [Artifactory](https://jfrog.com/artifactory) by creating a new release on GitHub - Testing and coverage with [pytest](https://docs.pytest.org/en/7.1.x/) and [codecov](https://about.codecov.io/) - Documentation with [MkDocs](https://www.mkdocs.org/) - Compatibility testing for multiple versions of Python with [Tox](https://tox.wiki/en/latest/) - Containerization with [Docker](https://www.docker.com/) -- Development environment with [VSCode devcontainers](https://code.visualstudio.com/docs/remote/containers) An example of a repository generated with this package can be found [here](https://github.com/fpgmaas/cookiecutter-poetry-example). diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index f508f0a..5e3015b 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -9,15 +9,12 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.230" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.1.6" hooks: - id: ruff - - - repo: https://github.com/psf/black - rev: "22.8.0" - hooks: - - id: black + args: [--exit-non-zero-on-fix] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-prettier rev: "v3.0.3" diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 7a09b34..9ed5223 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -36,11 +36,6 @@ mkdocstrings = {extras = ["python"], version = "^0.23.0"} requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" -[tool.black] -line-length = 120 -target-version = ['py37'] -preview = true - [tool.mypy] files = ["{{cookiecutter.project_slug}}"] disallow_untyped_defs = "True" @@ -97,6 +92,9 @@ ignore = [ "E731", ] +[tool.ruff.format] +preview = true + {% if cookiecutter.codecov == "y"-%} [tool.coverage.report] skip_empty = true