Skip to content

Commit 675ba1c

Browse files
JNRowejdunck
authored andcommitted
Minor PEP 8 compliance changes.
1 parent ff9132f commit 675ba1c

10 files changed

Lines changed: 52 additions & 42 deletions

File tree

github2/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
"Github API v2 library for Python"
12
VERSION = (0, 2, 0)
2-
__doc__ = "Github API v2 library for Python"
3+
34
__author__ = "Ask Solem"
45
__contact__ = "askh@opera.com"
56
__homepage__ = "http://github.com/ask/python-github2"
67
__version__ = ".".join(map(str, VERSION))
7-

github2/bin/github_manage_collaborators

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ def parse_commandline():
2222
parser = OptionParser()
2323
parser.description = __doc__
2424

25-
parser.set_usage('usage: %prog [options] (list|add|remove) [collaborator]. Try %prog --help for details.')
25+
parser.set_usage('usage: %prog [options] (list|add|remove) [collaborator].'
26+
'Try %prog --help for details.')
2627
parser.add_option('-d', '--debug', action='store_true',
2728
help='Enables debugging mode')
2829
parser.add_option('-l', '--login',
2930
help='Username to login with')
3031
parser.add_option('-a', '--account',
31-
help='User owning the repositories to be changed [default: same as --login]')
32+
help='User owning the repositories to be changed ' \
33+
'[default: same as --login]')
3234
parser.add_option('-t', '--apitoken',
33-
help='API Token - can be found on the lower right of https://github.com/account')
34-
35+
help='API Token - can be found on the lower right of ' \
36+
'https://github.com/account')
3537

3638
options, args = parser.parse_args()
3739
if len(args) not in [1, 2]:
@@ -50,19 +52,19 @@ def parse_commandline():
5052

5153
def main(options, args):
5254
"""This implements the actual program functionality"""
53-
55+
5456
if not options.account:
5557
options.account = options.login
56-
58+
5759
github = github2.client.Github(username=options.login,
5860
api_token=options.apitoken,
5961
debug=options.debug)
60-
62+
6163
if len(args) == 1:
6264
for repos in github.repos.list(options.account):
6365
fullreposname = github.project_for_user_repo(options.account, repos.name)
6466
print "%s: %s" % (repos.name, ' '.join(github.repos.list_collaborators(fullreposname)))
65-
time.sleep(0.5) # to keep github from overloading
67+
time.sleep(0.5) # to keep github from overloading
6668
elif len(args) == 2:
6769
command, collaborator = args
6870
for repos in github.repos.list(options.account):
@@ -75,7 +77,7 @@ def main(options, args):
7577
if command == 'add':
7678
github.repos.add_collaborator(repos.name, collaborator)
7779
print "added %r to %r" % (collaborator, repos.name)
78-
time.sleep(0.5) # to keep github from overloading
80+
time.sleep(0.5) # to keep github from overloading
7981

8082

8183
if __name__ == '__main__':

github2/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from github2.users import Users
55
from github2.commits import Commits
66

7+
78
class Github(object):
89

910
def __init__(self, username=None, api_token=None, debug=False,
@@ -24,14 +25,14 @@ def __init__(self, username=None, api_token=None, debug=False,
2425
2526
`requests_per_second` is a float indicating the API rate limit
2627
you're operating under (1 per second per GitHub at the moment),
27-
or None to disable delays.
28+
or None to disable delays.
2829
2930
The default is to disable delays (for backwards compatibility).
3031
"""
3132

3233
self.debug = debug
3334
self.request = GithubRequest(username=username, api_token=api_token,
34-
debug=self.debug,
35+
debug=self.debug,
3536
requests_per_second=requests_per_second,
3637
access_token=access_token)
3738
self.issues = Issues(self.request)
@@ -53,7 +54,7 @@ def get_tree(self, project, tree_sha):
5354
def get_network_meta(self, project):
5455
return self.request.raw_request("/".join([self.request.github_url,
5556
project,
56-
"network_meta"] ), {})
57+
"network_meta"]), {})
5758

5859
def get_network_data(self, project, nethash, start=None, end=None):
5960
return self.request.raw_request("/".join([self.request.github_url,

github2/commits.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,3 @@ def list(self, project, branch="master", file=None):
3333
def show(self, project, sha):
3434
return self.get_value("show", project, sha,
3535
filter="commit", datatype=Commit)
36-
37-

github2/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
COMMIT_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S"
77

88

9-
109
def ghdate_to_datetime(github_date):
1110
date_without_tz = " ".join(github_date.strip().split()[:2])
1211
return datetime.strptime(date_without_tz, GITHUB_DATE_FORMAT)
@@ -52,7 +51,7 @@ def get_value(self, *args, **kwargs):
5251
# unicode keys are not accepted as kwargs by python, see:
5352
#http://mail-archives.apache.org/mod_mbox/qpid-dev/200609.mbox/%3C1159389941.4505.10.camel@localhost.localdomain%3E
5453
# So we make a local dict with the same keys but as strings:
55-
return datatype(**dict((str(k), v) for (k,v) in value.iteritems()))
54+
return datatype(**dict((str(k), v) for (k, v) in value.iteritems()))
5655
return value
5756

5857
def get_values(self, *args, **kwargs):
@@ -61,14 +60,15 @@ def get_values(self, *args, **kwargs):
6160
if datatype:
6261
# Same as above, unicode keys will blow up in **args, so we need to
6362
# create a new 'values' dict with string keys
64-
return [ datatype(**dict((str(k), v) for (k,v) in value.iteritems()))
65-
for value in values ]
63+
return [datatype(**dict((str(k), v) for (k, v) in value.iteritems()))
64+
for value in values]
6665
else:
6766
return values
6867

6968

7069
def doc_generator(docstring, attributes):
7170
docstring = docstring or ""
71+
7272
def section(title):
7373
return "\n".join([title, "-" * len(title)])
7474

@@ -157,7 +157,7 @@ def to_dict(self):
157157
#_contribute_method("__dict__", to_dict)
158158

159159
def iterate(self):
160-
not_empty = lambda e: e[1] is not None #AS I *think* this is what was intended.
160+
not_empty = lambda e: e[1] is not None # AS I *think* this is what was intended.
161161
return iter(filter(not_empty, vars(self).items()))
162162
_contribute_method("__iter__", iterate)
163163

github2/issues.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from github2.core import GithubCommand, BaseData, Attribute, DateAttribute
44

5+
56
class Issue(BaseData):
67
position = Attribute("The position of this issue in a list.")
78
number = Attribute("The issue number (unique for project).")

github2/repositories.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ def network(self, project):
100100
return self.make_request("show", project, "network", filter="network")
101101

102102
def languages(self, project):
103-
return self.make_request("show", project, "languages", filter="languages")
104-
103+
return self.make_request("show", project, "languages",
104+
filter="languages")
105+
105106
def tags(self, project):
106107
return self.make_request("show", project, "tags", filter="tags")
107108

@@ -110,8 +111,8 @@ def branches(self, project):
110111
filter="branches")
111112

112113
def watchers(self, project):
113-
return self.make_request("show", project, "watchers",
114-
filter="watchers")
114+
return self.make_request("show", project, "watchers",
115+
filter="watchers")
115116

116117
def watching(self, for_user=None):
117118
"""Lists all the repos a user is watching."""

github2/request.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import sys, time, datetime
1+
import datetime
2+
import sys
3+
import time
24
import httplib
35
try:
4-
import json as simplejson # For Python 2.6
6+
import json as simplejson # For Python 2.6
57
except ImportError:
68
import simplejson
79
from urlparse import urlparse, urlunparse
@@ -15,9 +17,11 @@
1517

1618
URL_PREFIX = "https://github.com/api/v2/json"
1719

20+
1821
class GithubError(Exception):
1922
"""An error occured when making a request to the Github API."""
2023

24+
2125
class GithubRequest(object):
2226
github_url = GITHUB_URL
2327
url_format = "%(github_url)s/api/%(api_version)s/%(api_format)s"
@@ -30,7 +34,7 @@ class GithubRequest(object):
3034
"https": httplib.HTTPSConnection,
3135
}
3236

33-
def __init__(self, username=None, api_token=None, url_prefix=None,
37+
def __init__(self, username=None, api_token=None, url_prefix=None,
3438
debug=False, requests_per_second=None, access_token=None):
3539
"""
3640
Make an API request.
@@ -44,7 +48,7 @@ def __init__(self, username=None, api_token=None, url_prefix=None,
4448
self.delay = 0
4549
else:
4650
self.delay = 1.0 / requests_per_second
47-
self.last_request = datetime.datetime(1900,1,1)
51+
self.last_request = datetime.datetime(1900, 1, 1)
4852
if not self.url_prefix:
4953
self.url_prefix = self.url_format % {
5054
"github_url": self.github_url,
@@ -60,7 +64,7 @@ def encode_authentication_data(self, extra_post_data):
6064
"token": self.api_token}
6165
else:
6266
post_data = {}
63-
post_data.update(extra_post_data)
67+
post_data.update(extra_post_data)
6468
return urlencode(post_data)
6569

6670
def get(self, *path_components):
@@ -81,7 +85,7 @@ def make_request(self, path, extra_post_data=None, method="GET"):
8185
if self.debug:
8286
sys.stderr.write("delaying API call %s\n" % duration)
8387
time.sleep(duration)
84-
88+
8589
extra_post_data = extra_post_data or {}
8690
url = "/".join([self.url_prefix, path])
8791
result = self.raw_request(url, extra_post_data, method=method)

github2/users.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from github2.core import BaseData, GithubCommand, Attribute, DateAttribute
1+
from github2.core import BaseData, GithubCommand, Attribute
22
import urllib
33

4+
45
class User(BaseData):
56
id = Attribute("The user id")
67
login = Attribute("The login username")
@@ -34,7 +35,8 @@ class Users(GithubCommand):
3435
domain = "user"
3536

3637
def search(self, query):
37-
return self.get_values("search", urllib.quote_plus(query), filter="users", datatype=User)
38+
return self.get_values("search", urllib.quote_plus(query),
39+
filter="users", datatype=User)
3840

3941
def search_by_email(self, query):
4042
return self.get_value("email", query, filter="user", datatype=User)

tests/unit.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@ class ReprTests(unittest.TestCase):
1010

1111
def test_issue(self):
1212
"""Issues can have non-ASCII characters in the title."""
13-
i = Issue(title = u'abcdé')
13+
i = Issue(title=u'abcdé')
1414
self.assertEqual(str, type(repr(i)))
1515

1616

1717
class RateLimits(unittest.TestCase):
1818
"""
1919
How should we handle actual API calls such that tests can run?
20-
Perhaps the library should support a ~/.python_github2.conf from which to get the auth?
20+
Perhaps the library should support a ~/.python_github2.conf from which to
21+
get the auth?
2122
"""
2223
def test_delays(self):
23-
import datetime, time
24-
USERNAME=''
25-
API_KEY=''
26-
client = Github(username=USERNAME, api_token=API_KEY,
24+
import datetime
25+
USERNAME = ''
26+
API_KEY = ''
27+
client = Github(username=USERNAME, api_token=API_KEY,
2728
requests_per_second=.5)
2829
client.users.show('defunkt')
2930
start = datetime.datetime.now()
3031
client.users.show('mojombo')
3132
end = datetime.datetime.now()
32-
self.assertGreaterEqual((end-start).total_seconds(), 2.0,
33-
"Expected .5 reqs per second to require a 2 second delay between calls.")
34-
33+
self.assertGreaterEqual((end - start).total_seconds(), 2.0,
34+
"Expected .5 reqs per second to require a 2 second delay between "
35+
"calls.")

0 commit comments

Comments
 (0)