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

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