Skip to content

Commit

Permalink
Split contributing and add Python style overview
Browse files Browse the repository at this point in the history
  • Loading branch information
patrys committed Feb 1, 2018
1 parent 8bcfe17 commit 5ebcb98
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.py]
indent_size = 4
max_line_length = 79
multi_line_output = 4
quote_type = single

[*.js]
Expand Down
8 changes: 5 additions & 3 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Contributing Guides
Please use GitHub issues and pull requests to report problems and discuss new features.


Naming Conventions
------------------
.. toctree::
:maxdepth: 1

To keep a consistent code structure we follow some rules of naming files. Templates use underscore as a word separator and static files, as they end up as a part of URL, use dashes.
contributing/editorconfig
contributing/coding-style
contributing/naming
57 changes: 57 additions & 0 deletions docs/contributing/coding-style.rst
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.
6 changes: 6 additions & 0 deletions docs/contributing/editorconfig.rst
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.
22 changes: 22 additions & 0 deletions docs/contributing/naming.rst
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.

0 comments on commit 5ebcb98

Please sign in to comment.