Skip to content

Commit

Permalink
Merge pull request #9209 from Chubercik/ruff-formatter
Browse files Browse the repository at this point in the history
Update Python code style guidelines regarding usage of `ruff`
  • Loading branch information
skyace65 authored Jun 16, 2024
2 parents bf8c53b + 1499311 commit 9cb26f2
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions contributing/development/code_style_guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,35 +267,34 @@ Python
Godot's SCons buildsystem is written in Python, and various scripts included
in the source tree are also using Python.

For those, we follow the `Black style guide <https://github.com/psf/black#the-black-code-style>`__.
Blacken your Python changes using `Black <https://pypi.org/project/black/>`__.
For those, we use the `Ruff linter and code formatter <https://docs.astral.sh/ruff/>`__.

Using black locally
Using ruff locally
~~~~~~~~~~~~~~~~~~~

First of all, you will need to install Black. Black requires Python 3.7+ to run.
First of all, you will need to install Ruff. Ruff requires Python 3.7+ to run.

Installation
^^^^^^^^^^^^

Here's how to install black:
Here's how to install ruff:

::

pip3 install black --user
pip3 install ruff --user


You then have different possibilities to apply black to your changes:
You then have different possibilities to apply ruff to your changes:

Manual usage
^^^^^^^^^^^^

You can apply ``black`` manually to one or more files with the following
You can apply ``ruff`` manually to one or more files with the following
command:

::

black -l 120 <path/to/file(s)>
ruff -l 120 <path/to/file(s)>

- ``-l 120`` means that the allowed number of characters per line is 120.
This number was agreed upon by the developers.
Expand All @@ -307,8 +306,8 @@ Pre-commit hook
~~~~~~~~~~~~~~~

For ease of use, we provide hooks for Git with the `pre-commit <https://pre-commit.com/>`__
Python framework that will run ``black`` automatically on all your commits with the
correct version of ``black``.
Python framework that will run ``ruff`` automatically on all your commits with the
correct version of ``ruff``.
To set up:

::
Expand All @@ -319,7 +318,7 @@ To set up:

You can also run the hook manually with ``pre-commit run``.

.. note::
.. note::

Previously, we supplied a hook in the folder ``misc/hooks``. If you copied the
script manually, these hooks should still work, but symlinks will be broken.
Expand All @@ -331,8 +330,8 @@ Editor integration
^^^^^^^^^^^^^^^^^^

Many IDEs or code editors have beautifier plugins that can be configured to run
black automatically, for example, each time you save a file. For details, you can
check `Black editor integration <https://github.com/psf/black#editor-integration>`__.
ruff automatically, for example, each time you save a file. For details, you can
check `Ruff Integrations <https://docs.astral.sh/ruff/integrations/>`__.

Comment style guide
-------------------
Expand Down

0 comments on commit 9cb26f2

Please sign in to comment.