1#!/usr/bin/env python2
2# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3import glob
4
5# Checks that all python files in the repository are at least free of syntax
6# errors. This provides a minimal pre-/post-commit check for python file
7# modifications.
8
9filenames = []
10# Avoid scanning all of ./ because there might be other external repos
11# linked in.
12for base in ["buckifier", "build_tools", "coverage", "tools"]:
13    # Clean this up when we finally upgrade to Python 3
14    for suff in ["*", "*/*", "*/*/*"]:
15        filenames += glob.glob(base + "/" + suff + ".py")
16
17for filename in filenames:
18    source = open(filename, 'r').read() + '\n'
19    # Parses and syntax checks the file, throwing on error. (No pyc written.)
20    _ = compile(source, filename, 'exec')
21
22print("No syntax errors in {0} .py files".format(len(filenames)))
23