Skip to content

Commit d479e23

Browse files
committed
THRIFT-3691 Run flake8 Python style check on Travis-CI
Client: Build (Python) Patch: Nobuaki Sukegawa This closes apache#907
1 parent 2c5ed27 commit d479e23

26 files changed

+74
-42
lines changed

.travis.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# build Apache Thrift on Travis CI - https://travis-ci.org/
2121

2222
sudo: required
23+
dist: trusty
2324

2425
services:
2526
- docker
@@ -148,12 +149,18 @@ matrix:
148149
include:
149150
# QA jobs for code analytics and metrics
150151
#
151-
# static code analysis with cppcheck
152+
# C/C++ static code analysis with cppcheck
152153
# add --error-exitcode=1 to --enable=all as soon as everything is fixed
153-
- env: TEST_NAME="cppcheck"
154+
#
155+
# Python code style check with flake8
156+
#
157+
# search for TODO etc within source tree
158+
# some statistics about the code base
159+
# some info about the build machine
160+
- env: TEST_NAME="cppcheck, flake8, TODO FIXME HACK, LoC and system info"
154161
install:
155162
- sudo apt-get update
156-
- sudo apt-get install cppcheck
163+
- sudo apt-get install -y cppcheck sloccount python-flake8
157164
script:
158165
# Compiler cppcheck (All)
159166
- cppcheck --force --quiet --inline-suppr --enable=all -j2 compiler/cpp/src
@@ -165,15 +172,16 @@ matrix:
165172
- cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 compiler/cpp/src
166173
- cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/cpp/src lib/cpp/test test/cpp tutorial/cpp
167174
- cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib
168-
169-
# search for TODO etc within source tree
170-
# some statistics about the code base
171-
# some info about the build machine
172-
- env: TEST_NAME="TODO FIXME HACK, LoC and system info"
173-
install:
174-
- sudo apt-get update
175-
- sudo apt-get install sloccount
176-
script:
175+
# Python code style
176+
- flake8 --ignore=E501 lib/py
177+
- flake8 tutorial/py
178+
- flake8 --ignore=E501 test/py
179+
- flake8 test/py.twisted
180+
- flake8 test/py.tornado
181+
- flake8 --ignore=E501 test/test.py
182+
- flake8 --ignore=E501 test/crossrunner
183+
- flake8 test/features
184+
# TODO etc
177185
- grep -r TODO *
178186
- grep -r FIXME *
179187
- grep -r HACK *

compiler/cpp/src/main.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ string include_file(string filename) {
356356
if (filename[0] == '/') {
357357
// Realpath!
358358
char rp[THRIFT_PATH_MAX];
359+
// cppcheck-suppress uninitvar
359360
if (saferealpath(filename.c_str(), rp) == NULL) {
360361
pwarning(0, "Cannot open include file %s\n", filename.c_str());
361362
return std::string();
@@ -378,6 +379,7 @@ string include_file(string filename) {
378379

379380
// Realpath!
380381
char rp[THRIFT_PATH_MAX];
382+
// cppcheck-suppress uninitvar
381383
if (saferealpath(sfilename.c_str(), rp) == NULL) {
382384
continue;
383385
}
@@ -1163,6 +1165,7 @@ int main(int argc, char** argv) {
11631165
}
11641166
char old_thrift_file_rp[THRIFT_PATH_MAX];
11651167

1168+
// cppcheck-suppress uninitvar
11661169
if (saferealpath(arg, old_thrift_file_rp) == NULL) {
11671170
failure("Could not open input file with realpath: %s", arg);
11681171
}
@@ -1231,6 +1234,7 @@ int main(int argc, char** argv) {
12311234
fprintf(stderr, "Missing file name of new thrift file for audit\n");
12321235
usage();
12331236
}
1237+
// cppcheck-suppress uninitvar
12341238
if (saferealpath(argv[i], new_thrift_file_rp) == NULL) {
12351239
failure("Could not open input file with realpath: %s", argv[i]);
12361240
}
@@ -1256,6 +1260,7 @@ int main(int argc, char** argv) {
12561260
fprintf(stderr, "Missing file name\n");
12571261
usage();
12581262
}
1263+
// cppcheck-suppress uninitvar
12591264
if (saferealpath(argv[i], rp) == NULL) {
12601265
failure("Could not open input file with realpath: %s", argv[i]);
12611266
}

lib/py/CMakeLists.txt

100755100644
File mode changed.

lib/py/Makefile.am

100755100644
File mode changed.

lib/py/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
optimize = 1
33
[metadata]
44
description-file = README.md
5+
[flake8]
6+
max-line-length = 100

lib/py/src/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def str_to_binary(str_val):
3131

3232
else:
3333

34-
from io import BytesIO as BufferIO
34+
from io import BytesIO as BufferIO # noqa
3535

3636
def binary_to_str(bin_val):
3737
return bin_val.decode('utf8')

lib/py/test/thrift_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import sys
2121
import unittest
2222

23-
import _import_local_thrift
23+
import _import_local_thrift # noqa
2424
from thrift.protocol.TJSONProtocol import TJSONProtocol
2525
from thrift.transport import TTransport
2626

test/crossrunner/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# under the License.
1818
#
1919

20-
from .test import test_name
21-
from .collect import collect_cross_tests, collect_feature_tests
22-
from .run import TestDispatcher
23-
from .report import generate_known_failures, load_known_failures
20+
from .test import test_name # noqa
21+
from .collect import collect_cross_tests, collect_feature_tests # noqa
22+
from .run import TestDispatcher # noqa
23+
from .report import generate_known_failures, load_known_failures # noqa

test/crossrunner/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
RESULT_TIMEOUT = 128
3838
RESULT_ERROR = 64
3939

40+
# globals
41+
ports = None
42+
stop = None
43+
4044

4145
class ExecutionContext(object):
4246
def __init__(self, cmd, cwd, env, report):

test/crossrunner/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 100

test/features/container_limit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55

66
from util import add_common_args, init_protocol
7-
from local_thrift import thrift
7+
from local_thrift import thrift # noqa
88
from thrift.Thrift import TMessageType, TType
99

1010

test/features/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 100

test/features/string_limit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55

66
from util import add_common_args, init_protocol
7-
from local_thrift import thrift
7+
from local_thrift import thrift # noqa
88
from thrift.Thrift import TMessageType, TType
99

1010

test/features/theader_binary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66

77
from util import add_common_args
8-
from local_thrift import thrift
8+
from local_thrift import thrift # noqa
99
from thrift.Thrift import TMessageType, TType
1010
from thrift.transport.TSocket import TSocket
1111
from thrift.transport.TTransport import TBufferedTransport, TFramedTransport

test/features/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
import socket
33

4-
from local_thrift import thrift
4+
from local_thrift import thrift # noqa
55
from thrift.transport.TSocket import TSocket
66
from thrift.transport.TTransport import TBufferedTransport, TFramedTransport
77
from thrift.transport.THttpClient import THttpClient

test/py.tornado/setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
ignore = E402
3+
max-line-length = 100

test/py.tornado/test_suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from thrift.transport.TTransport import TTransportException
4545

4646
from ThriftTest import ThriftTest
47-
from ThriftTest.ttypes import *
47+
from ThriftTest.ttypes import Xception, Xtruct
4848

4949

5050
class TestHandler(object):

test/py.twisted/setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
ignore = E402
3+
max-line-length = 100

test/py.twisted/test_suite.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ def setUp(self):
113113
self.processor = ThriftTest.Processor(self.handler)
114114
self.pfactory = TBinaryProtocol.TBinaryProtocolFactory()
115115

116-
self.server = reactor.listenTCP(0,
117-
TTwisted.ThriftServerFactory(self.processor,
118-
self.pfactory), interface="127.0.0.1")
116+
self.server = reactor.listenTCP(
117+
0, TTwisted.ThriftServerFactory(self.processor, self.pfactory), interface="127.0.0.1")
119118

120119
self.portNo = self.server.getHost().port
121120

test/py/SerializationTest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def setUp(self):
8080
vertwo2000=VersioningTestV2(newstruct=Bonk(message='World!', type=314)),
8181
a_set2500=set(['lazy', 'brown', 'cow']),
8282
vertwo3000=VersioningTestV2(newset=set([2, 3, 5, 7, 11])),
83-
big_numbers=[2**8, 2**16, 2**31 - 1, -(2**31 - 1)]
83+
big_numbers=[2 ** 8, 2 ** 16, 2 ** 31 - 1, -(2 ** 31 - 1)]
8484
)
8585

8686
self.compact_struct = CompactProtoTestStruct(
@@ -160,10 +160,9 @@ def setUp(self):
160160
# note, the sets below are sets of chars, since the strings are iterated
161161
map_int_strset={10: set('abc'), 20: set('def'), 30: set('GHI')},
162162
map_int_strset_list=[
163-
{10: set('abc'), 20: set('def'), 30: set('GHI')},
164-
{100: set('lmn'), 200: set('opq'), 300: set('RST')},
165-
{1000: set('uvw'), 2000: set('wxy'), 3000: set('XYZ')}
166-
]
163+
{10: set('abc'), 20: set('def'), 30: set('GHI')},
164+
{100: set('lmn'), 200: set('opq'), 300: set('RST')},
165+
{1000: set('uvw'), 2000: set('wxy'), 3000: set('XYZ')}]
167166
)
168167

169168
self.nested_lists_bonk = NestedListsBonk(

test/py/TestClient.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# under the License.
2020
#
2121

22-
import glob
2322
import os
2423
import sys
2524
import time

test/py/TestSyntax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
#
2121

2222
# Just import these generated files to make sure they are syntactically valid
23-
from DebugProtoTest import EmptyService
24-
from DebugProtoTest import Inherited
23+
from DebugProtoTest import EmptyService # noqa
24+
from DebugProtoTest import Inherited # noqa

test/py/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 100

tutorial/py/PythonClient.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def main():
5252
client.ping()
5353
print('ping()')
5454

55-
sum = client.add(1, 1)
56-
print(('1+1=%d' % (sum)))
55+
sum_ = client.add(1, 1)
56+
print('1+1=%d' % sum_)
5757

5858
work = Work()
5959

@@ -66,17 +66,17 @@ def main():
6666
print('Whoa? You know how to divide by zero?')
6767
print('FYI the answer is %d' % quotient)
6868
except InvalidOperation as e:
69-
print(('InvalidOperation: %r' % e))
69+
print('InvalidOperation: %r' % e)
7070

7171
work.op = Operation.SUBTRACT
7272
work.num1 = 15
7373
work.num2 = 10
7474

7575
diff = client.calculate(1, work)
76-
print(('15-10=%d' % (diff)))
76+
print('15-10=%d' % diff)
7777

7878
log = client.getStruct(1)
79-
print(('Check log: %s' % (log.value)))
79+
print('Check log: %s' % log.value)
8080

8181
# Close!
8282
transport.close()
@@ -85,4 +85,4 @@ def main():
8585
try:
8686
main()
8787
except Thrift.TException as tx:
88-
print(('%s' % (tx.message)))
88+
print('%s' % tx.message)

tutorial/py/PythonServer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ def zip(self):
9292
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
9393

9494
# You could do one of these for a multithreaded server
95-
# server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
96-
# server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
95+
# server = TServer.TThreadedServer(
96+
# processor, transport, tfactory, pfactory)
97+
# server = TServer.TThreadPoolServer(
98+
# processor, transport, tfactory, pfactory)
9799

98100
print('Starting the server...')
99101
server.serve()

tutorial/py/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
ignore = E402

0 commit comments

Comments
 (0)