You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -76,9 +77,10 @@ see the relevant sections below in this document.
76
77
Why?
77
78
====
78
79
79
-
You want to start unifying code style in your project using Black_.
80
+
You want to start unifying code style in your project
81
+
using Black_ or `the Ruff formatter`_.
80
82
Maybe you also like to standardize on how to order your imports,
81
-
or do static type checking or other static analysis for your code.
83
+
or convert string formatting to use f-strings.
82
84
83
85
However, instead of formatting the whole code base in one giant commit,
84
86
you'd like to only change formatting when you're touching the code for other reasons.
@@ -92,6 +94,11 @@ for various good reasons, and so far there hasn't been a plan to implemented it
92
94
However, in September 2021 Black developers started to hint towards adding this feature
93
95
after all (`1352`__). This might at least simplify Darker's algorithm substantially.
94
96
97
+
The ``--range`` option in `the Ruff formatter`_
98
+
does allow for partial formatting of a single range,
99
+
but to make use of it,
100
+
Darker would need call `the Ruff formatter`_ once for each modified chunk.
101
+
95
102
__https://github.com/psf/black/issues/134
96
103
__https://github.com/psf/black/issues/142
97
104
__https://github.com/psf/black/issues/245
@@ -105,7 +112,8 @@ This tool is for those who want to do partial formatting right now.
105
112
106
113
Note that this tool is meant for special situations
107
114
when dealing with existing code bases.
108
-
You should just use Black_ and isort_ as is when starting a project from scratch.
115
+
You should just use Black_ or `the Ruff formatter`_, Flynt_ and isort_ as is
116
+
when starting a project from scratch.
109
117
110
118
You may also want to still consider whether reformatting the whole code base in one
111
119
commit would make sense in your particular case. You can ignore a reformatting commit
@@ -161,13 +169,14 @@ Use ``python -m darker`` instead of ``darker`` in that case.
161
169
By default, ``darker`` just runs Black_ to reformat the code.
162
170
You can enable additional features with command line options:
163
171
172
+
- ``--formatter=ruff``: Use `the Ruff formatter`_ instead of Black_.
164
173
- ``-i`` / ``--isort``: Reorder imports using isort_. Note that isort_ must be
165
174
run in the same Python environment as the packages to process, as it imports
166
175
your modules to determine whether they are first or third party modules.
167
176
- ``-f`` / ``--flynt``: Also convert string formatting to use f-strings using the
168
177
``flynt`` package
169
178
170
-
If you only want to run those tools without reformatting with Black,
179
+
If you only want to run isort_ and/or Flynt_ without reformatting code,
171
180
use the ``--formatter=none`` option.
172
181
173
182
*New in version 1.1.0:* The ``-L`` / ``--lint`` option.
@@ -300,6 +309,9 @@ flynt_ (option ``-f`` / ``--flynt``) is also invoked as a subprocess, but passin
300
309
command line options to it is currently not supported. Configuration files need to be
301
310
used instead.
302
311
312
+
Options for `the Ruff formatter`_ are read as usual directly by Ruff itself
313
+
when Darker invokes it as a subprocess.
314
+
303
315
Darker does honor exclusion options in Black configuration files when recursing
304
316
directories, but the exclusions are only applied to Black reformatting.
305
317
Isort is still run on excluded files. Also, individual files explicitly listed on the
@@ -308,6 +320,7 @@ command line are still reformatted even if they match exclusion patterns.
308
320
For more details, see:
309
321
310
322
- `Black documentation about pyproject.toml`_
323
+
- `Ruff documentation about pyproject.toml and ruff.toml`_
311
324
- `isort documentation about config files`_
312
325
- `public GitHub repositories which install and run Darker`_
313
326
- `flynt documentation about configuration files`_
@@ -384,7 +397,7 @@ To change default values for these options for a given project,
384
397
add a ``[tool.darker]`` section to ``pyproject.toml`` in the project's root directory,
385
398
or to a different TOML file specified using the ``-c`` / ``--config`` option.
386
399
387
-
You should configure invoked tools like Black_, isort_ and flynt_
400
+
You should configure invoked tools like Black_, `the Ruff formatter`_, isort_ and flynt_
388
401
using their own configuration files.
389
402
390
403
As an exception, the ``line-length`` and ``target-version`` options in ``[tool.darker]``
@@ -467,6 +480,7 @@ the Graylint_ package. Also removed ``lint =``, ``skip_string_normalization =``
467
480
468
481
.. _Black documentation about pyproject.toml: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
469
482
.. _isort documentation about config files: https://timothycrosley.github.io/isort/docs/configuration/config_files/
483
+
.. _Ruff documentation about pyproject.toml and ruff.toml: https://docs.astral.sh/ruff/formatter/#configuration
470
484
.. _public GitHub repositories which install and run Darker: https://github.com/search?q=%2Fpip+install+.*darker%2F+path%3A%2F%5E.github%5C%2Fworkflows%5C%2F.*%2F&type=code
471
485
.. _flynt documentation about configuration files: https://github.com/ikamensh/flynt#configuration-files
472
486
.. _command line arguments: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#command-line-options
@@ -820,16 +834,19 @@ line options always take highest precedence.
820
834
.. _Pygments: https://pypi.org/project/Pygments/
821
835
822
836
823
-
Guarding against Black compatibility breakage
824
-
=============================================
837
+
Guarding against Black, Flynt and isort compatibility breakage
0 commit comments