diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..df8fdb261 --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +exclude = .git,__pycache__,**/gen-*/**,contrib/**,docs/source/conf.py,old,build,dist +ignore = W504,E402,E501 +max-complexity = 30 +max-line-length = 120 diff --git a/build/appveyor/CYGW-appveyor-install.bat b/build/appveyor/CYGW-appveyor-install.bat index 79b6ef06b..72712b20e 100644 --- a/build/appveyor/CYGW-appveyor-install.bat +++ b/build/appveyor/CYGW-appveyor-install.bat @@ -25,6 +25,12 @@ CALL cl_banner_install.bat || EXIT /B CALL cl_setenv.bat || EXIT /B CALL cl_showenv.bat || EXIT /B +:: +:: Upgrades cygwin to the latest, if you want... +:: +:: appveyor DownloadFile "https://cygwin.com/setup-x86_64.exe" +:: setup-x86_64.exe --quiet-mode --wait --upgrade-also --packages="gcc-g++" + :: :: Install apt-cyg for package management :: diff --git a/build/docker/scripts/sca.sh b/build/docker/scripts/sca.sh index 16d582619..42128fc67 100755 --- a/build/docker/scripts/sca.sh +++ b/build/docker/scripts/sca.sh @@ -39,15 +39,7 @@ cppcheck --force --quiet --inline-suppr --error-exitcode=1 -j2 lib/cpp/src lib/c 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=W504,E501 lib/py -flake8 --exclude=tutorial/py/build tutorial/py -# THRIFT-4371 : generated files are excluded because they haven't been scrubbed yet -flake8 --ignore=E501 --exclude="*/gen-py*/*",test/py/build test/py -flake8 test/py.twisted -flake8 test/py.tornado -flake8 --ignore=E501 test/test.py -flake8 --ignore=E501,E722 test/crossrunner -flake8 test/features +flake8 # PHP code style composer install --quiet diff --git a/lib/nodejs/examples/httpServer.py b/lib/nodejs/examples/httpServer.py index b712fcd7f..76e9f4aa3 100644 --- a/lib/nodejs/examples/httpServer.py +++ b/lib/nodejs/examples/httpServer.py @@ -5,10 +5,12 @@ from hello import HelloSvc from thrift.protocol import TJSONProtocol from thrift.server import THttpServer + class HelloSvcHandler: - def hello_func(self): - print("Hello Called") - return "hello from Python" + def hello_func(self): + print("Hello Called") + return "hello from Python" + processor = HelloSvc.Processor(HelloSvcHandler()) protoFactory = TJSONProtocol.TJSONProtocolFactory() diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp index 33ba20343..c4146cc5c 100644 --- a/test/cpp/src/TestClient.cpp +++ b/test/cpp/src/TestClient.cpp @@ -69,12 +69,12 @@ using namespace thrift::test; // agreement between client and server. // -template -class TPedanticProtocol : public _P +template +class TPedanticProtocol : public Proto { public: TPedanticProtocol(std::shared_ptr& transport) - : _P(transport), m_last_seqid((std::numeric_limits::max)() - 10) { } + : Proto(transport), m_last_seqid((std::numeric_limits::max)() - 10) { } virtual uint32_t writeMessageBegin_virt(const std::string& name, const TMessageType messageType, @@ -85,14 +85,14 @@ class TPedanticProtocol : public _P seqid = ++m_last_seqid; } - return _P::writeMessageBegin_virt(name, messageType, seqid); + return Proto::writeMessageBegin_virt(name, messageType, seqid); } virtual uint32_t readMessageBegin_virt(std::string& name, TMessageType& messageType, int32_t& seqid) override { - uint32_t result = _P::readMessageBegin_virt(name, messageType, seqid); + uint32_t result = Proto::readMessageBegin_virt(name, messageType, seqid); if (seqid != m_last_seqid) { std::stringstream ss; ss << "ERROR: send request with seqid " << m_last_seqid << " and got reply with seqid " << seqid; diff --git a/test/crossrunner/run.py b/test/crossrunner/run.py index ef8fb60f3..bb06d25ef 100644 --- a/test/crossrunner/run.py +++ b/test/crossrunner/run.py @@ -259,7 +259,7 @@ def run_test(testdir, logdir, test_dict, max_retry, async_mode=True): raise logger.warn('Error executing [%s]', test.name, exc_info=True) return (retry_count, RESULT_ERROR) - except: + except Exception: logger.info('Interrupted execution', exc_info=True) if not async_mode: raise diff --git a/test/py/TestClient.py b/test/py/TestClient.py index cc9185cfe..a85098eb4 100755 --- a/test/py/TestClient.py +++ b/test/py/TestClient.py @@ -26,9 +26,7 @@ import unittest from optparse import OptionParser from util import local_libpath - sys.path.insert(0, local_libpath()) - from thrift.protocol import TProtocolDecorator from thrift.protocol import TProtocol @@ -277,6 +275,7 @@ class AbstractTest(unittest.TestCase): # running on it (when multiplexec) LAST_SEQID = None + class TPedanticSequenceIdProtocolWrapper(TProtocolDecorator.TProtocolDecorator): """ Wraps any protocol with sequence ID checking: looks for outbound @@ -289,7 +288,8 @@ class TPedanticSequenceIdProtocolWrapper(TProtocolDecorator.TProtocolDecorator): def writeMessageBegin(self, name, type, seqid): global LAST_SEQID if LAST_SEQID and LAST_SEQID == seqid: - raise TProtocol.TProtocolException(INVALID_DATA, + raise TProtocol.TProtocolException( + TProtocol.TProtocolException.INVALID_DATA, "Python client reused sequence ID {0}".format(seqid)) LAST_SEQID = seqid super(TPedanticSequenceIdProtocolWrapper, self).writeMessageBegin( @@ -300,7 +300,8 @@ class TPedanticSequenceIdProtocolWrapper(TProtocolDecorator.TProtocolDecorator): (name, type, seqid) =\ super(TPedanticSequenceIdProtocolWrapper, self).readMessageBegin() if LAST_SEQID != seqid: - raise TProtocol.TProtocolException(INVALID_DATA, + raise TProtocol.TProtocolException( + TProtocol.TProtocolException.INVALID_DATA, "We sent seqid {0} and server returned seqid {1}".format( self.last, seqid)) return (name, type, seqid) @@ -310,6 +311,7 @@ def make_pedantic(proto): """ Wrap a protocol in the pedantic sequence ID wrapper. """ return TPedanticSequenceIdProtocolWrapper(proto) + class MultiplexedOptionalTest(AbstractTest): def get_protocol2(self, transport): return None diff --git a/tutorial/php/runserver.py b/tutorial/php/runserver.py index 077daa102..8cc30fbe5 100755 --- a/tutorial/php/runserver.py +++ b/tutorial/php/runserver.py @@ -30,4 +30,5 @@ os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) class Handler(CGIHTTPServer.CGIHTTPRequestHandler): cgi_directories = ['/php'] + BaseHTTPServer.HTTPServer(('', 8080), Handler).serve_forever() diff --git a/tutorial/py.twisted/PythonClient.py b/tutorial/py.twisted/PythonClient.py index 63dde7e7a..2976495e3 100755 --- a/tutorial/py.twisted/PythonClient.py +++ b/tutorial/py.twisted/PythonClient.py @@ -67,6 +67,7 @@ def main(client): print(('Check log: %s' % (log.value))) reactor.stop() + if __name__ == '__main__': d = ClientCreator(reactor, TTwisted.ThriftClientProtocol, diff --git a/tutorial/py.twisted/PythonServer.py b/tutorial/py.twisted/PythonServer.py index 1b0e2d5b9..034e4a312 100755 --- a/tutorial/py.twisted/PythonServer.py +++ b/tutorial/py.twisted/PythonServer.py @@ -85,6 +85,7 @@ class CalculatorHandler: def zip(self): print('zip()') + if __name__ == '__main__': handler = CalculatorHandler() processor = Calculator.Processor(handler)