Skip to content

Commit 9288034

Browse files
committed
feat: pep8 all the things
Brings the code-base back up to validating flake8 checks. Closes #445
1 parent b0fbd35 commit 9288034

19 files changed

Lines changed: 160 additions & 87 deletions

.hound.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fail_on_violations: true
2+
python:
3+
enabled: true

kazoo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .version import __version__
1+
from .version import __version__ # noqa

kazoo/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,8 @@ def reconfig(self, joining, leaving, new_members, from_config=-1):
13841384
joining=joining, leaving=None, new_members=None)
13851385
13861386
# wait and then remove it (just by using its id) (incremental)
1387-
data, _ = zk.reconfig(joining=None, leaving='100', new_members=None)
1387+
data, _ = zk.reconfig(joining=None, leaving='100',
1388+
new_members=None)
13881389
13891390
# now do a full change of the cluster (non-incremental)
13901391
new = [
@@ -1418,7 +1419,8 @@ def reconfig(self, joining, leaving, new_members, from_config=-1):
14181419
returns a non-zero error code.
14191420
14201421
"""
1421-
result = self.reconfig_async(joining, leaving, new_members, from_config)
1422+
result = self.reconfig_async(joining, leaving, new_members,
1423+
from_config)
14221424
return result.get()
14231425

14241426
def reconfig_async(self, joining, leaving, new_members, from_config):

kazoo/handlers/threading.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,11 @@ def select(self, *args, **kwargs):
149149
end = (time.time() + timeout) if timeout else None
150150
while end is None or time.time() < end:
151151
if end is not None:
152-
args = list(args) # make a list, since tuples aren't mutable
153-
args[3] = end - time.time() # set the timeout to the remaining time
152+
# make a list, since tuples aren't mutable
153+
args = list(args)
154+
155+
# set the timeout to the remaining time
156+
args[3] = end - time.time()
154157
try:
155158
return select.select(*args, **kwargs)
156159
except select.error as ex:

kazoo/protocol/connection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ def _expand_client_hosts(self):
491491
host_ports = []
492492
for host, port in self.client.hosts:
493493
try:
494-
for rhost in socket.getaddrinfo(host.strip(), port, 0, 0, socket.IPPROTO_TCP):
494+
for rhost in socket.getaddrinfo(host.strip(), port, 0, 0,
495+
socket.IPPROTO_TCP):
495496
host_ports.append((rhost[4][0], rhost[4][1]))
496497
except socket.gaierror as e:
497498
# Skip hosts that don't resolve
@@ -618,7 +619,8 @@ def _connect(self, host, port):
618619
client._session_id or 0, client._session_passwd,
619620
client.read_only)
620621

621-
# save the client's last_zxid before it gets overwritten by the server's.
622+
# save the client's last_zxid before it gets overwritten by the
623+
# server's.
622624
# we'll need this to reset watches via SetWatches further below.
623625
last_zxid = client.last_zxid
624626

@@ -667,7 +669,8 @@ def _connect(self, host, port):
667669
client._data_watchers.keys(),
668670
client._data_watchers.keys(),
669671
client._child_watchers.keys())
670-
zxid = self._invoke(connect_timeout / 1000.0, sw, xid=SET_WATCHES_XID)
672+
zxid = self._invoke(connect_timeout / 1000.0, sw,
673+
xid=SET_WATCHES_XID)
671674
if zxid:
672675
client.last_zxid = zxid
673676

kazoo/protocol/serialization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ def unchroot(client, response):
359359
return resp
360360

361361

362-
class Reconfig(namedtuple('Reconfig', 'joining leaving new_members config_id')):
362+
class Reconfig(namedtuple('Reconfig',
363+
'joining leaving new_members config_id')):
363364
type = 16
364365

365366
def serialize(self):

kazoo/protocol/states.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class EventType(object):
105105
NONE = 'NONE'
106106

107107
EVENT_TYPE_MAP = {
108-
-1:EventType.NONE,
108+
-1: EventType.NONE,
109109
1: EventType.CREATED,
110110
2: EventType.DELETED,
111111
3: EventType.CHANGED,

kazoo/recipe/lease.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,28 @@
1515
class NonBlockingLease(object):
1616
"""Exclusive lease that does not block.
1717
18-
An exclusive lease ensures that only one client at a time owns the lease. The client may
19-
renew the lease without losing it by obtaining a new lease with the same path and same
20-
identity. The lease object evaluates to True if the lease was obtained.
18+
An exclusive lease ensures that only one client at a time owns the lease.
19+
The client may renew the lease without losing it by obtaining a new lease
20+
with the same path and same identity. The lease object evaluates to True
21+
if the lease was obtained.
2122
22-
A common use case is a situation where a task should only run on a single host. In this
23-
case, the clients that did not obtain the lease should exit without performing the protected
24-
task.
23+
A common use case is a situation where a task should only run on a single
24+
host. In this case, the clients that did not obtain the lease should exit
25+
without performing the protected task.
2526
26-
The lease stores time stamps using client clocks, and will therefore only work if client clocks
27-
are roughly synchronised. It uses UTC, and works across time zones and daylight savings.
27+
The lease stores time stamps using client clocks, and will therefore only
28+
work if client clocks are roughly synchronised. It uses UTC, and works
29+
across time zones and daylight savings.
2830
2931
Example usage: with a :class:`~kazoo.client.KazooClient` instance::
3032
3133
zk = KazooClient()
3234
zk.start()
33-
# Hold lease over an hour in order to keep job on same machine, with failover if it dies.
34-
lease = zk.NonBlockingLease("/db_leases/hourly_cleanup", datetime.timedelta(minutes = 70),
35-
identifier = "DB hourly cleanup on " + socket.gethostname())
35+
# Hold lease over an hour in order to keep job on same machine,
36+
# with failover if it dies.
37+
lease = zk.NonBlockingLease(
38+
"/db_leases/hourly_cleanup", datetime.timedelta(minutes = 70),
39+
identifier = "DB hourly cleanup on " + socket.gethostname())
3640
if lease:
3741
do_hourly_database_cleanup()
3842
"""
@@ -42,15 +46,20 @@ class NonBlockingLease(object):
4246
_date_format = "%Y-%m-%dT%H:%M:%S"
4347
_byte_encoding = 'utf-8'
4448

45-
def __init__(self, client, path, duration, identifier=None, utcnow=datetime.datetime.utcnow):
49+
def __init__(self, client, path, duration, identifier=None,
50+
utcnow=datetime.datetime.utcnow):
4651
"""Create a non-blocking lease.
4752
4853
:param client: A :class:`~kazoo.client.KazooClient` instance.
4954
:param path: The lease path to use.
50-
:param duration: Duration during which the lease is reserved. A :class:`~datetime.timedelta` instance.
51-
:param identifier: Unique name to use for this lease holder. Reuse in order to renew the lease.
52-
Defaults do :meth:`socket.gethostname()`.
53-
:param utcnow: Clock function, by default returning :meth:`datetime.datetime.utcnow()`. Used for testing.
55+
:param duration: Duration during which the lease is reserved. A
56+
:class:`~datetime.timedelta` instance.
57+
:param identifier: Unique name to use for this lease holder. Reuse in
58+
order to renew the lease. Defaults to
59+
:meth:`socket.gethostname()`.
60+
:param utcnow: Clock function, by default returning
61+
:meth:`datetime.datetime.utcnow()`. Used for testing.
62+
5463
"""
5564
ident = identifier or socket.gethostname()
5665
self.obtained = False
@@ -69,13 +78,15 @@ def _attempt_obtaining(self, client, path, duration, ident, utcnow):
6978
if data["version"] != self._version:
7079
# We need an upgrade, let someone else take the lease
7180
return
72-
current_end = datetime.datetime.strptime(data['end'], self._date_format)
81+
current_end = datetime.datetime.strptime(data['end'],
82+
self._date_format)
7383
if data['holder'] != ident and now < current_end:
7484
# Another client is still holding the lease
7585
return
7686
client.delete(holder_path)
7787
end_lease = (now + duration).strftime(self._date_format)
78-
new_data = {'version': self._version, 'holder': ident, 'end': end_lease}
88+
new_data = {'version': self._version, 'holder': ident,
89+
'end': end_lease}
7990
client.create(holder_path, self._encode(new_data))
8091
self.obtained = True
8192

@@ -100,16 +111,21 @@ def __bool__(self):
100111
class MultiNonBlockingLease(object):
101112
"""Exclusive lease for multiple clients.
102113
103-
This type of lease is useful when a limited set of hosts should run a particular task.
104-
It will attempt to obtain leases trying a sequence of ZooKeeper lease paths.
114+
This type of lease is useful when a limited set of hosts should run a
115+
particular task. It will attempt to obtain leases trying a sequence of
116+
ZooKeeper lease paths.
105117
106118
:param client: A :class:`~kazoo.client.KazooClient` instance.
107119
:param count: Number of host leases allowed.
108120
:param path: ZooKeeper path under which lease files are stored.
109-
:param duration: Duration during which the lease is reserved. A :class:`~datetime.timedelta` instance.
110-
:param identifier: Unique name to use for this lease holder. Reuse in order to renew the lease.
121+
:param duration: Duration during which the lease is reserved. A
122+
:class:`~datetime.timedelta` instance.
123+
:param identifier: Unique name to use for this lease holder. Reuse in order
124+
to renew the lease.
111125
Defaults do :meth:`socket.gethostname()`.
112-
:param utcnow: Clock function, by default returning :meth:`datetime.datetime.utcnow()`. Used for testing.
126+
:param utcnow: Clock function, by default returning
127+
:meth:`datetime.datetime.utcnow()`. Used for testing.
128+
113129
"""
114130

115131
def __init__(self, client, count, path, duration, identifier=None,

kazoo/recipe/lock.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class Lock(object):
6868
Note: This lock is not *re-entrant*. Repeated calls after already
6969
acquired will block.
7070
71-
This is an exclusive lock. For a read/write lock, see :class:`WriteLock` and
72-
:class:`ReadLock`.
71+
This is an exclusive lock. For a read/write lock, see :class:`WriteLock`
72+
and :class:`ReadLock`.
7373
7474
"""
7575

@@ -267,8 +267,8 @@ def _get_sorted_children(self):
267267

268268
# Node names are prefixed by a type: strip the prefix first, which may
269269
# be one of multiple values in case of a read-write lock, and return
270-
# only the sequence number (as a string since it is padded and will sort
271-
# correctly anyway).
270+
# only the sequence number (as a string since it is padded and will
271+
# sort correctly anyway).
272272
#
273273
# In some cases, the lock path may contain nodes with other prefixes
274274
# (eg. in case of a lease), just sort them last ('~' sorts after all

kazoo/recipe/queue.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _inner_get(self):
100100
# get another one
101101
self._children = []
102102
raise ForceRetryError()
103-
103+
104104
self._children.pop(0)
105105
return data
106106

@@ -269,8 +269,9 @@ def release(self):
269269
270270
:returns: True if the lock was removed successfully, False otherwise.
271271
:rtype: bool
272+
272273
"""
273-
if not self.processing_element is None and self.holds_lock:
274+
if self.processing_element is not None and self.holds_lock:
274275
id_, value = self.processing_element
275276
with self.client.transaction() as transaction:
276277
transaction.delete("{path}/{id}".format(
@@ -281,7 +282,6 @@ def release(self):
281282
else:
282283
return False
283284

284-
285285
def _inner_get(self, timeout):
286286
flag = self.client.handler.event_object()
287287
lock = self.client.handler.lock_object()

0 commit comments

Comments
 (0)