<commit_before>try:
    # python3 vs. python2
    import configparser
except ImportError:
    import ConfigParser as configparser
import logging
import numpy.distutils.system_info as numpy_sys
import numpy
import os
import sys

logger = logging.getLogger('pythran')


def init_cfg(sys_file, platform_file, user_file):
    sys_config_dir = os.path.dirname(__file__)
    sys_config_path = os.path.join(sys_config_dir, sys_file)

    platform_config_path = os.path.join(sys_config_dir, platform_file)

    user_config_dir = os.environ.get('XDG_CONFIG_HOME', '~')
    user_config_path = os.path.expanduser(
        os.path.join(user_config_dir, user_file))

    cfgp = configparser.SafeConfigParser()
    for required in (sys_config_path, platform_config_path):
        cfgp.readfp(open(required))
    cfgp.read([user_config_path])

    for key in ('CC', 'CXX'):
        value = cfgp.get('compiler', key)
        if value:
            os.environ[key] = str(value)

    for obsolete_section in ('user', 'sys'):
        if cfgp.has_section(obsolete_section):
            logger.warn("Your pythranrc has an obsolete `%s' section",
                        obsolete_section)

    return cfgp


def make_extension(**extra):
    def parse_define(define):
        index = define.find('=')
        if index < 0:
            return (define, None)
        else:
            return define[:index], define[index + 1:]
    extension = {
        # forcing str conversion to handle Unicode case (the default on MS)
        "define_macros": [str(x) for x in
                          cfg.get('compiler', 'defines').split()],
        "undef_macros": [str(x) for x in
                         cfg.get('compiler', 'undefs').split()],
        "include_dirs": [str(x) for x in
                         cfg.get('compiler', 'include_dirs').split()],
        "library_dirs": [str(x) for x in
                         cfg.get('compiler', 'library_dirs').split()],
        "libraries": [str(x) for x in
                      cfg.get('compiler', 'libs').split()],
        "extra_compile_args": [str(x) for x in
                               cfg.get('compiler', 'cflags').split()],
        "extra_link_args": [str(x) for x in
                            cfg.get('compiler', 'ldflags').split()],
    }

    extension['define_macros'].append('ENABLE_PYTHON_MODULE')
    extension['define_macros'].append(
        '__PYTHRAN__={}'.format(sys.version_info.major))

    here = os.path.dirname(os.path.dirname(__file__)) or '.'
    # using / as separator as advised in the distutils doc
    extension["include_dirs"].append(here + '/pythran')
    for k, w in extra.items():
        extension[k].extend(w)
    if cfg.getboolean('pythran', 'complex_hook'):
        # the patch is *not* portable
        extension["include_dirs"].append(here + '/pythran/pythonic/patch')

    # numpy specific
    extension['include_dirs'].append(numpy.get_include())

    # blas dependency
    user_blas = cfg.get('compiler', 'blas')
    numpy_blas = numpy_sys.get_info(user_blas)
    # required to cope with atlas missing ectern "C"
    extension['define_macros'].append('PYTHRAN_BLAS_{}'
                                      .format(user_blas.upper()))
    extension['libraries'].extend(numpy_blas.get('libraries', []))
    extension['library_dirs'].extend(numpy_blas.get('library_dirs', []))
    extension['include_dirs'].extend(numpy_blas.get('include_dirs', []))

    # final macro normalization<commit_msg>Avoid numpy polution of stdout<commit_after>try:
    # python3 vs. python2
    import configparser
except ImportError:
    import ConfigParser as configparser
import logging
import numpy.distutils.system_info as numpy_sys
import numpy
import os
import sys

logger = logging.getLogger('pythran')


def init_cfg(sys_file, platform_file, user_file):
    sys_config_dir = os.path.dirname(__file__)
    sys_config_path = os.path.join(sys_config_dir, sys_file)

    platform_config_path = os.path.join(sys_config_dir, platform_file)

    user_config_dir = os.environ.get('XDG_CONFIG_HOME', '~')
    user_config_path = os.path.expanduser(
        os.path.join(user_config_dir, user_file))

    cfgp = configparser.SafeConfigParser()
    for required in (sys_config_path, platform_config_path):
        cfgp.readfp(open(required))
    cfgp.read([user_config_path])

    for key in ('CC', 'CXX'):
        value = cfgp.get('compiler', key)
        if value:
            os.environ[key] = str(value)

    for obsolete_section in ('user', 'sys'):
        if cfgp.has_section(obsolete_section):
            logger.warn("Your pythranrc has an obsolete `%s' section",
                        obsolete_section)

    return cfgp


def make_extension(**extra):
    def parse_define(define):
        index = define.find('=')
        if index < 0:
            return (define, None)
        else:
            return define[:index], define[index + 1:]
    extension = {
        # forcing str conversion to handle Unicode case (the default on MS)
        "define_macros": [str(x) for x in
                          cfg.get('compiler', 'defines').split()],
        "undef_macros": [str(x) for x in
                         cfg.get('compiler', 'undefs').split()],
        "include_dirs": [str(x) for x in
                         cfg.get('compiler', 'include_dirs').split()],
        "library_dirs": [str(x) for x in
                         cfg.get('compiler', 'library_dirs').split()],
        "libraries": [str(x) for x in
                      cfg.get('compiler', 'libs').split()],
        "extra_compile_args": [str(x) for x in
                               cfg.get('compiler', 'cflags').split()],
        "extra_link_args": [str(x) for x in
                            cfg.get('compiler', 'ldflags').split()],
    }

    extension['define_macros'].append('ENABLE_PYTHON_MODULE')
    extension['define_macros'].append(
        '__PYTHRAN__={}'.format(sys.version_info.major))

    here = os.path.dirname(os.path.dirname(__file__)) or '.'
    # using / as separator as advised in the distutils doc
    extension["include_dirs"].append(here + '/pythran')
    for k, w in extra.items():
        extension[k].extend(w)
    if cfg.getboolean('pythran', 'complex_hook'):
        # the patch is *not* portable
        extension["include_dirs"].append(here + '/pythran/pythonic/patch')

    # Numpy can poluate the stdout with warning message which should be on stderr
    old_stdout = sys.stdout
    try:
        sys.stdout = sys.stderr

        # numpy specific
        extension['include_dirs'].append(numpy.get_include())

        # blas dependency
        user_blas = cfg.get('compiler', 'blas')
        numpy_blas = numpy_sys.get_info(user_blas)
        # required to cope with atlas missing ectern "C"
        extension['define_macros'].append('PYTHRAN_BLAS_{}'
                                          .format(user_blas.upper()))
        extension['libraries'].extend(numpy_blas.get('libraries', []))
        extension['library_dirs'].extend(numpy_blas.get('library_dirs', []))
        extension['include_dirs'].extend(numpy_blas.get('include_dirs', []))
    finally:
        sys.stdout = old_stdout

    # final macro normalization
{'fraction_non_alphanumeric': 0.13082287308228732, 'fraction_numerical': 0.0011157601115760112, 'mean_word_length': 2.634566649771921, 'pattern_counts': {'":': 14, '<': 5, '<?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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '719557', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2171, 'n_words': 462}