| 1 |
Manila Style Commandments |
| 2 |
========================= |
| 3 |
|
| 4 |
Step 1: Read https://www.python.org/dev/peps/pep-0008/ |
| 5 |
Step 2: Read https://www.python.org/dev/peps/pep-0008/ again |
| 6 |
Step 3: Read on |
| 7 |
|
| 8 |
Imports |
| 9 |
------- |
| 10 |
- thou shalt not import objects, only modules |
| 11 |
- thou shalt not import more than one module per line |
| 12 |
- thou shalt not make relative imports |
| 13 |
- thou shalt organize your imports according to the following template |
| 14 |
|
| 15 |
:: |
| 16 |
# vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 17 |
{{stdlib imports in human alphabetical order}} |
| 18 |
\n |
| 19 |
{{manila imports in human alphabetical order}} |
| 20 |
\n |
| 21 |
\n |
| 22 |
{{begin your code}} |
| 23 |
|
| 24 |
|
| 25 |
General |
| 26 |
------- |
| 27 |
- thou shalt put two newlines twixt toplevel code (funcs, classes, etc) |
| 28 |
- thou shalt put one newline twixt methods in classes and anywhere else |
| 29 |
- thou shalt not write "except:", use "except Exception:" at the very least |
| 30 |
- thou shalt include your name with TODOs as in "TODO(termie)" |
| 31 |
- thou shalt not name anything the same name as a builtin or reserved word |
| 32 |
- thou shalt not violate causality in our time cone, or else |
| 33 |
|
| 34 |
|
| 35 |
Human Alphabetical Order Examples |
| 36 |
--------------------------------- |
| 37 |
:: |
| 38 |
import httplib |
| 39 |
import logging |
| 40 |
import random |
| 41 |
import StringIO |
| 42 |
import time |
| 43 |
import unittest |
| 44 |
|
| 45 |
from manila.auth import users |
| 46 |
from manila.endpoint import api |
| 47 |
from manila.endpoint import cloud |
| 48 |
from manila import flags |
| 49 |
from manila import test |
| 50 |
|
| 51 |
Docstrings |
| 52 |
---------- |
| 53 |
"""A one line docstring looks like this and ends in a period.""" |
| 54 |
|
| 55 |
|
| 56 |
"""A multiline docstring has a one-line summary, less than 80 characters. |
| 57 |
|
| 58 |
Then a new paragraph after a newline that explains in more detail any |
| 59 |
general information about the function, class or method. Example usages |
| 60 |
are also great to have here if it is a complex class for function. After |
| 61 |
you have finished your descriptions add an extra newline and close the |
| 62 |
quotations. |
| 63 |
|
| 64 |
When writing the docstring for a class, an extra line should be placed |
| 65 |
after the closing quotations. For more in-depth explanations for these |
| 66 |
decisions see https://www.python.org/dev/peps/pep-0257/ |
| 67 |
|
| 68 |
If you are going to describe parameters and return values, use Sphinx, the |
| 69 |
appropriate syntax is as follows. |
| 70 |
|
| 71 |
:param foo: the foo parameter |
| 72 |
:param bar: the bar parameter |
| 73 |
:returns: description of the return value |
| 74 |
|
| 75 |
""" |