<commit_before>import re



MAP = {
    'VERSION':                    'NPY_DUMMY',
    'HAVE_LONG_LONG_INT':         'NPY_HAVE_LONGLONG',
    'SIZEOF_LONG_DOUBLE':         'NPY_SIZEOF_LONGDOUBLE',
    'SIZEOF_LONG_LONG':           'NPY_SIZEOF_LONGLONG',
    'SIZEOF_VOID_P':              'NPY_SIZEOF_PTR',
    'SIZEOF_FLOAT_COMPLEX':       'NPY_SIZEOF_COMPLEX_FLOAT',
    'SIZEOF_DOUBLE_COMPLEX':      'NPY_SIZEOF_COMPLEX_DOUBLE',
    'SIZEOF_LONG_DOUBLE_COMPLEX': 'NPY_SIZEOF_COMPLEX_LONGDOUBLE',
}


def define_repl(match):
    name = match.group(2)

    if name in MAP:
        name = MAP[name]
    else:
        name = 'NPY_' + name

    assert name.startswith('NPY_')
    return match.group(1) + name + match.group(3)


def rename_defs(data):
    p = re.compile(r'^(#\s*define\s+)([A-Z0-9_]+)(\s+\S+)$', re.M)
    return p.sub(define_repl, data)


if __name__ == '__main__':
    src = 'config.h'
    dst = 'src/npy_config.h'

    print "\treading:", src
    data = open(src).read()

    data = '''\
/* npy_config.h   Generated from config.h by tools/mk_config.py */
''' + rename_defs(data)

    print "\twriting:", dst
    fo = open(dst, 'w')
    fo.write(data)
    fo.close()<commit_msg>create main() for config tool<commit_after>import re



MAP = {
    'VERSION':                    'DUMMY_VERSION',
    'HAVE_LONG_LONG_INT':         'NPY_HAVE_LONGLONG',
    'SIZEOF_LONG_DOUBLE':         'NPY_SIZEOF_LONGDOUBLE',
    'SIZEOF_LONG_LONG':           'NPY_SIZEOF_LONGLONG',
    'SIZEOF_VOID_P':              'NPY_SIZEOF_PTR',
    'SIZEOF_FLOAT_COMPLEX':       'NPY_SIZEOF_COMPLEX_FLOAT',
    'SIZEOF_DOUBLE_COMPLEX':      'NPY_SIZEOF_COMPLEX_DOUBLE',
    'SIZEOF_LONG_DOUBLE_COMPLEX': 'NPY_SIZEOF_COMPLEX_LONGDOUBLE',
}

def define_repl(match):
    name = match.group(2)
    if name in MAP:
        name = MAP[name]
    else:
        name = 'NPY_' + name
    return match.group(1) + name + match.group(3)

def rename_defs(data):
    p = re.compile(r'^(#\s*define\s+)([A-Z0-9_]+)(\s+\S+)$', re.M)
    return p.sub(define_repl, data)



def main():
    src = 'config.h'
    dst = 'src/npy_config.h'

    print "\treading:", src
    data = open(src).read()

    data = '''\
/* npy_config.h   Generated from config.h by tools/mk_config.py */
''' + rename_defs(data)

    print "\twriting:", dst
    fo = open(dst, 'w')
    fo.write(data)
    fo.close()


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.1521103217718345, 'fraction_numerical': 0.004178854993731718, 'mean_word_length': 2.717391304347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2242162', 'n_tokens_mistral': 981, 'n_tokens_neox': 954, 'n_words': 154}