@@ -11,92 +11,68 @@ Most of the tools presented can be configured using :ref:`the
11
11
\`\` pyproject.toml\`\` file`. Avoiding dotfiles leads to a much
12
12
cleaner root project directory.
13
13
14
- Black
15
- -----
14
+ Ruff
15
+ ----
16
16
17
- `Black `_ is the most popular code formatter in the Python community because it is
18
- maintained by the Python Software Foundation. It allows for a minimum
19
- configuration to ensure that the Python code format looks almost the same across
20
- projects.
17
+ `Ruff `_ is a Python linter and code formatter written in Rust. It aims to be
18
+ orders of magnitude faster than alternative tools while integrating more
19
+ functionality behind a single, common interface. Ruff can therefore be used
20
+ to replace the previously preferred alternatives that were `Flake8 `_
21
+ (natively re-implementing its popular plugins), `Black `_ and `isort `_.
21
22
22
- While ` PEP 8 `_ imposes a default line length of 79 characters, Black has
23
- a default line length of 88 characters.
23
+ It is actively developed, used in major open-source projects, and offers the following
24
+ features and advantages:
24
25
25
- The minimum Black configuration for a PyAnsys project should look like this:
26
+ - Can be installed via `` pip install ruff ``
26
27
27
- .. code-block :: toml
28
-
29
- [tool.black]
30
- line-length = "<length>"
31
-
32
-
33
- The ``isort `` tool
34
- ------------------
35
-
36
- The goal of `isort `_ is to properly format ``import `` statements by making sure
37
- that they follow the standard order:
38
-
39
- #. Library
40
- #. Third-party libraries
41
- #. Custom libraries
28
+ - ``pyproject.toml `` support
42
29
43
- When using `isort `_ with `Black `_, it is important to properly configure both
44
- tools so that no conflicts arise. To accomplish this, use the
45
- ``--profile black `` flag in ``isort ``.
30
+ - Python 3.7 to 3.13 compatibility
46
31
47
- .. code-block :: toml
48
-
49
- [tool.isort]
50
- profile = "black"
51
- force_sort_within_sections = true
52
- line_length = "<length>"
53
- src_paths = ["doc", "src", "tests"]
54
-
55
- Flake8
56
- ------
32
+ - Built-in caching, to avoid re-analyzing unchanged files
57
33
58
- The goal of `Flake8 `_ is to act as a `PEP 8 `_ compliance checker. Again, if
59
- this tool is being used with `Black `_, it is important to make sure that no
60
- conflicts arise.
34
+ - Over 800 built-in rules
61
35
62
- The following configuration is the minimum one to set up Flake8 together with
63
- Black.
36
+ - Editor integrations for VS Code or PyCharm
64
37
65
- The configuration for Flake8 must be specified in a ``.flake8 `` file.
38
+ A minimum Ruff configuration for a PyAnsys project (to be included in the ``pyproject.toml ``)
39
+ may look like this:
66
40
67
41
.. code-block :: toml
68
42
69
- [flake8]
70
- max-line-length = 88
71
- extend-ignore = 'E203'
72
-
73
- Flake8 has many options that can be set within the configuration file.
74
- For more information, see `Full Listing of Options and Their Descriptions
75
- <https://flake8.pycqa.org/en/latest/user/options.html> `__ in the Flake8
76
- documentation.
77
-
78
- The example configuration defines these options:
79
-
80
- - ``exclude ``
81
- Subdirectories and files to exclude when checking.
82
-
83
- - ``select ``
84
- Sequence of error codes that Flake8 is to report errors
85
- for. The set in the preceding configuration is a basic set of errors
86
- for checking and is not an exhaustive list. For more information, see
87
- `Error/Violation Codes <https://flake8.pycqa.org/en/3.9.2/user/error-codes.html >`__
88
- in the Flake8 documentation.
89
-
90
- - ``count ``
91
- Total number of errors to print when checking ends.
92
-
93
- - ``max-complexity ``
94
- Maximum allowed McCabe complexity value for a block of code.
95
- The value of 10 was chosen because it is a common default.
96
-
97
- - ``statistics ``
98
- Number of occurrences of each error or warning code
99
- to print as a report when checking ends.
43
+ [tool.ruff]
44
+ line-length = 100
45
+ fix = true
46
+
47
+ [tool.ruff.format]
48
+ quote-style = "double"
49
+ indent-style = "space"
50
+
51
+ [tool.ruff.lint]
52
+ select = [
53
+ "E", # pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
54
+ "D", # pydocstyle, see https://docs.astral.sh/ruff/rules/#pydocstyle-d
55
+ "F", # pyflakes, see https://docs.astral.sh/ruff/rules/#pyflakes-f
56
+ "I", # isort, see https://docs.astral.sh/ruff/rules/#isort-i
57
+ "N", # pep8-naming, see https://docs.astral.sh/ruff/rules/#pep8-naming-n
58
+ "PTH", # flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
59
+ "TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
60
+ ]
61
+ ignore = [
62
+ "TD003", # Missing issue link in TODOs comment
63
+ ]
64
+
65
+ [tool.ruff.lint.pydocstyle]
66
+ convention = "numpy"
67
+
68
+ [tool.ruff.lint.isort]
69
+ combine-as-imports = true
70
+ force-sort-within-sections = true
71
+
72
+ Linting and formatting rules shall be added step by step when migrating a project to Ruff,
73
+ gradually resolving the triggered errors. For more information about configuring Ruff, as
74
+ well as a complete description of the available rules and settings, please refer to the
75
+ `tool's documentation <https://docs.astral.sh/ruff/configuration/ >`__.
100
76
101
77
102
78
The ``Add-license-headers `` pre-commit hook
@@ -151,20 +127,11 @@ configuration that includes both code and documentation formatting tools.
151
127
152
128
repos :
153
129
154
- - repo : https://github.com/psf/black
155
- rev : X.Y.Z
156
- hooks :
157
- - id : black
158
-
159
- - repo : https://github.com/pycqa/isort
160
- rev : X.Y.Z
161
- hooks :
162
- - id : isort
163
-
164
- - repo : https://github.com/PyCQA/flake8
165
- rev : X.Y.Z
130
+ - repo : https://github.com/astral-sh/ruff-pre-commit
131
+ rev : vX.Y.Z
166
132
hooks :
167
- - id : flake8
133
+ - id : ruff
134
+ - id : ruff-format
168
135
169
136
- repo : https://github.com/codespell-project/codespell
170
137
rev : vX.Y.Z
0 commit comments