forked from saleor/saleor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split contributing and add Python style overview
- Loading branch information
Showing
5 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Coding Style | ||
============ | ||
|
||
|
||
Python | ||
------ | ||
|
||
Always follow `PEP 8 <https://www.python.org/dev/peps/pep-0008/>`_ but keep in mind that consistency is important. | ||
|
||
String Literals | ||
~~~~~~~~~~~~~~~ | ||
|
||
Prefer single quotes to double quotes unless the string itself contains single quotes that would need to be needlessly escaped. | ||
|
||
Wrapping Code | ||
~~~~~~~~~~~~~ | ||
|
||
When wrapping code follow the "hanging grid" format: | ||
|
||
.. code-block:: python | ||
some_dict = { | ||
'one': 1, | ||
'two': 2, | ||
'three': 3} | ||
.. code-block:: python | ||
some_list = [ | ||
'foo', 'bar', 'baz'] | ||
Python is an indent-based language and we believe that beautiful, readable code is more important than saving a single line of ``git diff``. Please avoid dangling parentheses, brackets, square brackets or hanging commas even if the Django project seems to encourage this programming style: | ||
|
||
.. code-block:: python | ||
this_is_wrong = { | ||
'one': 1, | ||
'two': 2, | ||
'three': 3, | ||
} | ||
Please break multi-line code immediately after the parenthesis and avoid relying on a precise number of spaces for alignment: | ||
|
||
.. code-block:: python | ||
also_wrong('this is hard', | ||
'to maintain', | ||
'as it often needs to be realigned') | ||
Linters | ||
~~~~~~~ | ||
|
||
Use `pylint <https://www.pylint.org/>`_ with the ``pylint-django`` plugin to catch errors in your code. | ||
|
||
Use `pycodestyle <http://pycodestyle.pycqa.org/en/latest/>`_ to make sure your code adheres to PEP 8. | ||
|
||
Use `pydocstyle <http://pydocstyle.pycqa.org/en/latest/>`_ to check that your docstrings are properly formatted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
EditorConfig | ||
============ | ||
|
||
The root of the repository contains an `EditorConfig <http://editorconfig.org/>`_ file. | ||
|
||
Most editors and IDEs support this file either directly or via plugins. If you make sure that your programming environment respects the contents of this file you will automatically get correct indentation, encoding, and line endings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Naming Conventions | ||
================== | ||
|
||
To keep a consistent code structure we follow some rules when naming files. | ||
|
||
|
||
Python Modules | ||
-------------- | ||
|
||
Try to have the name reflect the function of the file. If possible avoid generic file names such as ``utils.py``. | ||
|
||
|
||
Django Templates | ||
---------------- | ||
|
||
Use underscore as a word separator. | ||
|
||
|
||
Static Files | ||
------------ | ||
|
||
Use dashes to separate words as they end up as part of the URL. |