Skip to content

Commit 92238d8

Browse files
docs: Adding section on Ruff in code style tools page
1 parent 679da01 commit 92238d8

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

doc/source/coding-style/formatting-tools.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,71 @@ Most of the tools presented can be configured using :ref:`the
1111
\`\`pyproject.toml\`\` file`. Avoiding dotfiles leads to a much
1212
cleaner root project directory.
1313

14+
Ruff
15+
----
16+
17+
| `Ruff`_ is a Python linter and code formatter written in Rust.
18+
| It aims to be orders of magnitude faster than alternative tools while integrating more
19+
functionality behind a single, common interface.
20+
| Ruff can be used to replace linters and formatters like ``Flake8`` (natively re-implementing
21+
its popular plugins), ``Black`` and ``isort``: It provides drop-in parity with these tools,
22+
while executing tens or hundreds of times faster. It is actively developed and used in major
23+
open-source projects.
24+
| In addition, it offers the following features and advantages:
25+
26+
- Installable via ``pip``
27+
28+
- ``pyproject.toml`` support
29+
30+
- Python 3.7 to 3.13 compatibility
31+
32+
- Built-in caching, to avoid re-analyzing unchanged files
33+
34+
- Over 800 built-in rules
35+
36+
- Editor integrations for VS Code or PyCharm
37+
38+
A minimum Ruff configuration for a PyAnsys project (to be included in the ``pyproject.toml``)
39+
may look like this:
40+
41+
.. code-block:: toml
42+
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+
"rule_to_ignore", # list all rules that shall be ignored by the linter
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+
| When migrating a project to Ruff, linting and formatting rules shall be added step by step,
73+
gradually resolving the triggered errors.
74+
| For more information about configuring Ruff, as well as a complete description of the available
75+
rules and settings, please refer to the `tool's documentation
76+
<https://docs.astral.sh/ruff/configuration/>`__.
77+
78+
1479
Black
1580
-----
1681

doc/source/links.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
.. _numpy: https://numpy.org/
8383
.. _pandas: https://pandas.pydata.org/
8484
.. _pre-commit: https://pre-commit.com/
85+
.. _Ruff: https://docs.astral.sh/ruff/
8586
.. _scipy: https://scipy.org/
8687
.. _tox: https://tox.wiki/en/latest/
8788
.. _tox_repo: https://github.com/tox-dev/tox

0 commit comments

Comments
 (0)