[pypy-svn] buildbot default: pep8 cleanups

RonnyPfannschmidt commits-noreply at bitbucket.org
Wed Apr 20 15:53:52 CEST 2011


Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: 
Changeset: r477:cf60c5d1dea0
Date: 2011-04-20 08:42 +0200
http://bitbucket.org/pypy/buildbot/changeset/cf60c5d1dea0/

Log:	pep8 cleanups

diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -11,9 +11,6 @@
 from . import mail
 
 
-
-
-
 seen_nodes = set()
 
 
@@ -35,8 +32,6 @@
         yield commit
 
 
-
-
 def handle(payload, test=False):
     path = payload['repository']['absolute_url']
     local_repo = app.config['LOCAL_REPOS'].join(path)
@@ -49,7 +44,6 @@
     mail.handle_diff_email(payload, test)
 
 
-
 if __name__ == '__main__':
     import hook as hookfile
     repopath = os.path.dirname(os.path.dirname(hookfile.__file__))
@@ -75,7 +69,8 @@
 
                {u'author': u'antocuni',
                 u'branch': u'default',
-                u'files': [{u'file': u'bitbucket_hook/hook.py', u'type': u'modified'}],
+                u'files': [{u'file': u'bitbucket_hook/hook.py',
+                            u'type': u'modified'}],
                 u'message': u"don't send newlines to irc",
                 u'node': u'e17583fbfa5c',
                 u'parents': [u'69e9eac01cf6'],
@@ -99,13 +94,16 @@
 
                {u'author': u'antocuni',
                 u'branch': u'default',
-                u'files': [{u'file': u'bitbucket_hook/hook.py', u'type': u'modified'},
-                           {u'file': u'bitbucket_hook/__init__.py', u'type': u'added'},
+                u'files': [{u'file': u'bitbucket_hook/hook.py',
+                            u'type': u'modified'},
+                           {u'file': u'bitbucket_hook/__init__.py',
+                            u'type': u'added'},
                            {u'file': u'bitbucket_hook/test/__init__.py',
                             u'type': u'added'},
                            {u'file': u'bitbucket_hook/test/test_hook.py',
                             u'type': u'added'}],
-                u'message': u'partially refactor the hook to be more testable, and write a test for the fix in 12cc0caf054d',
+                u'message': u'partially refactor the hook to be more testable,'
+                            u' and write a test for the fix in 12cc0caf054d',
                 u'node': u'9c7bc068df88',
                 u'parents': [u'12cc0caf054d'],
                 u'raw_author': u'Antonio Cuni <anto.cuni at gmail.com>',
@@ -114,8 +112,7 @@
                 u'size': 753,
                 u'timestamp': u'2010-12-19 14:45:44'}]
 
-
-    test_payload[u'commits']  = commits
+    test_payload[u'commits'] = commits
 
 ##    # To regenerate:
 ##    try:

diff --git a/bitbucket_hook/irc.py b/bitbucket_hook/irc.py
--- a/bitbucket_hook/irc.py
+++ b/bitbucket_hook/irc.py
@@ -6,6 +6,7 @@
 import time
 import subprocess
 
+
 def getpaths(files, listfiles=False):
 
     # Handle empty input
@@ -40,14 +41,15 @@
     return common_prefix, filenames
 
 
-
 def send_message(message, test=False):
     if test:
         print message + '\n'
     else:
         from .main import app
         return subprocess.call([
-            app.config['BOT'], app.config['CHANNEL'], message
+            app.config['BOT'],
+            app.config['CHANNEL'],
+            message,
         ])
 
 
@@ -65,7 +67,7 @@
         branch = commit['branch']
         node = commit['node']
         timestamp = commit.get('timestamp')
-        print '[%s] %s %s %s' % (time.strftime('%Y-%m-%d %H:%M'), node, timestamp, author)
+        print time.strftime('[%Y-%m-%d %H:%M]'), node, timestamp, author
 
         files = commit.get('files', [])
         common_prefix, filenames = getpaths(files, app.config['LISTFILES'])
@@ -74,9 +76,9 @@
 
         if app.config['USE_COLOR_CODES']:
             author = '\x0312%s\x0F' % author   # in blue
-            branch = '\x02%s\x0F'   % branch   # in bold
-            node = '\x0311%s\x0F'   % node     # in azure
-            common_prefix = '\x0315%s\x0F' % common_prefix # in gray
+            branch = '\x02%s\x0F' % branch   # in bold
+            node = '\x0311%s\x0F' % node     # in azure
+            common_prefix = '\x0315%s\x0F' % common_prefix  # in gray
 
         message = commit['message'].replace('\n', ' ')
         fields = (author, branch, node, common_prefix, filenames)
@@ -88,5 +90,3 @@
             maxlen = totallen - (len(part1) + 3)
             irc_msg = part1 + message[:maxlen] + '...'
         send_message(irc_msg, test)
-
-

diff --git a/bitbucket_hook/test/conftest.py b/bitbucket_hook/test/conftest.py
--- a/bitbucket_hook/test/conftest.py
+++ b/bitbucket_hook/test/conftest.py
@@ -1,26 +1,30 @@
 from bitbucket_hook import irc, mail, hook
 
+
 def pytest_funcarg__mails(request):
     return []
 
+
 def pytest_funcarg__messages(request):
     return []
 
+
 def pytest_runtest_setup(item):
     hook.seen_nodes.clear()
 
+
 def pytest_funcarg__monkeypatch(request):
-    mp =  request.getfuncargvalue('monkeypatch')
+    mp = request.getfuncargvalue('monkeypatch')
     mails = request.getfuncargvalue('mails')
-    def send(from_, to, subject, body,test=False, mails=mails):
+
+    def send(from_, to, subject, body, test=False, mails=mails):
         mails.append((from_, to, subject, body))
     mp.setattr(mail, 'send', send)
 
     messages = request.getfuncargvalue('messages')
+
     def send_irc_message(message, test=False):
         messages.append(message)
     mp.setattr(irc, 'send_message', send_irc_message)
 
-
     return mp
-

diff --git a/bitbucket_hook/test/test_scm.py b/bitbucket_hook/test/test_scm.py
--- a/bitbucket_hook/test/test_scm.py
+++ b/bitbucket_hook/test/test_scm.py
@@ -6,6 +6,7 @@
 
 
 def test_non_ascii_encoding_guess_utf8(monkeypatch):
+
     def _hgexe(argv):
         return u'sp&#228;m'.encode('utf-8'), '', 0
     monkeypatch.setattr(scm, '_hgexe', _hgexe)
@@ -15,8 +16,9 @@
 
 
 def test_non_ascii_encoding_invalid_utf8(monkeypatch):
+
     def _hgexe(argv):
-        return '\xe4aa', '', 0 # invalid utf-8 string
+        return '\xe4aa', '', 0  # invalid utf-8 string
     monkeypatch.setattr(scm, '_hgexe', _hgexe)
     stdout = scm.hg('foobar')
     assert type(stdout) is unicode
@@ -31,4 +33,3 @@
     with pytest.raises(Exception):
         print scm.hg
         scm.hg('uhmwrong')
-

diff --git a/bitbucket_hook/test/test_hook.py b/bitbucket_hook/test/test_hook.py
--- a/bitbucket_hook/test/test_hook.py
+++ b/bitbucket_hook/test/test_hook.py
@@ -7,20 +7,22 @@
 hook.app.config['USE_COLOR_CODES'] = False
 
 
-
 def test_sort_commits():
     #
     commits = hook.get_commits('test_sort', {
-        'commits': [{'revision': 43, 'node': 'second', 'raw_node': 'first'},
-                    {'revision': 42, 'node': 'first', 'raw_node': 'second'}]
-        })
+        'commits': [
+            {'revision': 43, 'node': 'second', 'raw_node': 'first'},
+            {'revision': 42, 'node': 'first', 'raw_node': 'second'},
+        ],
+    })
     commits = [x['node'] for x in commits]
 
     assert commits == ['first', 'second']
 
 
-LONG_MESSAGE = u'This is a test with a long message: ' + 'x'*1000
-LONG_CUT = LONG_MESSAGE[:160-29]
+LONG_MESSAGE = u'This is a test with a long message: ' + 'x' * 1000
+LONG_CUT = LONG_MESSAGE[:160 - 29]
+
 
 def irc_cases(payload=None):
 
@@ -37,12 +39,12 @@
                                   d(file='my/file3')]
     single_file_deep = [d(file='path/to/single')]
 
-    cases = [(no_file,  ''), # No diff
-             (single_file,'single'), # Single file
+    cases = [(no_file,  ''),  # No diff
+             (single_file, 'single'),  # Single file
              (multiple_files,   ''),  # No common prefix
-             (multiple_files_subdir, 'path/'), # Common prefix
-             (multiple_files_subdir_root, ''), # No common subdir, file in root
-             (single_file_deep,'path/to/single') # Single file in deep path
+             (multiple_files_subdir, 'path/'),  # Common prefix
+             (multiple_files_subdir_root, ''),  # No common subdir file in root
+             (single_file_deep, 'path/to/single'),  # Single file in deep path
             ]
 
     author = u'antocuni'
@@ -54,7 +56,7 @@
 
     for i, (case, snippet) in enumerate(cases):
         rev = 44 + i
-        node = chr(97+i) + 'xxyyy'
+        node = chr(97 + i) + 'xxyyy'
         raw_node = node * 2
         expected.append(expected_template % (node, snippet, LONG_CUT))
         commits.append(d(revision=rev, files=case, author=author,
@@ -66,21 +68,25 @@
 
 def test_irc_message(monkeypatch, messages):
     payload = {
-        'commits': [{'revision': 42,
-                     'branch': u'default',
-                     'author': u'antocuni',
-                     'message': u'this is a test',
-                     'node': 'abcdef',
-                     'raw_node': 'abcdef',
-                     },
-                    {'revision': 43,
-                     'author': u'antocuni',
-                     'branch': u'mybranch',
-                     'message': LONG_MESSAGE,
-                     'node': 'xxxyyy',
-                     'raw_node': 'xxxyyy',
-                     }
-                    ]}
+        'commits': [
+            {
+                'revision': 42,
+                'branch': u'default',
+                'author': u'antocuni',
+                'message': u'this is a test',
+                'node': 'abcdef',
+                'raw_node': 'abcdef',
+            },
+            {
+                'revision': 43,
+                'author': u'antocuni',
+                'branch': u'mybranch',
+                'message': LONG_MESSAGE,
+                'node': 'xxxyyy',
+                'raw_node': 'xxxyyy',
+            },
+        ]
+    }
 
     payload, expected = irc_cases(payload)
     irc.handle_message(payload)
@@ -94,13 +100,23 @@
     for got, wanted in zip(messages[2:], expected):
         assert got == wanted
 
-def noop(*args, **kwargs): pass
+
+def noop(*args, **kwargs):
+    pass
+
+
 class mock:
     __init__ = noop
-    def communicate(*args, **kwargs): return '1', 2
-    def wait(*args, **kwargs): return 0
+
+    def communicate(*args, **kwargs):
+        return '1', 2
+
+    def wait(*args, **kwargs):
+        return 0
+
     sendmail = noop
 
+
 def test_handle(monkeypatch):
     commits, _ = irc_cases()
     test_payload = {u'repository': {u'absolute_url': '',
@@ -124,11 +140,11 @@
 
 
 def test_ignore_duplicate_commits(monkeypatch, mails, messages):
-    def hg( *args):
+    def hg(*args):
         return '<hg %s>' % ' '.join(map(str, args))
     monkeypatch.setattr(scm, 'hg', hg)
     monkeypatch.setattr(hook, 'seen_nodes', set())
-    monkeypatch.setattr(hook, 'check_for_local_repo', lambda _:True)
+    monkeypatch.setattr(hook, 'check_for_local_repo', lambda _: True)
 
     commits, _ = irc_cases()
     payload = {u'repository': {u'absolute_url': '',
@@ -144,5 +160,3 @@
     num_commits = len(commits['commits'])
     assert len(mails) == num_commits
     assert len(messages) == num_commits
-
-

diff --git a/bitbucket_hook/mail.py b/bitbucket_hook/mail.py
--- a/bitbucket_hook/mail.py
+++ b/bitbucket_hook/mail.py
@@ -33,7 +33,7 @@
     body = scm.hg('-R', local_repo, 'log', '-r', hgid,
              '--template', template)
     diff = scm.get_diff(local_repo, hgid, commit['files'])
-    body = body+diff
+    body = body + diff
     send(sender, app.config['ADDRESS'], subject, body, test)
 
 
@@ -62,6 +62,3 @@
     commits = hook.get_commits('email', payload)
     for commit in commits:
         send_diff_for_commit(payload, commit, test)
-
-
-

diff --git a/bitbucket_hook/test/test_irc.py b/bitbucket_hook/test/test_irc.py
--- a/bitbucket_hook/test/test_irc.py
+++ b/bitbucket_hook/test/test_irc.py
@@ -1,8 +1,10 @@
 from bitbucket_hook.irc import getpaths
 
+
 def fl(*paths):
     return [{'file': x} for x in paths]
 
+
 def pytest_generate_tests(metafunc):
 
     barefile = fl('file')
@@ -14,7 +16,6 @@
     slashleft = fl('/slashleft')
     slashright = fl('slashright/')
 
-
     nocommon = distinct + fl('path4/file')
     nocommonplusroot = distinct + barefile
 
@@ -34,41 +35,41 @@
 
     pypyempty = fl('pypy/rlib/rdtoa.py', 'pypy/rlib/test/test_rdtoa.py')
 
+    nothing = ('', '')
 
-    nothing = ('', '')
     expectations = [
         ('null', [], nothing),
         ('empty', empty, nothing),
-        ('empty*2', empty*2, nothing),
+        ('empty*2', empty * 2, nothing),
         ('bare', barefile, ('file', '')),
         ('deep', deepfile, ('a/long/path/to/deepfile.py', '')),
         ('slashes', slashesfile, ('/slashesfile/', '')),
         ('slashleft', slashleft, ('/slashleft', '')),
         ('slashright', slashright, ('slashright/', '')),
         ('nocommon', nocommon, ('', ' M(file1, file2, file, file)')),
-        ('nocommon+root', nocommonplusroot, 
+        ('nocommon+root', nocommonplusroot,
                           ('', ' M(file1, file2, file, file)')),
-        ('nocommon+empty', nocommonplusempty, ('',' M(file1, file2, file)')),
+        ('nocommon+empty', nocommonplusempty, ('', ' M(file1, file2, file)')),
         ('common', common, ('some/path/to/',
                 ' M(file, file, anotherfile, afile)')),
         ('common+root', commonplusroot, ('', ' M(file1, file2, file, file)')),
-        ('common+empty', commonplusempty, ('',' M(file1, file2, file)')),
-        ('nocommon+slash', nocommonplusslash, ('',' M(file1, file2, file)')),
-        ('common+slash', commonplusslash, ('path/',' M(file1, file2, file)')),
+        ('common+empty', commonplusempty, ('', ' M(file1, file2, file)')),
+        ('nocommon+slash', nocommonplusslash, ('', ' M(file1, file2, file)')),
+        ('common+slash', commonplusslash, ('path/', ' M(file1, file2, file)')),
         ('pypydoubledash', pypydoubleslash, ('pypy/jit/metainterp/',
                          ' M(u.py, test_c.py, test_o.py)')),
         ('pypyempty', pypyempty, ('pypy/rlib/',
                    ' M(rdtoa.py, test_rdtoa.py)')),
         ]
 
-    if metafunc.function.__name__=='test_getpaths':
+    if metafunc.function.__name__ == 'test_getpaths':
         for name, files, (common, listfiles) in expectations:
-            metafunc.addcall(id='list/'+name, funcargs={
+            metafunc.addcall(id='list/' + name, funcargs={
                 'files': files,
                 'expected_common': common,
                 'expected_listfiles': listfiles,
             })
-            metafunc.addcall(id='nolist/'+name, funcargs={
+            metafunc.addcall(id='nolist/' + name, funcargs={
                 'files': files,
                 'expected_common': common,
                 'expected_listfiles': listfiles,
@@ -79,5 +80,3 @@
     common, files = getpaths(files, listfiles=bool(expected_listfiles))
     assert common == expected_common
     assert files == expected_listfiles
-
-

diff --git a/bitbucket_hook/scm.py b/bitbucket_hook/scm.py
--- a/bitbucket_hook/scm.py
+++ b/bitbucket_hook/scm.py
@@ -1,12 +1,14 @@
 import sys
 from subprocess import Popen, PIPE
 
+
 def _hgexe(argv):
     proc = Popen(['hg'] + list(argv), stdout=PIPE, stderr=PIPE)
     stdout, stderr = proc.communicate()
     ret = proc.wait()
     return stdout, stderr, ret
 
+
 def hg(*argv):
     argv = map(str, argv)
     stdout, stderr, ret = _hgexe(argv)

diff --git a/bitbucket_hook/main.py b/bitbucket_hook/main.py
--- a/bitbucket_hook/main.py
+++ b/bitbucket_hook/main.py
@@ -22,12 +22,16 @@
 HOST_NAME = 'codespeak.net'
 PORT_NUMBER = 9237
 
+
 @app.route('/', methods=['GET'])
 def test_form():
     """Respond to a GET request."""
     return """
         <html>
-            <p>This is the pypy bitbucket hook. Use the following form only for testing</p>
+            <p>
+                This is the pypy bitbucket hook.
+                Use the following form only for testing
+            </p>
             <form method=post>
                 payload: <input name=payload> <br>
                 submit: <input type=submit>
@@ -36,7 +40,6 @@
     """
 
 
-
 @app.route('/', methods=['POST'])
 def handle_payload():
     payload = json.loads(flask.request.form['payload'])
@@ -56,6 +59,7 @@
     USE_COLOR_CODES = True
     LISTFILES = False
 
+
 class CodeSpeakConfig(DefaultConfig):
     SMTP_SERVER = 'localhost'
     SMTP_PORT = 25
@@ -64,6 +68,7 @@
     CHANNEL = '#pypy'
     BOT = '/svn/hooks/commit-bot/message'
 
+
 class ViperConfig(DefaultConfig):
     SMTP_SERVER = "out.alice.it"
     SMTP_PORT = 25


More information about the Pypy-commit mailing list