@@ -108,18 +108,20 @@ Here is the snippet to add Black to your `.pre-commit-config.yml`:
108108
109109` ` ` yaml
110110- repo: https://github.com/psf/black-pre-commit-mirror
111- rev: "23.10.0 "
111+ rev: "23.10.1 "
112112 hooks:
113113 - id: black
114114` ` `
115115
116116{% details You can add a Black badge to your repo as well %}
117117
118+ [](https://github.com/psf/black)
119+
118120` ` ` md
119121[](https://github.com/psf/black)
120122` ` `
121123
122- ` ` ` rst
124+ ```
123125.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
124126 :target: https://github.com/psf/black
125127```
@@ -142,13 +144,13 @@ look like Black, but run 30x faster. Here is the snippet to add Black to your
142144
143145{% details You can add a Ruff badge to your repo as well %}
144146
145- [) ](https://github.com/astral-sh/ruff)
147+ [ ![ 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 )
146148
147149``` md
148- [) ](https://github.com/astral-sh/ruff)
150+ [](https://github.com/astral-sh/ruff)
149151```
150152
151- ` ` ` rst
153+ ```
152154.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json
153155 :target: https://github.com/astral-sh/ruff
154156```
@@ -157,13 +159,13 @@ look like Black, but run 30x faster. Here is the snippet to add Black to your
157159
158160{% endtab %} {% endtabs %}
159161
160- In _very_ specific situations, you may want to retain special formatting. After
161- carefully deciding that it is a special use case, you can use `# fmt: on` and
162- ` # fmt: off` around a code block to have it keep custom formatting. _Always_
163- consider refactoring before you try this option! Most of the time, you can find
164- a way to make the Blacked code look better by rewriting your code; factor out
165- long unreadable portions into a variable, avoid writing matrices as 1D lists,
166- etc.
162+ In _ very_ specific situations, like when making a 2D array, you may want to
163+ retain special formatting. After carefully deciding that it is a special use
164+ case, you can use ` # fmt: on ` and ` # fmt: off` around a code block to have it
165+ keep custom formatting. _ Always _ consider refactoring before you try this
166+ option! Most of the time, you can find a way to make the Blacked code look
167+ better by rewriting your code; factor out long unreadable portions into a
168+ variable, avoid writing matrices as 1D lists, etc.
167169
168170{% details Documentation / README snippets support %}
169171
@@ -177,7 +179,7 @@ markdown and restructured text. Note that because black is in
177179 rev : " 1.16.0"
178180 hooks :
179181 - id : blacken-docs
180- additional_dependencies: [black==23.10.0 ]
182+ additional_dependencies : [black==23.* ]
181183` ` `
182184
183185{% enddetails %}
@@ -195,7 +197,7 @@ pre-commit hook.
195197
196198` ` ` yaml
197199- repo : https://github.com/astral-sh/ruff-pre-commit
198- rev: "v0.1.1 "
200+ rev : " v0.1.3 "
199201 hooks :
200202 - id : ruff
201203 args : ["--fix", "--show-fixes"]
@@ -209,7 +211,6 @@ inspect and undo changes in git.
209211` ` ` toml
210212[tool.ruff]
211213src = ["src"]
212- exclude = []
213214
214215[tool.ruff.lint]
215216extend-select = [
@@ -239,15 +240,8 @@ extend-select = [
239240]
240241ignore = [
241242 "PLR", # Design related pylint codes
242- "E501", # Line too long
243- "PT004", # Use underscore for non-returning fixture (use usefixture instead)
244243]
245244typing-modules = ["mypackage._compat.typing"]
246- unfixable = [
247- "T20", # Removes print statements
248- "F841", # Removes unused variables
249- ]
250- flake8-unused-arguments.ignore-variadic-names = true
251245isort.required-imports = ["from __future__ import annotations"]
252246
253247[tool.ruff.lint.per-file-ignores]
@@ -283,7 +277,7 @@ without this).
283277> ```
284278>
285279> This selects the minimum version you want to target (primarily for `"UP"` and
286- > `"I"`) {% rr RF002 %},
280+ > `"I"`) {% rr RF002 %}
287281
288282Here are some good error codes to enable on most (but not all!) projects :
289283
@@ -839,7 +833,8 @@ limiting the default checks or by starting off a new project using them, you can
839833get some very nice linting, including catching some problematic code that
840834otherwise is hard to catch. PyLint is generally not a good candidate for
841835pre-commit, since it needs to have your package installed - it is less static of
842- check than Flake8. Here is a suggested pyproject.toml entry to get you started :
836+ check than Ruff or Flake8. Here is a suggested `pyproject.toml` entry to get you
837+ started :
843838
844839` ` ` toml
845840[tool.pylint]
@@ -871,34 +866,23 @@ You can replace `src` with the module name.
871866
872867# # Jupyter notebook support
873868
874- # ## NBQA
875-
876- You can adapt most tools to notebooks using
877- [nbQA](https://github.com/nbQA-dev/nbQA). The most useful one is probably Ruff :
869+ # ## Ruff
878870
879- ` ` ` yaml
880- - repo: https://github.com/nbQA-dev/nbQA
881- rev: "1.7.0"
882- hooks:
883- - id: nbqa-ruff
884- additional_dependencies: [ruff==0.0.275]
885- ` ` `
886-
887- You can pass extra flags to Ruff via the hook, like
888- `args : ["--extend-ignore=F821,F401"]`.
889-
890- {: .note-title }
891-
892- > Native notebook support
893- >
894- > Ruff 0.257 added experimental notebook support! You currently have to enable
895- > checking `.ipynb` files both in Ruff and pre-commit to use it.
871+ Ruff natively supports notebooks. You have to enable checking `.ipynb` files in
872+ pre-commit to use it with `types_or : [python, pyi, jupyter]`. This should be on
873+ both hooks if using both the linter and the formatter.
896874
897875# ## Black
898876
899877For Black, just make sure you use the `id : black-jupyter` hook instead of
900878`id : black`; that will also include notebooks.
901879
880+ # ## NBQA
881+
882+ You can adapt other tools to notebooks using
883+ [nbQA](https://github.com/nbQA-dev/nbQA). However, check to see if the tool
884+ natively supports notebooks first, several of them do now.
885+
902886# ## Stripping output
903887
904888You also might like the following hook, which cleans Jupyter outputs :
0 commit comments