mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
[4.0.x] Refs #33476 -- Adjusted docs and config files for Black.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Backport of ba94488196
from main
This commit is contained in:
parent
8c407ee7f3
commit
9a7755fa2d
9 changed files with 54 additions and 45 deletions
|
@ -35,10 +35,13 @@ them.
|
|||
Python style
|
||||
============
|
||||
|
||||
* Please conform to the indentation style dictated in the ``.editorconfig``
|
||||
file. We recommend using a text editor with `EditorConfig`_ support to avoid
|
||||
indentation and whitespace issues. The Python files use 4 spaces for
|
||||
indentation and the HTML files use 2 spaces.
|
||||
* All files should be formatted using the `black`_ auto-formatter. This will be
|
||||
run by ``pre-commit`` if that is configured.
|
||||
|
||||
* The project repository includes an ``.editorconfig`` file. We recommend using
|
||||
a text editor with `EditorConfig`_ support to avoid indentation and
|
||||
whitespace issues. The Python files use 4 spaces for indentation and the HTML
|
||||
files use 2 spaces.
|
||||
|
||||
* Unless otherwise specified, follow :pep:`8`.
|
||||
|
||||
|
@ -51,33 +54,11 @@ Python style
|
|||
|
||||
An exception to :pep:`8` is our rules on line lengths. Don't limit lines of
|
||||
code to 79 characters if it means the code looks significantly uglier or is
|
||||
harder to read. We allow up to 119 characters as this is the width of GitHub
|
||||
code review; anything longer requires horizontal scrolling which makes review
|
||||
more difficult. This check is included when you run ``flake8``. Documentation,
|
||||
harder to read. We allow up to 88 characters as this is the line length used
|
||||
by ``black``. This check is included when you run ``flake8``. Documentation,
|
||||
comments, and docstrings should be wrapped at 79 characters, even though
|
||||
:pep:`8` suggests 72.
|
||||
|
||||
* Use four spaces for indentation.
|
||||
|
||||
* Use four space hanging indentation rather than vertical alignment::
|
||||
|
||||
raise AttributeError(
|
||||
'Here is a multiline error message '
|
||||
'shortened for clarity.'
|
||||
)
|
||||
|
||||
Instead of::
|
||||
|
||||
raise AttributeError('Here is a multiline error message '
|
||||
'shortened for clarity.')
|
||||
|
||||
This makes better use of space and avoids having to realign strings if the
|
||||
length of the first line changes.
|
||||
|
||||
* Use single quotes for strings, or a double quote if the string contains a
|
||||
single quote. Don't waste time doing unrelated refactoring of existing code
|
||||
to conform to this style.
|
||||
|
||||
* String variable interpolation may use
|
||||
:py:ref:`%-formatting <old-string-formatting>`, :py:ref:`f-strings
|
||||
<f-strings>`, or :py:meth:`str.format` as appropriate, with the goal of
|
||||
|
@ -146,6 +127,10 @@ Python style
|
|||
"""
|
||||
...
|
||||
|
||||
.. versionchanged:: 4.0.3
|
||||
|
||||
All Python code in Django was reformatted with `black`_.
|
||||
|
||||
.. _coding-style-imports:
|
||||
|
||||
Imports
|
||||
|
@ -397,5 +382,6 @@ JavaScript style
|
|||
For details about the JavaScript code style used by Django, see
|
||||
:doc:`javascript`.
|
||||
|
||||
.. _black: https://black.readthedocs.io/en/stable/
|
||||
.. _editorconfig: https://editorconfig.org/
|
||||
.. _flake8: https://pypi.org/project/flake8/
|
||||
|
|
|
@ -290,9 +290,9 @@ All code changes
|
|||
|
||||
* Does the :doc:`coding style
|
||||
</internals/contributing/writing-code/coding-style>` conform to our
|
||||
guidelines? Are there any ``flake8`` errors? You can install the
|
||||
:ref:`pre-commit <coding-style-pre-commit>` hooks to automatically catch
|
||||
these errors.
|
||||
guidelines? Are there any ``black``, ``flake8``, or ``isort`` errors? You
|
||||
can install the :ref:`pre-commit <coding-style-pre-commit>` hooks to
|
||||
automatically catch these errors.
|
||||
* If the change is backwards incompatible in any way, is there a note
|
||||
in the release notes (``docs/releases/A.B.txt``)?
|
||||
* Is Django's test suite passing?
|
||||
|
|
|
@ -69,16 +69,18 @@ command from any place in the Django source tree:
|
|||
$ tox
|
||||
|
||||
By default, ``tox`` runs the test suite with the bundled test settings file for
|
||||
SQLite, ``flake8``, ``isort``, and the documentation spelling checker. In
|
||||
addition to the system dependencies noted elsewhere in this documentation,
|
||||
the command ``python3`` must be on your path and linked to the appropriate
|
||||
version of Python. A list of default environments can be seen as follows:
|
||||
SQLite, ``black``, ``flake8``, ``isort``, and the documentation spelling
|
||||
checker. In addition to the system dependencies noted elsewhere in this
|
||||
documentation, the command ``python3`` must be on your path and linked to the
|
||||
appropriate version of Python. A list of default environments can be seen as
|
||||
follows:
|
||||
|
||||
.. console::
|
||||
|
||||
$ tox -l
|
||||
py3
|
||||
flake8
|
||||
black
|
||||
flake8>=3.7.0
|
||||
docs
|
||||
isort>=5.1.0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue