Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 7970b7b

Browse files
committed
style fixes
1 parent 13500fb commit 7970b7b

File tree

11 files changed

+131
-97
lines changed

11 files changed

+131
-97
lines changed

highfive/app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import sys
88
import traceback
99

10-
from .config import Config, InvalidTokenException
11-
from .newpr import HighfiveHandler, UnsupportedRepoError
12-
from .payload import Payload
13-
1410
import click
1511
import dotenv
1612
import flask
1713
import waitress
1814

15+
from .config import Config, InvalidTokenException
16+
from .newpr import HighfiveHandler, UnsupportedRepoError
17+
from .payload import Payload
18+
1919

2020
def create_app(config, webhook_secrets=None, config_dir=None):
2121
if webhook_secrets is None:
@@ -45,7 +45,7 @@ def new_pr():
4545
expected = hmac.new(webhook_secret.encode("utf-8"), digestmod=hashlib.sha1)
4646
expected.update(raw_data)
4747
expected = expected.hexdigest()
48-
if hmac.compare_digest('sha1='+expected, signature):
48+
if hmac.compare_digest('sha1=' + expected, signature):
4949
break
5050
else:
5151
return 'Error: invalid signature\n', 403

highfive/irc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import socket
22
import time
33

4+
45
class IrcClient(object):
56
""" A simple IRC client to send a message and then leave.
67
the calls to `time.sleep` are so the socket has time to recognize
78
responses from the IRC protocol
89
"""
10+
911
def __init__(self, target, nick="rust-highfive", should_join=False):
1012
self.target = target.encode("utf-8")
1113
self.nick = nick.encode("utf-8")
@@ -17,7 +19,7 @@ def __init__(self, target, nick="rust-highfive", should_join=False):
1719
time.sleep(2)
1820

1921
def join(self):
20-
self.ircsock.send(b"JOIN " + self.targert + b"\r\n")
22+
self.ircsock.send(b"JOIN " + self.target + b"\r\n")
2123

2224
def send(self, msg):
2325
if type(msg) == str:
@@ -28,7 +30,7 @@ def send(self, msg):
2830
print("Timeout! EXITING")
2931
return
3032
ircmsg = self.ircsock.recv(2048).strip()
31-
#if ircmsg: print(ircmsg)
33+
# if ircmsg: print(ircmsg)
3234

3335
if ircmsg.find(self.nick + b" +x") != -1:
3436
self.ircsock.send(b"PRIVMSG " + self.target + b" :" + msg + b"\r\n")

highfive/newpr.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
#!/usr/bin/env python3
22

3-
import urllib
4-
import cgi
5-
import cgitb
6-
from copy import deepcopy
3+
import gzip
74
import json
5+
import os
86
import random
7+
import re
8+
import urllib
99
from configparser import ConfigParser
10+
from copy import deepcopy
1011
from io import StringIO
11-
import gzip
12-
import re
13-
import os
1412

15-
from highfive import irc, payload
13+
from highfive import irc
1614

1715
# Maximum per page is 100. Sorted by number of commits, so most of the time the
1816
# contributor will happen early,
@@ -39,13 +37,15 @@
3937
review_without_reviewer = '@%s: no appropriate reviewer found, use r? to override'
4038

4139
reviewer_re = re.compile("\\b[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)")
42-
submodule_re = re.compile(".*\+Subproject\scommit\s.*", re.DOTALL|re.MULTILINE)
40+
submodule_re = re.compile(".*\+Subproject\scommit\s.*", re.DOTALL | re.MULTILINE)
4341

4442
rustaceans_api_url = "http://www.ncameron.org/rustaceans/user?username={username}"
4543

44+
4645
class UnsupportedRepoError(IOError):
4746
pass
4847

48+
4949
class HighfiveHandler(object):
5050
def __init__(self, payload, config, config_dir=None):
5151
self.payload = payload
@@ -57,7 +57,7 @@ def __init__(self, payload, config, config_dir=None):
5757
self.repo_config = self.load_repo_config()
5858

5959
def load_repo_config(self):
60-
'''Load the repository configuration.'''
60+
"""Load the repository configuration."""
6161
(org, repo) = self.payload['repository', 'full_name'].split('/')
6262
try:
6363
return self._load_json_file(os.path.join(org, repo) + '.json')
@@ -103,7 +103,7 @@ def api_req(self, method, url, data=None, media_type=None):
103103
buf = StringIO(f.read())
104104
f = gzip.GzipFile(fileobj=buf)
105105
body = f.read().decode("utf-8")
106-
return { "header": header, "body": body }
106+
return {"header": header, "body": body}
107107

108108
def set_assignee(self, assignee, owner, repo, issue, user, author, to_mention):
109109
try:
@@ -122,7 +122,7 @@ def set_assignee(self, assignee, owner, repo, issue, user, author, to_mention):
122122
if irc_name_of_reviewer:
123123
client = irc.IrcClient(target="#rust-bots")
124124
client.send_then_quit("{}: ping to review issue https://www.github.com/{}/{}/pull/{} by {}."
125-
.format(irc_name_of_reviewer, owner, repo, issue, author))
125+
.format(irc_name_of_reviewer, owner, repo, issue, author))
126126
self.run_commands(to_mention, owner, repo, issue, user)
127127

128128
def run_commands(self, to_mention, owner, repo, issue, user):
@@ -217,8 +217,7 @@ def review_msg(self, reviewer, submitter):
217217
else review_with_reviewer % reviewer
218218

219219
def unexpected_branch(self):
220-
""" returns (expected_branch, actual_branch) if they differ, else False
221-
"""
220+
""" returns (expected_branch, actual_branch) if they differ, else False"""
222221

223222
# If unspecified, assume master.
224223
expected_target = self.repo_config.get('expected_branch', 'master')
@@ -249,16 +248,16 @@ def is_new_contributor(self, username, owner, repo):
249248
raise e
250249

251250
def find_reviewer(self, msg):
252-
'''
251+
"""
253252
If the user specified a reviewer, return the username, otherwise returns
254253
None.
255-
'''
254+
"""
256255
if msg is not None:
257256
match = reviewer_re.search(msg)
258257
return match.group(1) if match else None
259258

260259
def choose_reviewer(self, repo, owner, diff, exclude):
261-
'''Choose a reviewer for the PR.'''
260+
"""Choose a reviewer for the PR."""
262261
# Get JSON data on reviewers.
263262
dirs = self.repo_config.get('dirs', {})
264263
groups = deepcopy(self.repo_config['groups'])
@@ -311,7 +310,6 @@ def choose_reviewer(self, repo, owner, diff, exclude):
311310
if not potential:
312311
potential = groups['core']
313312

314-
315313
# expand the reviewers list by group
316314
reviewers = []
317315
seen = {"all"}
@@ -337,9 +335,9 @@ def choose_reviewer(self, repo, owner, diff, exclude):
337335
return None
338336

339337
def get_to_mention(self, diff):
340-
'''
338+
"""
341339
Get the list of people to mention.
342-
'''
340+
"""
343341
dirs = self.repo_config.get('dirs', {})
344342
mentions = self.repo_config.get('mentions', {})
345343

@@ -428,7 +426,7 @@ def new_pr(self):
428426
def new_comment(self):
429427
# Check the issue is a PR and is open.
430428
if self.payload['issue', 'state'] != 'open' \
431-
or 'pull_request' not in self.payload['issue']:
429+
or 'pull_request' not in self.payload['issue']:
432430
return
433431

434432
commenter = self.payload['comment', 'user', 'login']
@@ -442,8 +440,8 @@ def new_comment(self):
442440
# Check the commenter is the submitter of the PR or the previous assignee.
443441
author = self.payload['issue', 'user', 'login']
444442
if not (author == commenter or (
445-
self.payload['issue', 'assignee'] \
446-
and commenter == self.payload['issue', 'assignee', 'login']
443+
self.payload['issue', 'assignee'] \
444+
and commenter == self.payload['issue', 'assignee', 'login']
447445
)):
448446
# Check if commenter is a collaborator.
449447
if not self.is_collaborator(commenter, owner, repo):

highfive/tests/fakes.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
from highfive import payload
21
import json
32
import os
43

4+
from highfive import payload
5+
6+
57
def load_fake(fake):
68
fakes_dir = os.path.join(os.path.dirname(__file__), 'fakes')
79

810
with open(os.path.join(fakes_dir, fake)) as fake:
911
return fake.read()
1012

13+
1114
def get_fake_filename(name):
1215
return os.path.join(os.path.dirname(__file__), 'fakes', name)
1316

17+
1418
def get_repo_configs():
1519
return {
1620
'individuals_no_dirs': {
17-
"groups": { "all": ["@pnkfelix", "@nrc"] },
21+
"groups": {"all": ["@pnkfelix", "@nrc"]},
1822
"dirs": {},
1923
},
2024
'individuals_no_dirs_labels': {
21-
"groups": { "all": ["@pnkfelix", "@nrc"] },
25+
"groups": {"all": ["@pnkfelix", "@nrc"]},
2226
"dirs": {},
2327
"new_pr_labels": ["a", "b"],
2428
},
2529
'individuals_dirs': {
26-
"groups": { "all": ["@pnkfelix", "@nrc"] },
27-
"dirs": { "src/librustc": ["@aturon"] },
30+
"groups": {"all": ["@pnkfelix", "@nrc"]},
31+
"dirs": {"src/librustc": ["@aturon"]},
2832
},
2933
'individuals_dirs_2': {
30-
"groups": { "all": ["@pnkfelix", "@nrc"] },
31-
"dirs": { "src/foobazdir": ["@aturon"] },
34+
"groups": {"all": ["@pnkfelix", "@nrc"]},
35+
"dirs": {"src/foobazdir": ["@aturon"]},
3236
},
3337
'individual_files': {
34-
"groups": { "all": ["@pnkfelix", "@nrc"] },
35-
"dirs": { ".travis.yml": ["@aturon"] },
38+
"groups": {"all": ["@pnkfelix", "@nrc"]},
39+
"dirs": {".travis.yml": ["@aturon"]},
3640
},
3741
'circular_groups': {
3842
"groups": {
@@ -41,11 +45,12 @@ def get_repo_configs():
4145
},
4246
},
4347
'empty': {
44-
"groups": { "all": [] },
48+
"groups": {"all": []},
4549
"dirs": {},
4650
},
4751
}
4852

53+
4954
def get_global_configs():
5055
return {
5156
'base': {
@@ -54,10 +59,11 @@ def get_global_configs():
5459
}
5560
},
5661
'has_all': {
57-
"groups": { "all": ["@alexcrichton"] }
62+
"groups": {"all": ["@alexcrichton"]}
5863
},
5964
}
6065

66+
6167
class Payload(object):
6268
@staticmethod
6369
def new_comment():
@@ -67,8 +73,8 @@ def new_comment():
6773

6874
@staticmethod
6975
def new_pr(
70-
number=7, pr_body='The PR comment.', pr_url='https://the.url/',
71-
repo_name='repo-name', repo_owner='repo-owner', pr_author='prAuthor'
76+
number=7, pr_body='The PR comment.', pr_url='https://the.url/',
77+
repo_name='repo-name', repo_owner='repo-owner', pr_author='prAuthor'
7278
):
7379
with open(get_fake_filename('open-pr.payload'), 'r') as fin:
7480
p = json.load(fin)

highfive/tests/patcherize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ def patcherize():
77
patchers = {}
88

99
def _patcherize(patcher_names=None):
10-
for n,p in (patcher_names or ()):
10+
for n, p in (patcher_names or ()):
1111
patchers[n] = mock.patch(p)
12-
return {n: p.start() for n,p in patchers.items()}
12+
return {n: p.start() for n, p in patchers.items()}
1313

1414
yield _patcherize
1515

highfive/tests/test_configs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
from copy import deepcopy
21
import json
3-
from jsonschema import validate
4-
from jsonschema.exceptions import ValidationError
52
import os
6-
import pytest
3+
from copy import deepcopy
74

5+
import pytest
6+
from jsonschema import validate
7+
from jsonschema.exceptions import ValidationError
88

99
CONFIG_SCHEMA = {
1010
"type": "object",
1111
"required": [
1212
"groups",
1313
],
1414
"properties": {
15-
"contributing" : {
15+
"contributing": {
1616
"type": "string",
1717
},
1818
"dirs": {
@@ -82,6 +82,7 @@
8282
GLOBAL_SCHEMA = deepcopy(CONFIG_SCHEMA)
8383
del GLOBAL_SCHEMA['properties']['groups']['required']
8484

85+
8586
def config_valid(fname):
8687
with open(fname, 'r') as fin:
8788
try:
@@ -100,6 +101,7 @@ def config_valid(fname):
100101

101102
return True
102103

104+
103105
@pytest.mark.config
104106
@pytest.mark.hermetic
105107
@pytest.fixture

0 commit comments

Comments
 (0)