@@ -7,20 +7,26 @@ There are many tools for checking code style. This section presents some of
77the most popular ones in the Python ecosystem. A minimum configuration is
88provided for each one so that you can easily include them in your PyAnsys project.
99
10+ .. note ::
11+ This page focuses on code-quality automation for Python projects.
12+ For documentation-focused tools such as ``blacken-docs ``, ``docformatter ``,
13+ ``Vale ``, and ``numpydoc `` validation, see
14+ :ref: `doc_style_tools `.
15+
1016Most of the tools presented can be configured using :ref: `the
1117\`\` pyproject.toml\`\` file`. Avoiding dotfiles leads to a much
1218cleaner root project directory.
1319
1420Ruff
1521----
1622
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 `_
23+ `Ruff `_ is a Python linter and code formatter written in Rust. It aims to be
24+ orders of magnitude faster than alternative tools while integrating more
25+ functionality behind a single, common interface. Ruff can therefore be used
26+ to replace the previously preferred alternatives that were `Flake8 `_
2127(natively re-implementing its popular plugins), `Black `_ and `isort `_.
2228
23- It is actively developed, used in major open-source projects, and offers the following
29+ It is actively developed, used in major open-source projects, and offers the following
2430features and advantages:
2531
2632- Can be installed via ``pip install ruff ``
@@ -47,6 +53,7 @@ may look like this:
4753 [tool.ruff.format]
4854 quote-style = "double"
4955 indent-style = "space"
56+ docstring-code-format = true
5057
5158 [tool.ruff.lint]
5259 select = [
@@ -57,6 +64,7 @@ may look like this:
5764 "N", # pep8-naming, see https://docs.astral.sh/ruff/rules/#pep8-naming-n
5865 "PTH", # flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
5966 "TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
67+ "W", # pycodestyle, see https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
6068 ]
6169 ignore = [
6270 "TD003", # Missing issue link in TODOs comment
@@ -69,9 +77,9 @@ may look like this:
6977 combine-as-imports = true
7078 force-sort-within-sections = true
7179
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
80+ Linting and formatting rules shall be added step by step when migrating a project to Ruff,
81+ gradually resolving the triggered errors. For more information about configuring Ruff, as
82+ well as a complete description of the available rules and settings, see the
7583`tool's documentation <https://docs.astral.sh/ruff/configuration/ >`__.
7684
7785
@@ -126,13 +134,13 @@ configuration that includes both code and documentation formatting tools.
126134.. code-block :: yaml
127135
128136 repos :
129-
137+
130138 - repo : https://github.com/astral-sh/ruff-pre-commit
131139 rev : vX.Y.Z
132140 hooks :
133141 - id : ruff
134142 - id : ruff-format
135-
143+
136144 - repo : https://github.com/codespell-project/codespell
137145 rev : vX.Y.Z
138146 hooks :
@@ -144,7 +152,7 @@ configuration that includes both code and documentation formatting tools.
144152 - id : pydocstyle
145153 additional_dependencies : [toml]
146154 exclude : " tests/"
147-
155+
148156 - repo : https://github.com/ansys/pre-commit-hooks
149157 rev : v0.2.4
150158 hooks :
@@ -168,7 +176,7 @@ Then, ensure that you install it as a ``Git hook`` by running this command:
168176 Use ``pre-commit ``
169177~~~~~~~~~~~~~~~~~~
170178
171- One installed as described, ``pre-commit `` automatically triggers every time
179+ Once installed as described, ``pre-commit `` automatically triggers every time
172180that you try to commit a change. If any hook defined in the ``.pre-commit-config.yaml ``
173181file fails, you must fix the failing files, stage the new changes, and try to commit
174182them again.
@@ -280,3 +288,40 @@ Use the following configuration in your ``.pre-commit-config.yaml`` file to be c
280288
281289 repos :
282290 # Your repository-specific configurations here
291+
292+ CI/CD integration with Ansys reusable actions
293+ ----------------------------------------------
294+
295+ The PyAnsys ecosystem provides a set of reusable GitHub Actions in the
296+ `ansys/actions <https://actions.docs.ansys.com/version/stable/index.html >`_
297+ repository. These actions encapsulate common CI/CD tasks so that individual
298+ PyAnsys projects do not need to re-implement them from scratch.
299+
300+ For code style enforcement in CI, use the ``code-style `` action. It internally
301+ runs ``pre-commit `` with all hooks defined in your ``.pre-commit-config.yaml ``
302+ file, guaranteeing that every pull request is checked against the same rules
303+ that developers run locally.
304+
305+ A minimal job definition looks like this:
306+
307+ .. code-block :: yaml
308+
309+ code-style :
310+ name : " Code style"
311+ runs-on : ubuntu-latest
312+ steps :
313+ - name : " Code style"
314+ uses : ansys/actions/code-style@vX.Y.Z
315+ with :
316+ python-version : ${{ env.MAIN_PYTHON_VERSION }}
317+
318+ .. note ::
319+
320+ Replace ``vX.Y.Z `` with the latest available version. For the full list of
321+ inputs and outputs supported by this action, see the
322+ `Code style action documentation
323+ <https://actions.docs.ansys.com/version/stable/style-actions/index.html#code-style-action> `_.
324+
325+ For a complete list of all reusable actions provided by the PyAnsys ecosystem,
326+ see the `Ansys actions documentation
327+ <https://actions.docs.ansys.com/version/stable/index.html> `_.
0 commit comments