-
Notifications
You must be signed in to change notification settings - Fork 23
Coding Guidelines
Andre Merzky edited this page Oct 24, 2018
·
4 revisions
We use PEP.8 as base of our coding guidelines, with some additions / changes. Those changes are mostly caused by personal preferences of the developers (me, AM).
- allow visual code alignment of code;
- prefer
'
over"
( but use"
when that avoids escapes); - prefer
%
-based string expansion overstring.format
; - allow short names for loop variables.
In all other aspects we expect relatively strict PEP.8 compliance.
Example:
#!/usr/bin/env python
import sys
import time
import pprint
import radical.utils as ru
import radical.saga as rs
import radical.pilot as rp
# ------------------------------------------------------------------------------
# constants
# (we use delimiting lines like above to separate code sections, classes, etc.)
#
STATE_ONE = 'one'
STATE_TWO = 'two'
STATE_THREE = 'three'
# ------------------------------------------------------------------------------
#
# this class is nothing special, but its mine.
#
class MyClass(object):
'''
This method demonstrates what deviations from PEP.8 are accepted in RP.
'''
# --------------------------------------------------------------------------
#
def __init__(self):
self._state = STATE_ONE
self._created = time.time()
self._worker = ru.Thread()
self._config = {'title' : 'hello darkness',
'subtitle' : 'my old friend',
'super_category' : 'example'}
# --------------------------------------------------------------------------
#
def method(self, arg_1='default_1', arg_2='default_2',
arg_3='default_3', arg_4='default_4'):
'''
method documentation
'''
if arg_1 == 'default_1' and \
arg_2 != 'default_2' :
print 'this is unexpectedly indented (%s: %s)' % (arg_1, arg_2)
# we allow one letter names for temporary loop variables
for i in range(4):
print "It's a simply i [%d]" % i
# strangely indendet clauses
if arg3 == arg4: print 'haleluja' # because why noe
elif arg2 == arg4: print 'praise the space' # loooots of space
else : print 'clickediclickediclick' # clickedispace!
pprint.some_formatting_method(mode='radical', align='fancy',
enforce=False, encourage=True)
# ------------------------------------------------------------------------------
This is our flake8
configuration, which should transfer to other pep8 linters:
[flake8]
exclude = .git,__pycache__,docs,build,dist
max-complexity = 20
max-line-length = 80
ignore =
# module level import location
E402,
# space before/after operator
E221, E222,
# multiple spaces after/after keyword
E271, E272,
# whitespace before/after ...
E203, E202, E231, E241, E211, E116, E127,
# same indent
E129,
# comment indent not mod(4)
E114,
# cont line indentation
E128, E126, E124, E125, E131,
# blank lines
W391, E301, E303,
# multiple statements on one line
E701, E704,
# space before bracket
C0326,
# trailing whitespace
W291