Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black for developers #383

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions doc/source/contributing_code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ is not available for your operating system/architecture from your list.
'rdkit>=2020.03.1' \
'scikit-learn' \
'seaborn>=0.7.0' \
'tidynamics>1.0.0'
'tidynamics>1.0.0' \
'black=24'

# documentation dependencies
mamba install -c conda-forge \
Expand Down Expand Up @@ -334,7 +335,8 @@ dependencies, do the following:
'scipy>=1.5.0' \
'threadpoolctl' \
'tqdm>=4.43.0' \
'waterdynamics'
'waterdynamics' \
'black=24'

You can also install the following optional dependencies (note that
you will not be able to install all the optional dependencies as
Expand Down Expand Up @@ -450,30 +452,30 @@ Writing new code
Code formatting in Python
-------------------------

MDAnalysis is a project with a long history and many contributors; it hasn't used a consistent coding style. Since version 0.11.0, we are trying to update all the code to conform with `PEP8`_. Our strategy is to update the style every time we touch an old function and thus switch to `PEP8`_ continuously.
Since version 0.11.0, we are trying to update all the code to conform with `PEP8`_.

**Important requirements (from PEP8)**:
- keep line length to **79 characters or less**; break long lines sensibly although for readability we may allow longer lines
- indent with **spaces** and use **4 spaces per level**
**Important requirements (from PEP8):**
- naming:

- classes: `CapitalClasses` (i.e. capitalized nouns without spaces)
- methods and functions: `underscore_methods` (lower case, with underscores for spaces)

We recommend that you use a Python Integrated Development Environment (IDE) (`PyCharm`_ and others) or external tools like `flake8`_ for code linting. For integration of external tools with emacs and vim, check out `elpy`_ (emacs) and `python-mode`_ (vim).

To apply the code formatting in an automated way, you can also use code formatters. External tools include `autopep8`_ and `yapf`_. Most IDEs either have their own code formatter or will work with one of the above through plugins.
See :ref:`format-darker` for notes on maintaining code style compliance with existing tools.
MDAnalysis uses `black`_` for automated code formatting, which is bound by the `black stability policy`_. The configuration for `black`_ is provided in the `pyproject.toml` files. To format your code with `black`_, you can run the following commands:
RMeli marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: bash

black package
black testsuite

.. _`PEP8`: https://www.python.org/dev/peps/pep-0008/
.. _`flake8`: http://flake8.readthedocs.org/en/latest/
.. _`PyCharm`: https://www.jetbrains.com/pycharm/
.. _`elpy`: https://github.com/jorgenschaefer/elpy
.. _`python-mode`: https://github.com/klen/python-mode
.. _`autopep8`: https://github.com/hhatto/autopep8
.. _`yapf`: https://github.com/google/yapf

.. _`black`: https://black.readthedocs.io/en/stable/
.. _`black stability policy`: https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy

Modules and dependencies
------------------------
Expand Down
Loading