Syntax check python files on testing (#6209)

Summary:
Adds a python script to syntax check all python files in the
repository and report any errors.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6209

Test Plan:
'make check' with and without seeded syntax errors. Also look
for "No syntax errors in 34 .py files" on success, and in java_test CI output

Differential Revision: D19166756

Pulled By: pdillinger

fbshipit-source-id: 537df464b767260d66810b4cf4c9808a026c58a4
This commit is contained in:
Peter Dillinger 2019-12-19 08:29:32 -08:00 committed by Facebook Github Bot
parent 54f9092b0c
commit 5b18729d7d
2 changed files with 19 additions and 0 deletions

View File

@ -939,6 +939,7 @@ check: all
fi
rm -rf $(TMPD)
ifneq ($(PLATFORM), OS_AIX)
python tools/check_all_python.py
ifeq ($(filter -DROCKSDB_LITE,$(OPT)),)
python tools/ldb_test.py
sh tools/rocksdb_dump_test.sh
@ -2051,6 +2052,7 @@ jtest_run:
jtest: rocksdbjava
cd java;$(MAKE) sample;$(MAKE) test;
python tools/check_all_python.py # TODO peterd: find a better place for this check in CI targets
jdb_bench:
cd java;$(MAKE) db_bench;

17
tools/check_all_python.py Normal file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python2
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import glob
# Checks that all python files in the repository are at least free of syntax
# errors. This provides a minimal pre-/post-commit check for python file
# modifications.
count = 0
# Clean this up when we finally upgrade to Python 3
for filename in glob.glob("*.py") + glob.glob("*/*.py") + glob.glob("*/*/*.py") + glob.glob("*/*/*/*.py"):
source = open(filename, 'r').read() + '\n'
# Parses and syntax checks the file, throwing on error. (No pyc written.)
_ = compile(source, filename, 'exec')
count = count + 1
print("No syntax errors in {0} .py files".format(count))