Skip to content

Commit

Permalink
Sphinx: fix some more warnings; address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Grubb committed Jul 17, 2015
1 parent fd77e63 commit 99deb17
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 28 deletions.
60 changes: 45 additions & 15 deletions master/docs/developer/py3-compat.rst
Expand Up @@ -10,12 +10,16 @@ Imports
All ``__future__`` import have to happen at the top of the module, anything else is seen as a syntax error.
All imports from the python-future package should happen below ``__future__`` imports, but before any other.

Yes::
Yes:

.. code-block:: python
from __future__ import print_function
from builtins import basestring
No::
No:

.. code-block:: python
from twisted.application import internet
from twisted.spread import pb
Expand All @@ -28,13 +32,17 @@ In python3, ``dict.iteritems`` is no longer available.
While ``dict.items()`` does exist, it can be memory intensive in python2.
For this reason, please use the python.future function ``iteritems()``.

Example::
Example:

.. code-block:: python
d = {"cheese": 4, "bread": 5, "milk": 1}
for item, num in d.iteritems():
print("We have {} {}".format(num, item))
should be written as::
should be written as:

.. code-block:: python
from future.utils import iteritems
d = {"cheese": 4, "bread": 5, "milk": 1}
Expand All @@ -47,13 +55,17 @@ If a list is required, please use ``list(iteritems(dict))``.
This is for compatibility with the six library.

For iterating over dictionary keys, please use ``for key in dict:``.
For example::
For example:

.. code-block:: python
d = {"cheese": 4, "bread": 5, "milk": 1}
for item in d:
print("We have {}".format(item))
Similarly when you want a list of keys::
Similarly when you want a list of keys:

.. code-block:: python
keys = list(d)
Expand All @@ -62,13 +74,17 @@ New-style classes
All classes in Python3 are newstyle, so any classes added to the code base must therefore be new-style.
This is done by inheriting ``object``

Old-style::
Old-style:

.. code-block:: python
class Foo:
def __init__(self, bar)
self.bar = bar
new-style::
new-style:

.. code-block:: python
class Foo(object):
def __init__(self, bar)
Expand All @@ -89,7 +105,9 @@ It can be both unicode and bytestring.
In python3, this is no longer the case.
For this reasons all string must be marked with either ``u''`` or ``b''`` to signify if the string is a unicode string or a bytestring respectively

Example::
Example:

.. code-block:: python
u'this is a unicode string, a string for humans to read'
b'This is a bytestring, a string for computers to read'
Expand All @@ -98,14 +116,18 @@ Example::
Exceptions
----------
All exceptions should be written with the ``as`` statement.
Before::
Before:

.. code-block:: python
try:
number = 5 / 0
except ZeroDivisionError, err:
print(err.msg)
After::
After:

.. code-block:: python
try:
number = 5/0
Expand All @@ -119,13 +141,17 @@ In Python2 there is a basestring type, which both str and unicode inherit.
In Python3, only unicode should be of this type, while bytestrings are ``type(byte)``.

For this reason, we use a builtin form python future.
Before::
Before:

.. code-block:: python
s = "this is a string"
if(isinstance(basestring)):
print "This line will run"
After::
After:

.. code-block:: python
from builtins import str
unicode_s = u"this is a unicode string"
Expand All @@ -147,11 +173,15 @@ Division
Integer division is slightly different in Python3.
``//`` is integer division and ``/`` is floating point division.
For this reason, we use ``division`` from the future module.
Before::
Before:
.. code-block:: python
2 / 3 = 0
After::
After:
.. code-block:: python
from __future__ import division
Expand Down
8 changes: 6 additions & 2 deletions master/docs/manual/cfg-www.rst
Expand Up @@ -480,7 +480,9 @@ You can grant roles from groups information provided by the Auth plugins, or if
Example Configs
+++++++++++++++

Simple config which allows admin people to run everything::
Simple config which allows admin people to run everything:

.. code-block:: python
from buildbot.plugins import *
authz = util.Authz(
Expand All @@ -496,7 +498,9 @@ Simple config which allows admin people to run everything::
c['www']['auth'] = auth
c['www']['authz'] = authz
More complex config with separation per branch::
More complex config with separation per branch:

.. code-block:: python
from buildbot.plugins import *
Expand Down
22 changes: 11 additions & 11 deletions master/docs/manual/cfg-wwwhooks.rst
Expand Up @@ -81,17 +81,17 @@ The parameters are:
Any value.
If you provide a non-empty value (recommended), make sure that your hook is configured to use it:

.. code-block:: python
c['www'] = dict(
...,
change_hook_dialects={
'github': {
'secret': 'MY-SECRET',
'strict': True
}
},
...))
.. code-block:: python
c['www'] = dict(
...,
change_hook_dialects={
'github': {
'secret': 'MY-SECRET',
'strict': True
}
},
...))
:guilabel:`Which events would you like to trigger this webhook?`
Leave the default -- ``Just the push event`` -- other kind of events are not currently supported.
Expand Down

0 comments on commit 99deb17

Please sign in to comment.