Skip to content

Commit b8fb1ef

Browse files
committed
Enforce consistent code style with flake8
1 parent d8fe153 commit b8fb1ef

34 files changed

+208
-146
lines changed

.ci/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ tinys3
44
twine
55
psutil
66
pyOpenSSL==18.0.0
7+
flake8>=3.7.5

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
filename = *.py,*.pyx,*.pxd,*.pxi
3+
ignore = E402,E731,D100,D101,D102,D103,D104,D105,W503,W504,E252
4+
exclude = .git,__pycache__,build,dist,.eggs,postgres,vendor
5+
6+
per-file-ignores = *.pyx,*.pxd,*.pxi: E211, E222, E225, E226, E227, E999

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
sys.path.insert(0, os.path.abspath('..'))
99

1010
with open(os.path.abspath('../setup.py'), 'rt') as f:
11-
_m = re.search(r'''VERSION\s*=\s*(?P<q>'|")(?P<ver>[\d\.]+)(?P=q)''', f.read())
11+
_m = re.search(r'''VERSION\s*=\s*(?P<q>'|")(?P<ver>[\d\.]+)(?P=q)''',
12+
f.read())
1213
if not _m:
1314
raise RuntimeError('unable to read the version from setup.py')
1415
version = _m.group('ver')

examples/bench/echoclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
MSGSIZE = args.msize
4848
REQSIZE = MSGSIZE * args.mpr
4949

50-
msg = b'x'*(MSGSIZE - 1) + b'\n'
50+
msg = b'x' * (MSGSIZE - 1) + b'\n'
5151
if args.mpr:
5252
msg *= args.mpr
5353

@@ -90,6 +90,6 @@ def run_test(n):
9090
for _ in range(N):
9191
e.submit(run_test, NMESSAGES)
9292
end = time.time()
93-
duration = end-start
93+
duration = end - start
9494
print(NMESSAGES * N * TIMES, 'in', duration)
9595
print(NMESSAGES * N * TIMES / duration, 'requests/sec')

examples/bench/rlserver.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import asyncio
33
import gc
44
import os.path
5-
import socket as socket_module
6-
7-
from socket import *
5+
import socket as stdsock
86

97

108
PRINT = 0
@@ -13,7 +11,8 @@
1311
async def echo_client_streams(reader, writer):
1412
sock = writer.get_extra_info('socket')
1513
try:
16-
sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
14+
sock.setsockopt(
15+
stdsock.IPPROTO_TCP, stdsock.TCP_NODELAY, 1)
1716
except (OSError, NameError):
1817
pass
1918
if PRINT:

requirements.dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Cython==0.29.0
22
Sphinx>=1.4.1
33
psutil
44
pyOpenSSL==18.0.0
5+
flake8>=3.7.5

tests/test_aiohttp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ async def stop():
101101
self.loop.run_until_complete(stop())
102102

103103

104-
105104
@unittest.skipIf(skip_tests, "no aiohttp module")
106105
class Test_UV_AioHTTP(_TestAioHTTP, tb.UVTestCase):
107106
pass

tests/test_pipes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ def reader(data):
224224
return len(data)
225225

226226
tb.run_until(self.loop, lambda: reader(data) >= 1,
227-
timeout=10)
227+
timeout=10)
228228
self.assertEqual(b'1', data)
229229

230230
transport.write(b'2345')
231231
tb.run_until(self.loop, lambda: reader(data) >= 5,
232-
timeout=10)
232+
timeout=10)
233233
self.assertEqual(b'12345', data)
234234
self.assertEqual('CONNECTED', proto.state)
235235

tests/test_signals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ def test_signals_invalid_signal(self):
270270
self.loop.add_signal_handler(signal.SIGKILL, lambda *a: None)
271271

272272
def test_signals_coro_callback(self):
273-
async def coro(): pass
273+
async def coro():
274+
pass
274275
with self.assertRaisesRegex(TypeError, 'coroutines cannot be used'):
275276
self.loop.add_signal_handler(signal.SIGHUP, coro)
276277

tests/test_sourcecode.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import subprocess
3+
import sys
4+
import unittest
5+
6+
7+
def find_uvloop_root():
8+
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9+
10+
11+
class TestFlake8(unittest.TestCase):
12+
13+
@unittest.skipIf(sys.version_info < (3, 6, 0),
14+
"flake8 under 3.5 does not recognize f-strings in *.pyx")
15+
def test_flake8(self):
16+
edgepath = find_uvloop_root()
17+
config_path = os.path.join(edgepath, '.flake8')
18+
if not os.path.exists(config_path):
19+
raise RuntimeError('could not locate .flake8 file')
20+
21+
try:
22+
import flake8 # NoQA
23+
except ImportError:
24+
raise unittest.SkipTest('flake8 moudule is missing')
25+
26+
for subdir in ['examples', 'uvloop', 'tests']:
27+
try:
28+
subprocess.run(
29+
[sys.executable, '-m', 'flake8', '--config', config_path],
30+
check=True,
31+
stdout=subprocess.PIPE,
32+
stderr=subprocess.PIPE,
33+
cwd=os.path.join(edgepath, subdir))
34+
except subprocess.CalledProcessError as ex:
35+
output = ex.output.decode()
36+
raise AssertionError(
37+
'flake8 validation failed:\n{}'.format(output)) from None

0 commit comments

Comments
 (0)