Skip to content

Commit

Permalink
THRIFT-4370: build generated code before running static code analysis;
Browse files Browse the repository at this point in the history
fix E722 flake8 issues identified in python code

This closes apache#1399
  • Loading branch information
jeking3 committed Oct 26, 2017
1 parent 254e86b commit 350fe75
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
20 changes: 17 additions & 3 deletions build/docker/scripts/sca.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#!/bin/sh
set -ev

#
# Generate thrift files so the static code analysis includes an analysis
# of the files the thrift compiler spits out. If running interactively
# set the NOBUILD environment variable to skip the boot/config/make phase.
#

if [[ -z "$NOBUILD" ]]; then
./bootstrap.sh
./configure --enable-tutorial=no
make -j3 precross
fi

#
# C/C++ static code analysis with cppcheck
# add --error-exitcode=1 to --enable=all as soon as everything is fixed
Expand All @@ -21,18 +33,20 @@ cppcheck --force --quiet --inline-suppr --enable=all -j2 lib/cpp/src lib/cpp/tes
cppcheck --force --quiet --inline-suppr --enable=all -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib

# Silent error checks
cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 compiler/cpp/src
# See THRIFT-4371 : flex generated code triggers "possible null pointer dereference" in yy_init_buffer
cppcheck --force --quiet --inline-suppr --suppress="*:thrift/thriftl.cc" --error-exitcode=1 -j2 compiler/cpp/src
cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/cpp/src lib/cpp/test test/cpp tutorial/cpp
cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/c_glib/src lib/c_glib/test test/c_glib/src tutorial/c_glib

# Python code style
flake8 --ignore=E501 lib/py
flake8 tutorial/py
flake8 --ignore=E501 test/py
# THRIFT-4371 : generated files are excluded because they haven't been scrubbed yet
flake8 --ignore=E501 --exclude="*/gen-py*/*" test/py
flake8 test/py.twisted
flake8 test/py.tornado
flake8 --ignore=E501 test/test.py
flake8 --ignore=E501 test/crossrunner
flake8 --ignore=E501,E722 test/crossrunner
flake8 test/features

# TODO etc
Expand Down
2 changes: 1 addition & 1 deletion lib/py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys
try:
from setuptools import setup, Extension
except:
except Exception:
from distutils.core import setup, Extension

from distutils.command.build_ext import build_ext
Expand Down
2 changes: 1 addition & 1 deletion test/features/container_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(argv):
print('[OK]: just limit')
try:
test_list(proto, list(range(args.limit + 1)))
except:
except Exception:
print('[OK]: limit + 1')
else:
print('[ERROR]: limit + 1')
Expand Down
2 changes: 1 addition & 1 deletion test/features/string_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main(argv):
print('[OK]: just limit')
try:
test_string(proto, 'a' * (args.limit + 1))
except:
except Exception:
print('[OK]: limit + 1')
else:
print('[ERROR]: limit + 1')
Expand Down
4 changes: 2 additions & 2 deletions test/py/TestServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def main(options):
try:
pfactory.string_length_limit = options.string_limit
pfactory.container_length_limit = options.container_limit
except:
except Exception:
# Ignore errors for those protocols that does not support length limit
pass

Expand Down Expand Up @@ -255,7 +255,7 @@ def clean_shutdown(signum, frame):
logging.info('Requesting server to stop()')
try:
server.stop()
except:
except Exception:
pass
signal.signal(signal.SIGALRM, clean_shutdown)
signal.alarm(4)
Expand Down
6 changes: 3 additions & 3 deletions test/py/TestSocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setUp(self):
self.listen_sock.bind(('localhost', self.port))
self.listen_sock.listen(5)
break
except:
except Exception:
if i == 49:
raise

Expand All @@ -50,7 +50,7 @@ def testConnectTimeout(self):
socket.setTimeout(10)
socket.open()
leaky.append(socket)
except:
except Exception:
self.assert_(time.time() - starttime < 5.0)

def testWriteTimeout(self):
Expand All @@ -64,7 +64,7 @@ def testWriteTimeout(self):
while True:
lsock.write("hi" * 100)

except:
except Exception:
self.assert_(time.time() - starttime < 5.0)


Expand Down

0 comments on commit 350fe75

Please sign in to comment.