<commit_before>#!/usr/bin/env python

import os
import shutil
import hashlib

base_path = os.path.dirname(__file__)

def same_cython(f0, f1):
    '''Compare two Cython generated C-files, based on their md5-sum.

    Returns True if the files are identical, False if not.  The first
    lines are skipped, due to the timestamp printed there.

    '''
    def md5sum(f):
        m = hashlib.new('md5')
        while True:
            d = f.read(8096)
            if not d:
                break
            m.update(d)
        return m.hexdigest()

    f0 = file(f0)
    f0.readline()

    f1 = file(f1)
    f1.readline()

    return md5sum(f0) == md5sum(f1)


def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs

    config = Configuration('opencv', parent_package, top_path)

    config.add_data_dir('tests')

    # since distutils/cython has problems, we'll check to see if cython is
    # installed and use that to rebuild the .c files, if not, we'll just build
    # directly from the included .c files

    cython_files = ['opencv_backend.pyx', 'opencv_cv.pyx']

    try:
        import Cython
        for pyxfile in [os.path.join(base_path, f) for f in cython_files]:
            # make a backup of the good c files
            c_file = pyxfile.rstrip('pyx') + 'c'
            c_file_new = c_file + '.new'

            # run cython compiler
            os.system('cython -o %s %s' % (c_file_new, pyxfile))

            # if the resulting file is small, cython compilation failed
            size = os.path.getsize(c_file_new)
            if size < 100:
                print "Cython compilation of %s failed. Using " \
                      "pre-generated file." % os.path.basename(pyxfile)
                continue

            # if the generated .c file differs from the one provided,
            # use that one instead
            if not same_cython(c_file_new, c_file):
                shutil.cp(c_file_new, c_file)

    except ImportError:
        # if cython is not found, we just build from the included .c files
        pass<commit_msg>Fixed shutil.cp -> shutil.copy; the former doesn't exist on python2.6<commit_after>#!/usr/bin/env python

import os
import shutil
import hashlib

base_path = os.path.dirname(__file__)

def same_cython(f0, f1):
    '''Compare two Cython generated C-files, based on their md5-sum.

    Returns True if the files are identical, False if not.  The first
    lines are skipped, due to the timestamp printed there.

    '''
    def md5sum(f):
        m = hashlib.new('md5')
        while True:
            d = f.read(8096)
            if not d:
                break
            m.update(d)
        return m.hexdigest()

    f0 = file(f0)
    f0.readline()

    f1 = file(f1)
    f1.readline()

    return md5sum(f0) == md5sum(f1)


def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs

    config = Configuration('opencv', parent_package, top_path)

    config.add_data_dir('tests')

    # since distutils/cython has problems, we'll check to see if cython is
    # installed and use that to rebuild the .c files, if not, we'll just build
    # directly from the included .c files

    cython_files = ['opencv_backend.pyx', 'opencv_cv.pyx']

    try:
        import Cython
        for pyxfile in [os.path.join(base_path, f) for f in cython_files]:
            # make a backup of the good c files
            c_file = pyxfile.rstrip('pyx') + 'c'
            c_file_new = c_file + '.new'

            # run cython compiler
            os.system('cython -o %s %s' % (c_file_new, pyxfile))

            # if the resulting file is small, cython compilation failed
            size = os.path.getsize(c_file_new)
            if size < 100:
                print "Cython compilation of %s failed. Using " \
                      "pre-generated file." % os.path.basename(pyxfile)
                continue

            # if the generated .c file differs from the one provided,
            # use that one instead
            if not same_cython(c_file_new, c_file):
                shutil.copy(c_file_new, c_file)

    except ImportError:
        # if cython is not found, we just build from the included .c files
        pass
{'fraction_non_alphanumeric': 0.08962482630847615, 'fraction_numerical': 0.010653080129689671, 'mean_word_length': 2.125180897250362, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2987538', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1324, 'n_words': 427}