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

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