Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 53 additions & 47 deletions docs/pages/guides/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://github.com/ghraw/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://github.com/ghraw/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://github.com/ghraw/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://github.com/ghraw/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://github.com/ghraw/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://github.com/ghraw/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 %}
Expand Down Expand Up @@ -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"]
Expand Down
6 changes: 1 addition & 5 deletions {{cookiecutter.project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -49,6 +44,7 @@ repos:
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

{%- if cookiecutter.backend == "setuptools" or cookiecutter.backend == "pybind11" %}

Expand Down
46 changes: 24 additions & 22 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down