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
main
Peter Dillinger 5 years ago committed by Facebook Github Bot
parent 54f9092b0c
commit 5b18729d7d
  1. 2
      Makefile
  2. 17
      tools/check_all_python.py

@ -939,6 +939,7 @@ check: all
fi fi
rm -rf $(TMPD) rm -rf $(TMPD)
ifneq ($(PLATFORM), OS_AIX) ifneq ($(PLATFORM), OS_AIX)
python tools/check_all_python.py
ifeq ($(filter -DROCKSDB_LITE,$(OPT)),) ifeq ($(filter -DROCKSDB_LITE,$(OPT)),)
python tools/ldb_test.py python tools/ldb_test.py
sh tools/rocksdb_dump_test.sh sh tools/rocksdb_dump_test.sh
@ -2051,6 +2052,7 @@ jtest_run:
jtest: rocksdbjava jtest: rocksdbjava
cd java;$(MAKE) sample;$(MAKE) test; 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: jdb_bench:
cd java;$(MAKE) db_bench; cd java;$(MAKE) db_bench;

@ -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))
Loading…
Cancel
Save