|
| 1 | +OpenStack Style Commandments |
| 2 | +============================ |
| 3 | + |
| 4 | +Step 0: Read https://github.com/openstack-dev/hacking/blob/master/HACKING.rst |
| 5 | +Step 1: Read http://www.python.org/dev/peps/pep-0008/ one more time |
| 6 | +Step 2: Read on |
| 7 | + |
| 8 | +General |
| 9 | +------- |
| 10 | +- thou shalt not violate causality in our time cone, or else |
| 11 | + |
| 12 | +Docstrings |
| 13 | +---------- |
| 14 | + |
| 15 | +Docstrings should ONLY use triple-double-quotes (``"""``) |
| 16 | + |
| 17 | +Single-line docstrings should NEVER have extraneous whitespace |
| 18 | +between enclosing triple-double-quotes. |
| 19 | + |
| 20 | +Deviation! Sentence fragments do not have punctuation. Specifically in the |
| 21 | +command classes the one line docstring is also the help string for that |
| 22 | +command and those do not have periods. |
| 23 | + |
| 24 | + """A one line docstring looks like this""" |
| 25 | + |
| 26 | +Calling Methods |
| 27 | +--------------- |
| 28 | + |
| 29 | +Deviation! When breaking up method calls due to the 79 char line length limit, |
| 30 | +use the alternate 4 space indent. With the frist argument on the succeeding |
| 31 | +line all arguments will then be vertically aligned. Use the same convention |
| 32 | +used with other data structure literals and terminate the method call with |
| 33 | +the last argument line ending with a comma and the closing paren on its own |
| 34 | +line indented to the starting line level. |
| 35 | + |
| 36 | + unnecessarily_long_function_name( |
| 37 | + 'string one', |
| 38 | + 'string two', |
| 39 | + kwarg1=constants.ACTIVE, |
| 40 | + kwarg2=['a', 'b', 'c'], |
| 41 | + ) |
| 42 | + |
| 43 | +Text encoding |
| 44 | +------------- |
| 45 | + |
| 46 | +Note: this section clearly has not been implemented in this project yet, it is |
| 47 | +the intention to do so. |
| 48 | + |
| 49 | +All text within python code should be of type 'unicode'. |
| 50 | + |
| 51 | + WRONG: |
| 52 | + |
| 53 | + >>> s = 'foo' |
| 54 | + >>> s |
| 55 | + 'foo' |
| 56 | + >>> type(s) |
| 57 | + <type 'str'> |
| 58 | + |
| 59 | + RIGHT: |
| 60 | + |
| 61 | + >>> u = u'foo' |
| 62 | + >>> u |
| 63 | + u'foo' |
| 64 | + >>> type(u) |
| 65 | + <type 'unicode'> |
| 66 | + |
| 67 | +Transitions between internal unicode and external strings should always |
| 68 | +be immediately and explicitly encoded or decoded. |
| 69 | + |
| 70 | +All external text that is not explicitly encoded (database storage, |
| 71 | +commandline arguments, etc.) should be presumed to be encoded as utf-8. |
| 72 | + |
| 73 | + WRONG: |
| 74 | + |
| 75 | + mystring = infile.readline() |
| 76 | + myreturnstring = do_some_magic_with(mystring) |
| 77 | + outfile.write(myreturnstring) |
| 78 | + |
| 79 | + RIGHT: |
| 80 | + |
| 81 | + mystring = infile.readline() |
| 82 | + mytext = s.decode('utf-8') |
| 83 | + returntext = do_some_magic_with(mytext) |
| 84 | + returnstring = returntext.encode('utf-8') |
| 85 | + outfile.write(returnstring) |
| 86 | + |
| 87 | +Python 3.x Compatibility |
| 88 | +------------------------ |
| 89 | + |
| 90 | +OpenStackClient strives to be Python 3.3 compatibile. Common guidelines: |
| 91 | + |
| 92 | +* Convert print statements to functions: print statements should be converted |
| 93 | + to an appropriate log or other output mechanism. |
| 94 | +* Use six where applicable: x.iteritems is converted to six.iteritems(x) |
| 95 | + for example. |
| 96 | + |
| 97 | +Running Tests |
| 98 | +------------- |
| 99 | + |
| 100 | +Note: Oh boy, are we behing on writing tests. But they are coming! |
| 101 | + |
| 102 | +The testing system is based on a combination of tox and testr. If you just |
| 103 | +want to run the whole suite, run `tox` and all will be fine. However, if |
| 104 | +you'd like to dig in a bit more, you might want to learn some things about |
| 105 | +testr itself. A basic walkthrough for OpenStack can be found at |
| 106 | +http://wiki.openstack.org/testr |
0 commit comments