torsava / rpms / python3

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