@@ -20,11 +20,14 @@ consistent, clean, and correct, it probably will be accepted. But
2020don't be surprised if the "offending" code gets fiddled with overtime to
2121conform to these conventions.
2222
23- There are also GitHub actions CI checks for python code style which will annotate the
24- PR diff for you to see the areas where your code is lacking compared to the set standard.
23+ There are also pre-commit CI checks for python code style which will automatically fix the
24+ PR.
25+
26+ Python
27+ ======
2528
2629Rules
27- =====
30+ -----
2831
2932The code must be compatible with the oldest supported version of python
3033which is 3.7
@@ -74,7 +77,7 @@ Conventions`_ and `Typing Conventions`_ PEPs, clarified and extended as follows:
7477 convenient than f-strings.
7578
7679Whitespace
77- ==========
80+ ----------
7881
7982Python is not C/C++ so whitespace should be used sparingly to maintain code readability
8083
@@ -114,7 +117,7 @@ Python is not C/C++ so whitespace should be used sparingly to maintain code rea
114117 emacs/Useless-Whitespace.html
115118
116119General advice
117- ==============
120+ --------------
118121
119122* Get rid of as many ``break `` and ``continue `` statements as possible.
120123
@@ -124,67 +127,30 @@ General advice
124127* Use descriptive variable names.
125128
126129Writing documentation in the code
127- =================================
130+ ---------------------------------
128131
129132Here is an example of how to write good docstrings:
130133
131134 https://github.com/numpy/numpy/blob/master/doc/example.py
132135
133136The NumPy docstring documentation can be found `here <https://numpydoc.readthedocs.io/en/latest/format.html >`_
134137
135- It is a good practice to run `pydocstyle <https://github.com/PyCQA/pydocstyle >`_
136- check on your code or use a text editor that does it automatically):
137-
138- .. code-block :: bash
139-
140- $ pydocstyle filename.py
138+ C++
139+ ===
141140
142- .. _stylecheck :
141+ The customized Clang Format style is used for C++ code formatting. The style is defined in
142+ ``.clang-format `` file in the root of the repository. The style is based on the Google C++
143+ style with some modifications.
143144
144- Run pycodestyle on your code
145- ============================
145+ Run scripts to check the code
146+ =============================
146147
147- It's a good idea to run `pycodestyle <https://github.com/PyCQA/pycodestyle >`_
148- on your code (or use a text editor that does it automatically):
148+ It's a good idea to install `pre-commit <https://pre-commit.com >`_ on your repository:
149149
150150.. code-block :: bash
151151
152- $ pycodestyle filename.py
153-
154- .. _typing :
155-
156- Run mypy on your code
157- =====================
158-
159- It's a good idea to run `mypy <https://github.com/PyCQA/pycodestyle >`_
160- on your code (or use a text editor that does it automatically):
161-
162- .. code-block :: bash
163-
164- $ mypy filename.py
165-
166- .. _docstyle :
167-
168- Run pydocstyle on your code
169- ===========================
170-
171- It's a good idea to run `pycodestyle <https://github.com/PyCQA/pycodestyle >`_
172- on your code (or use a text editor that does it automatically):
173-
174- .. code-block :: bash
175-
176- $ pycodestyle filename.py --max-line-length=88
177-
178- .. _autoformat :
179-
180- Run black on your code
181- ======================
182-
183- Another method of enforcing PEP8 _ is using a tool such as
184- `black <https://github.com/psf/black >`_. These tools tend to be
185- very effective at cleaning up code but should be used carefully and code
186- should be retested after cleaning it. Try:
187-
188- .. code-block :: bash
152+ $ pip install pre-commit
153+ $ pre-commit install
189154
190- $ black --help
155+ The scripts will be run automatically before each commit and will fix the code style
156+ issues automatically.
0 commit comments