churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Clone

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

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