diff --git a/docs/pages/guides/style.md b/docs/pages/guides/style.md index 968b4fe5..31df5b81 100644 --- a/docs/pages/guides/style.md +++ b/docs/pages/guides/style.md @@ -102,57 +102,61 @@ There are a _few_ options, mostly to enable/disable certain files, remove string normalization, and to change the line length, and those go in your `pyproject.toml` file. -{% tabs %} {% tab black Black %} +{% tabs %} {% tab ruff Ruff-format %} -Here is the snippet to add Black to your `.pre-commit-config.yml`: +Ruff, the powerful Rust-based linter, has a formatter that is designed with the +help of some of the Black authors to look 99.9% like Black, but run 30x faster. +Here is the snippet to add the formatter to your `.pre-commit-config.yml` +(combine with the Ruff linter below): ```yaml -- repo: https://github.com/psf/black-pre-commit-mirror - rev: "23.11.0" +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.1.6" hooks: - - id: black + # id: ruff would go here if using both + - id: ruff-format ``` -{% details You can add a Black badge to your repo as well %} +As you likely will be using Ruff if you follow this guide, the formatter is +recommended as well. -[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +{% details You can add a Ruff badge to your repo as well %} + +[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff) ```md -[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) +[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff) ``` ``` -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json + :target: https://github.com/astral-sh/ruff ``` {% enddetails %} -{% endtab %} {% tab ruff Ruff-format %} +{% endtab %} {% tab black Black %} -Ruff, the powerful Rust-based linter, also has a formatter that is designed to -look like Black, but run 30x faster. Here is the snippet to add Black to your -`.pre-commit-config.yml` (combine with Ruff below): +Here is the snippet to add Black to your `.pre-commit-config.yml`: ```yaml -- repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.1.6" +- repo: https://github.com/psf/black-pre-commit-mirror + rev: "23.11.0" hooks: - # id: ruff would go here if using both - - id: ruff-format + - id: black ``` -{% details You can add a Ruff badge to your repo as well %} +{% details You can add a Black badge to your repo as well %} -[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) ```md -[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) ``` ``` -.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json - :target: https://github.com/astral-sh/ruff +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black ``` {% enddetails %} @@ -214,32 +218,34 @@ src = ["src"] [tool.ruff.lint] extend-select = [ - "B", # flake8-bugbear - "I", # isort - "ARG", # flake8-unused-arguments - "C4", # flake8-comprehensions - "EM", # flake8-errmsg - "ICN", # flake8-import-conventions - "G", # flake8-logging-format - "PGH", # pygrep-hooks - "PIE", # flake8-pie - "PL", # pylint - "PT", # flake8-pytest-style - "PTH", # flake8-use-pathlib - "RET", # flake8-return - "RUF", # Ruff-specific - "SIM", # flake8-simplify - "T20", # flake8-print - "UP", # pyupgrade - "YTT", # flake8-2020 - "EXE", # flake8-executable - "NPY", # NumPy specific rules - "PD", # pandas-vet - "FURB", # refurb - "PYI", # flake8-pyi + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet + "FURB", # refurb + "PYI", # flake8-pyi ] ignore = [ - "PLR", # Design related pylint codes + "PLR09", # Too many <...> + "PLR2004", # Magic value used in comparison + "ISC001", # Conflicts with formatter ] typing-modules = ["mypackage._compat.typing"] isort.required-imports = ["from __future__ import annotations"] diff --git a/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/{{cookiecutter.project_name}}/.pre-commit-config.yaml index 357404c9..7f59e38c 100644 --- a/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -3,11 +3,6 @@ ci: autofix_commit_msg: "style: pre-commit fixes" repos: - - repo: https://github.com/psf/black-pre-commit-mirror - rev: "23.11.0" - hooks: - - id: black-jupyter - - repo: https://github.com/adamchainz/blacken-docs rev: "1.16.0" hooks: @@ -49,6 +44,7 @@ repos: hooks: - id: ruff args: ["--fix", "--show-fixes"] + - id: ruff-format {%- if cookiecutter.backend == "setuptools" or cookiecutter.backend == "pybind11" %} diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 41175675..d574060c 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -346,30 +346,32 @@ target-version = "py38" [tool.ruff.lint] extend-select = [ - "B", # flake8-bugbear - "I", # isort - "ARG", # flake8-unused-arguments - "C4", # flake8-comprehensions - "EM", # flake8-errmsg - "ICN", # flake8-import-conventions - "G", # flake8-logging-format - "PGH", # pygrep-hooks - "PIE", # flake8-pie - "PL", # pylint - "PT", # flake8-pytest-style - "PTH", # flake8-use-pathlib - "RET", # flake8-return - "RUF", # Ruff-specific - "SIM", # flake8-simplify - "T20", # flake8-print - "UP", # pyupgrade - "YTT", # flake8-2020 - "EXE", # flake8-executable - "NPY", # NumPy specific rules - "PD", # pandas-vet + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet ] ignore = [ - "PLR", # Design related pylint codes + "PLR09", # Too many <...> + "PLR2004", # Magic value used in comparison + "ISC001", # Conflicts with formatter ] isort.required-imports = ["from __future__ import annotations"] # Uncomment if using a _compat.typing backport