Blame check-pyc-and-pyo-timestamps.py

e32ce18
"""Checks if all *.pyc and *.pyo files have later mtime than their *.py files."""
e32ce18
e32ce18
import imp
e32ce18
import os
e32ce18
import sys
e32ce18
e32ce18
# list of test and other files that we expect not to have bytecode
e32ce18
not_compiled = [
e32ce18
    'test/bad_coding.py',
e32ce18
    'test/bad_coding2.py',
e32ce18
    'test/badsyntax_3131.py',
e32ce18
    'test/badsyntax_future3.py',
e32ce18
    'test/badsyntax_future4.py',
e32ce18
    'test/badsyntax_future5.py',
e32ce18
    'test/badsyntax_future6.py',
e32ce18
    'test/badsyntax_future7.py',
e32ce18
    'test/badsyntax_future8.py',
e32ce18
    'test/badsyntax_future9.py',
e32ce18
    'test/badsyntax_future10.py',
e32ce18
    'test/badsyntax_pep3120.py',
e32ce18
    'lib2to3/tests/data/bom.py',
e32ce18
    'lib2to3/tests/data/crlf.py',
e32ce18
    'lib2to3/tests/data/different_encoding.py',
e32ce18
    'lib2to3/tests/data/false_encoding.py',
e32ce18
    'lib2to3/tests/data/py2_test_grammar.py',
e32ce18
    '.debug-gdb.py',
e32ce18
]
e32ce18
failed = 0
e32ce18
e32ce18
def bytecode_expected(source):
e32ce18
    for f in not_compiled:
e32ce18
        if source.endswith(f):
e32ce18
            return False
e32ce18
    return True
e32ce18
e32ce18
compiled = filter(lambda f: bytecode_expected(f), sys.argv[1:])
e32ce18
for f in compiled:
e32ce18
    # check both pyo and pyc
e32ce18
    to_check = map(lambda b: imp.cache_from_source(f, b), (True, False))
e32ce18
    f_mtime = os.path.getmtime(f)
e32ce18
    for c in to_check:
e32ce18
        c_mtime = os.path.getmtime(c)
e32ce18
        if c_mtime < f_mtime:
e32ce18
            sys.stderr.write('Failed bytecompilation timestamps check: ')
e32ce18
            sys.stderr.write('Bytecode file {} is older than source file {}.\n'.format(c, f))
e32ce18
            failed += 1
e32ce18
e32ce18
if failed:
e32ce18
    sys.stderr.write('\n{} files failed bytecompilation timestamps check.\n'.format(failed))
e32ce18
    sys.exit(1)