@@ -9,9 +9,9 @@ Most of the tools presented can be configured using :ref:`the
9
9
\`\`pyproject.toml\`\` file`. Avoiding dotfiles leads to a much
10
10
cleaner root project directory.
11
11
12
-
13
12
Black
14
13
-----
14
+
15
15
`Black`_ is the most popular code formatter in the Python community because it is
16
16
maintained by the Python Software Foundation. It allows for a minimum
17
17
configuration to ensure that the Python code format looks almost the same across
@@ -28,17 +28,17 @@ The minimum `black`_ configuration for a PyAnsys project should look like this:
28
28
line-length = "<length>"
29
29
30
30
31
- Isort
32
- -----
31
+ The ``isort``
32
+ -------------
33
+
33
34
The goal of `isort`_ is to properly format ``import`` statements by making sure
34
35
that they follow the standard order:
35
36
36
37
#. library
37
38
#. third-party libraries
38
39
#. custom libraries
39
40
40
-
41
- When using `isort`_ with `black`_, it is important to properly configure both
41
+ When using `isort`_ with `Black`_, it is important to properly configure both
42
42
tools so that no conflicts arise. To accomplish this, use the
43
43
``--profile black`` flag in `isort`_.
44
44
@@ -51,11 +51,11 @@ tools so that no conflicts arise. To accomplish this, use the
51
51
default_section = "THIRDPARTY"
52
52
src_paths = ["doc", "src", "tests"]
53
53
54
-
55
54
Flake8
56
55
------
57
- The goal of `flake8` is to act as a `PEP 8`_ compliance checker. Again, if
58
- this tool is being used with `black`_, it is important to make sure that no
56
+
57
+ The goal of `Flake8` is to act as a `PEP 8`_ compliance checker. Again, if
58
+ this tool is being used with `Black`_, it is important to make sure that no
59
59
conflicts arise.
60
60
61
61
The following configuration is the minimum one to set up `flake8`_ together with
@@ -100,6 +100,7 @@ The example configuration defines these options:
100
100
101
101
Add-license-headers
102
102
-------------------
103
+
103
104
The goal of the ``add-license-headers`` pre-commit hook is to add and update license headers
104
105
for files with `REUSE <https://reuse.software/>`_. By default, the hook runs on
105
106
PROTO files in any directory and on Python files in the ``src``, ``examples``, and ``tests`` directories.
@@ -110,9 +111,9 @@ You can find the MIT license that is added to the files in
110
111
111
112
For information on customizing the hook, see the `README <https://github.com/ansys/pre-commit-hooks/blob/main/README.rst>` file.
112
113
113
-
114
114
Code coverage
115
115
-------------
116
+
116
117
Code coverage indicates the percentage of the codebase tested by the test
117
118
suite. Code coverage should be as high as possible to guarantee that every piece
118
119
of code has been tested.
@@ -132,8 +133,9 @@ project:
132
133
[tool.coverage.report]
133
134
show_missing = true
134
135
135
- Pre-commit
136
- ----------
136
+ The ``pre-commit``
137
+ ------------------
138
+
137
139
To ensure that every commit you make is compliant with the code style
138
140
guidelines for PyAnsys, you can take advantage of `pre-commit`_ in your project.
139
141
Every time you stage some changes and try to commit them, `pre-commit`_ only
@@ -144,7 +146,6 @@ The configuration for `pre-commit`_ must be defined in a
144
146
`pre-commit`_ configuration that includes both code and documentation
145
147
formatting tools.
146
148
147
-
148
149
.. code-block:: yaml
149
150
150
151
repos:
@@ -183,6 +184,7 @@ formatting tools.
183
184
184
185
Installing ``pre-commit``
185
186
~~~~~~~~~~~~~~~~~~~~~~~~~
187
+
186
188
You can install ``pre-commit`` by running:
187
189
188
190
.. code-block:: bash
@@ -197,6 +199,7 @@ Then, ensure that you install it as a ``Git hook`` by running:
197
199
198
200
Using ``pre-commit``
199
201
~~~~~~~~~~~~~~~~~~~~
202
+
200
203
One installed as described, ``pre-commit`` automatically triggers every time
201
204
that you try to commit a change. If any hook defined in `.pre-commit-config.yaml`
202
205
fails, you must fix the failing files, stage the new changes, and try to commit
@@ -213,6 +216,7 @@ the hooks fail.
213
216
214
217
Tox
215
218
---
219
+
216
220
You might consider using `tox`_ in your project. While this automation
217
221
tool is similar to `Make`_, it supports testing of your package in a temporary
218
222
virtual environment. Being able to test your package in isolation rather than in
@@ -221,7 +225,6 @@ virtual environment. Being able to test your package in isolation rather than in
221
225
Configuration for `tox`_ is stored in a ``tox.ini`` file. The minimum
222
226
configuration for a PyAnsys ``py<product>-<library>`` project should be:
223
227
224
-
225
228
.. tab-set::
226
229
227
230
.. tab-item:: Tox with Flit
@@ -232,21 +235,20 @@ configuration for a PyAnsys ``py<product>-<library>`` project should be:
232
235
233
236
.. include:: code/tox-poetry.rst
234
237
235
-
236
- This minimum configuration assumes that you have a ``requirements/`` directory that
237
- contains ``requirements_tests.txt`` and ``requirements_doc.txt``. In
238
+ This minimum configuration assumes that you have a ``requirements`` directory that
239
+ contains ``requirements_tests.txt`` and ``requirements_doc.txt`` files. In
238
240
addition, the ``style`` environment must execute ``pre-commit``, which guarantees
239
241
the usage of this tool in your project.
240
242
241
243
Installing ``tox``
242
244
~~~~~~~~~~~~~~~~~~
245
+
243
246
You can install ``tox`` like any other Python package:
244
247
245
248
.. code-block:: bash
246
249
247
250
python -m pip install tox
248
251
249
-
250
252
Using ``tox``
251
253
~~~~~~~~~~~~~
252
254
@@ -262,10 +264,9 @@ It is possible to run multiple environments by separating them with commas ``tox
262
264
-e <env-name0>,<env-name1>,...```. To run all available environments, simply
263
265
run ``tox``.
264
266
265
-
266
267
.. LINKS AND REFERENCES
267
268
268
- .. _black : https://black.readthedocs.io/en/latest/
269
+ .. _Black : https://black.readthedocs.io/en/latest/
269
270
.. _isort: https://pycqa.github.io/isort/
270
271
.. _flake8: https://flake8.pycqa.org/en/latest/
271
272
.. _pre-commit: https://pre-commit.com/
0 commit comments