[unknown button type]

Coding Style

If anything in this document conflicts with PEP 8 (Style Guide for Python Code) then please correct it as the PEP is leading.

General Python guidelines (PEP-8)

  • Use 4 spaces per indentation level.
  • Never mix tabs and spaces. Spaces only.
  • Limit all lines to a maximum of 79 characters.
  • Imports are always put at the top of the file, just after any module comments and docstrings
  • Imports should usually be on separate lines
  • Imports should be grouped in the following order (you should put a blank line between each group of imports):
    • 1. standard library imports
    • 2. related third party imports
    • 3. local application/library specific imports

Project specific guidelines

General

(?) means that we haven't decided on this yet

  • Double quotes should be used to indicate strings, i.e. “This is a string.”
  • (?) Use single quotes for non-natural language strings, i.e. some_array['key'].
  • When referring to both files and directories use the term “items” not “files”. Also sometimes you want to use “paths”.
  • (?) To stay consistent with imports always use absolute imports.

Debugging

Don't use print statements, use the logging facility. At the top of a module, use:

from rabbitvcs.lib.log import Log
log = Log("rabbitvcs.mymodule") # Replace "mymodule", obviously

…and then, eg.

log.debug("Number of items: %i" % len(items))

…or even:

try:
    risky_thing()
except Exception, e:
    log.exception(e)

Sometimes, if you put in some code for debugging, you could even leave it in as a comment for future maintainers, eg. from the status checker code:

# Uncomment this for useful simulation of a looooong status check :) 
# log.debug("Sleeping for 10s...")
# time.sleep(5)
# log.debug("Done.")

If you use Eclipse + pydev, use task tags to remind yourself to remove or flesh things out (eg. #FIXME: simplify code after debugging)

Example

[…]