Coding Styles
Common
- Line length: Maximum of
119
rather than usual79
. That said, where possible keep it between79-99
to keep it readable. - Indent:
4 spaces
, no tabs. - All code should use
'single quotes'
.
Python
Deluge follows PEP8 and Python Code Style with line length the only exception.
- Code must pass flake8 (w/flake8-quotes), isort and Pylint source code checkers.
flake8 deluge
isort -rc -df deluge
pylint deluge
pylint deluge/plugins/*/deluge/
-
Using the pre-commit app can aid in picking up issues before creating git commits.
-
All byte strings (
str
) should be decoded to strings (unicode strings,unicode
) on input and encoded back to byte strings on output. From Stackoverflow:
>>> b"abcde"
b'abcde'
>>> b"abcde".decode("utf-8")
'abcde'
Notes:
* *PyGTK/GTK+ will accept str
(utf8 encoded) or unicode
but will only return str
. See GTK+ Unicode docs. *
-
*There is also a
bytearray
type which enables in-place modification of a string. See Python Bytearrays * -
*For reference Python 3 renames
unicode
tostr
type and byte strings becomebytes
type. * -
All relative path separators used within code should be converted to posix format
/
, so should not contain\
or\\
. This is to prevent confusion when dealing with cross-platform clients and servers.
Docstrings
You will find a mix of the older reStructuredText and newer, easier to read, Sphinx Napoleon format.
Going forward the Napoleon Google Style will be used for all new doctrings and eventually convert over the rest.
Google Style short example:
def func(arg):
"""Function purpose.
Args:
arg (type): Description.
Returns:
type: Description. If the line is too, long indent next
line with three spaces.
"""
Most common sections are Args
and Returns
. See complete list of supported headers.
Verify that the documentation parses correctly with:
python setup.py build_docs
Python References
Useful links to style guides from other projects:
Javascript
Using codepainter with hautelook
style will ensure a consistent coding style.
codepaint xform -p hautelook "file.js"
- Classes should follow the Ext coding style.
- Class names should be in CamelCase
- Instances of classes should use camelCase.