From 1ba92b858292ff9b110601eb03460d8ca1cb4b86 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Thu, 19 Dec 2019 15:35:37 -0800 Subject: [PATCH] Only search specific directories in Python check (#6225) Summary: The new Python syntax check could fail if external entities were cloned or symlinked to a subdir in a rocksdb git clone. (E.g. Facebook internal LITE build.) Only look for Python files in specific subdirs Pull Request resolved: https://github.com/facebook/rocksdb/pull/6225 Test Plan: python tools/check_all_python.py (still 34 files checked) Reviewed By: gfosco Differential Revision: D19186110 Pulled By: pdillinger fbshipit-source-id: 1fefa54e36b32cd5d96d3d1a43e8a2a694c22ea5 --- tools/check_all_python.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/check_all_python.py b/tools/check_all_python.py index e6aa9e12a..17fe95eab 100644 --- a/tools/check_all_python.py +++ b/tools/check_all_python.py @@ -6,12 +6,17 @@ import glob # 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"): +filenames = [] +# Avoid scanning all of ./ because there might be other external repos +# linked in. +for base in ["buckifier", "build_tools", "coverage", "tools"]: + # Clean this up when we finally upgrade to Python 3 + for suff in ["*", "*/*", "*/*/*"]: + filenames += glob.glob(base + "/" + suff + ".py") + +for filename in filenames: 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)) +print("No syntax errors in {0} .py files".format(len(filenames)))