From 5b18729d7d628d7b4888d1070ee834fde924ca50 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Thu, 19 Dec 2019 08:29:32 -0800 Subject: [PATCH] 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 --- Makefile | 2 ++ tools/check_all_python.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tools/check_all_python.py diff --git a/Makefile b/Makefile index e4cbedd0b..ad98ee7bc 100644 --- a/Makefile +++ b/Makefile @@ -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; diff --git a/tools/check_all_python.py b/tools/check_all_python.py new file mode 100644 index 000000000..e6aa9e12a --- /dev/null +++ b/tools/check_all_python.py @@ -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))