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

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