Skip to content

Commit 8e1872e

Browse files
committed
Apply precommit reformatting.
1 parent 2f45d5b commit 8e1872e

File tree

13 files changed

+80
-88
lines changed

13 files changed

+80
-88
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
exclude: '^(\.tox|ci/templates|\.bumpversion\.cfg)(/|$)'
66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: master
8+
rev: v4.1.0
99
hooks:
1010
- id: trailing-whitespace
1111
- id: end-of-file-fixer
1212
- id: debug-statements
1313
- repo: https://github.com/timothycrosley/isort
14-
rev: master
14+
rev: 5.10.1
1515
hooks:
1616
- id: isort
1717
- repo: https://gitlab.com/pycqa/flake8
18-
rev: master
18+
rev: 3.9.2
1919
hooks:
2020
- id: flake8
2121
- repo: https://github.com/psf/black
22-
rev: main
22+
rev: 22.1.0
2323
hooks:
2424
- id: black

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ graft docs
22
graft src
33
graft ci
44
graft tests
5+
graft examples
56

67
include .bumpversion.cfg
78
include .cookiecutterrc

examples/bench.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,7 @@ def run():
6262
logging.critical("============== ============= =========== ========= ========== ========== ========== ==========")
6363

6464

65-
for concurrency in (
66-
1,
67-
2,
68-
3,
69-
6,
70-
12,
71-
24,
72-
48
73-
):
65+
for concurrency in (1, 2, 3, 6, 12, 24, 48):
7466
for duration in (
7567
0,
7668
0.01,
@@ -88,11 +80,20 @@ def run():
8880
if concurrency > 1:
8981
logging.critical(
9082
"%14s %12.3fs %11s %20s %10.2f %10s %10s",
91-
type_, duration, concurrency, sum(ret), sum(ret) / len(ret), min(ret), max(ret)
83+
type_,
84+
duration,
85+
concurrency,
86+
sum(ret),
87+
sum(ret) / len(ret),
88+
min(ret),
89+
max(ret),
9290
)
9391
else:
9492
logging.critical(
9593
"%14s %12.3fs %11s %20s",
96-
type_, duration, concurrency, sum(ret),
94+
type_,
95+
duration,
96+
concurrency,
97+
sum(ret),
9798
)
9899
logging.critical("============== ============= =========== ========= ========== ========== ========== ==========")

examples/bench.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,3 @@ Key takeaways:
7474

7575
* Some clients never get to acquire the lock.
7676
Note the ``Min`` column being ``0`` and the ``Max`` column being very high (indicating how many acquires a single client got).
77-

examples/plain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
else:
2323
getch = msvcrt.getch
2424
else:
25+
2526
def getch():
2627
"""getch() -> key character
2728
@@ -42,6 +43,7 @@ def getch():
4243
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
4344
return ch
4445

46+
4547
logging.basicConfig(level="DEBUG", format="%(asctime)s | %(process)6s | %(message)s")
4648

4749
c = redis.StrictRedis()

examples/test-tmux.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@
2525
if right_commands:
2626
session += 'tmux selectp -t0;tmux splitw -hd -p50 \"%s\"; ' % right_commands[-1]
2727
for index, command in enumerate(right_commands[:-1]):
28-
session += 'tmux selectp -t1;tmux splitw -d -p%i \"%s\"; ' % (
29-
100 / (len(right_commands) - index),
30-
command
31-
)
28+
session += 'tmux selectp -t1;tmux splitw -d -p%i \"%s\"; ' % (100 / (len(right_commands) - index), command)
3229

3330
for index, command in enumerate(left_commands[1:]):
34-
session += 'tmux selectp -t0;tmux splitw -d -p%i \"%s\"; ' % (
35-
100 / (len(left_commands) - index),
36-
command
37-
)
31+
session += 'tmux selectp -t0;tmux splitw -d -p%i \"%s\"; ' % (100 / (len(left_commands) - index), command)
3832
if left_commands:
3933
session += left_commands[0]
4034

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ def read(*names, **kwargs):
7575
'django': [
7676
'django-redis>=3.8.0',
7777
]
78-
}
78+
},
7979
)

src/redis_lock/__init__.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class Lock(object):
9494
"""
9595
A Lock context manager implemented via redis SETNX/BLPOP.
9696
"""
97+
9798
unlock_script = None
9899
extend_script = None
99100
reset_script = None
@@ -132,8 +133,7 @@ def __init__(self, redis_client, name, expire=None, id=None, auto_renewal=False,
132133
Advanced option to override signal list expiration in milliseconds. Increase it for very slow clients. Default: ``1000``.
133134
"""
134135
if strict and not isinstance(redis_client, StrictRedis):
135-
raise ValueError("redis_client must be instance of StrictRedis. "
136-
"Use strict=False if you know what you're doing.")
136+
raise ValueError("redis_client must be instance of StrictRedis. Use strict=False if you know what you're doing.")
137137
if auto_renewal and expire is None:
138138
raise ValueError("Expire may not be None when auto_renewal is set")
139139

@@ -161,9 +161,7 @@ def __init__(self, redis_client, name, expire=None, id=None, auto_renewal=False,
161161
raise TypeError(f"Incorrect type for `id`. Must be bytes/str not {type(id)}.")
162162
self._name = 'lock:' + name
163163
self._signal = 'lock-signal:' + name
164-
self._lock_renewal_interval = (float(expire) * 2 / 3
165-
if auto_renewal
166-
else None)
164+
self._lock_renewal_interval = float(expire) * 2 / 3 if auto_renewal else None
167165
self._lock_renewal_thread = None
168166

169167
self.register_scripts(redis_client)
@@ -255,10 +253,7 @@ def extend(self, expire=None):
255253
elif self._expire is not None:
256254
expire = self._expire
257255
else:
258-
raise TypeError(
259-
"To extend a lock 'expire' must be provided as an "
260-
"argument to extend() method or at initialization time."
261-
)
256+
raise TypeError("To extend a lock 'expire' must be provided as an argument to extend() method or at initialization time.")
262257

263258
error = self.extend_script(client=self._client, keys=(self._name, self._signal), args=(self._id, expire))
264259
if error == 1:
@@ -292,18 +287,18 @@ def _start_lock_renewer(self):
292287
raise AlreadyStarted("Lock refresh thread already started")
293288

294289
logger_for_refresh_start.debug(
295-
"Starting renewal thread for Lock(%r). Refresh interval: %s seconds.",
296-
self._name,
297-
self._lock_renewal_interval
290+
"Starting renewal thread for Lock(%r). Refresh interval: %s seconds.", self._name, self._lock_renewal_interval
298291
)
299292
self._lock_renewal_stop = threading.Event()
300293
self._lock_renewal_thread = threading.Thread(
301294
group=None,
302295
target=self._lock_renewer,
303-
kwargs={'name': self._name,
304-
'lockref': weakref.ref(self),
305-
'interval': self._lock_renewal_interval,
306-
'stop': self._lock_renewal_stop}
296+
kwargs={
297+
'name': self._name,
298+
'lockref': weakref.ref(self),
299+
'interval': self._lock_renewal_interval,
300+
'stop': self._lock_renewal_stop,
301+
},
307302
)
308303
self._lock_renewal_thread.demon = True
309304
self._lock_renewal_thread.start()

src/redis_lock/django_cache.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@
66

77

88
class RedisCache(PlainRedisCache):
9-
109
@property
1110
def __client(self):
1211
try:
1312
return self.client.get_client()
1413
except Exception as exc:
1514
raise NotImplementedError(
16-
"RedisCache doesn't have a raw client: %r. "
17-
"Use 'redis_cache.client.DefaultClient' as the CLIENT_CLASS !" % exc
15+
f"RedisCache doesn't have a raw client: {exc}. Use 'redis_cache.client.DefaultClient' as the CLIENT_CLASS !"
1816
)
1917

2018
def lock(self, key, expire=None, id=None, auto_renewal=False):
2119
return Lock(self.__client, key, expire=expire, id=id, auto_renewal=auto_renewal)
2220

23-
def locked_get_or_set(self, key, value_creator, version=None,
24-
expire=None, id=None, lock_key=None,
25-
timeout=DEFAULT_TIMEOUT):
21+
def locked_get_or_set(self, key, value_creator, version=None, expire=None, id=None, lock_key=None, timeout=DEFAULT_TIMEOUT):
2622
"""
2723
Fetch a given key from the cache. If the key does not exist, the key is added and
2824
set to the value returned when calling `value_creator`. The creator function

tests/conftest.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ def redis_server(tmp_path):
1515
except OSError:
1616
pass
1717
with TestProcess(
18-
'redis-server',
19-
'--port', '0',
20-
'--save', '',
21-
'--appendonly', 'yes',
22-
'--dir', tmp_path,
23-
'--unixsocket', UDS_PATH
18+
'redis-server', '--port', '0', '--save', '', '--appendonly', 'yes', '--dir', tmp_path, '--unixsocket', UDS_PATH
2419
) as redis_server:
2520
wait_for_strings(redis_server.read, TIMEOUT, 'ready to accept connections')
2621
yield redis_server

0 commit comments

Comments
 (0)