<commit_before># Author:  <NAME>
# Contact: <EMAIL>

"""
Support for building mpi4py with distutils.
"""

# -----------------------------------------------------------------------------

import sys
if sys.version[:3] == '3.0':
    from distutils import version
    version.cmp = lambda a, b : (a > b) - (a < b)
    del version
del sys

# -----------------------------------------------------------------------------

import sys, os, platform, re
from distutils import sysconfig
from distutils.util  import convert_path
from distutils.util  import split_quoted
from distutils.spawn import find_executable
from distutils import log

def fix_config_vars(names, values):
    values = list(values)
    if sys.platform == 'darwin':
        if 'ARCHFLAGS' in os.environ:
            ARCHFLAGS = os.environ['ARCHFLAGS']
            for i, flag in enumerate(list(values)):
                flag, count = re.subn('-arch\s+\w+', ' ', flag)
                if count and ARCHFLAGS:
                    flag = flag + ' ' + ARCHFLAGS
                values[i] = flag
        if 'SDKROOT' in os.environ:
            SDKROOT = os.environ['SDKROOT']
            for i, flag in enumerate(list(values)):
                flag, count = re.subn('-isysroot [^ \t]*', ' ', flag)
                if count and SDKROOT:
                    flag = flag + ' ' + '-isysroot ' + SDKROOT
                values[i] = flag
    return values

def get_config_vars(*names):
    # Core Python configuration
    values = sysconfig.get_config_vars(*names)
    # Do any distutils flags fixup right now
    values = fix_config_vars(names, values)
    return values

def fix_compiler_cmd(mpicc, pycc):
    if not pycc:  return mpicc
    if not mpicc: return pycc
    pycc = split_quoted(pycc)
    i = 0
    if os.path.basename(pycc[0]) == 'env':
        i = 1
        while '=' in pycc[i]:
            i = i + 1
    pycc[i] = mpicc
    mpicc   = ' '.join(pycc)
    return mpicc

def fix_linker_cmd(mpild, pyld):
    if not pyld:  return mpild
    if not mpild: return pyld
    aix_fixup = (sys.platform.startswith('aix') and
                 'ld_so_aix' in pyld)
    pyld = split_quoted(pyld)
    i = 0
    if os.path.basename(pyld[0]) == 'env':
        i = 1
        while '=' in pyld[i]:
            i = i + 1
    if aix_fixup:
        i = i + 1
    pyld[i] = mpild
    mpild   = ' '.join(pyld)
    return mpild

from distutils.unixccompiler import UnixCCompiler
rpath_option_orig = UnixCCompiler.runtime_library_dir_option
def rpath_option(compiler, dir):
    option = rpath_option_orig(compiler, dir)
    if sys.platform.startswith('linux'):
        if option.startswith('-R'):
            option =  option.replace('-R', '-Wl,-rpath,', 1)
        elif option.startswith('-Wl,-R,'):
            option =  option.replace('-Wl,-R,', '-Wl,-rpath,', 1)
    return option
UnixCCompiler.runtime_library_dir_option = rpath_option

def customize_compiler(compiler, lang=None,
                       mpicc=None, mpicxx=None, mpild=None,
                       environ=None):
    if environ is None:
        environ = os.environ
    if compiler.compiler_type == 'unix':
        # Distutils configuration, actually obtained by parsing
        # :file:{prefix}/lib[32|64]/python{X}.{Y}/config/Makefile
        (cc, cxx, ccshared,
         basecflags, optcflags,
         ld_so, so_ext) = \
         get_config_vars('CC', 'CXX', 'CCSHARED',
                         'BASECFLAGS', 'OPT',
                         'LDSHARED', 'SO')
        cc    = cc    .replace('-pthread', '')
        cxx   = cxx   .replace('-pthread', '')
        ld_so = ld_so .replace('-pthread', '')
        cppflags = ''
        cflags   = ''
        cxxflags = ''
        ldflags  = ''
        # Compiler command overriding
        if mpicc:
            cc  = fix_compiler_cmd(mpicc,  cc)
        if mpicxx:
            cxx = fix_compiler_cmd(mpicxx, cxx)
        if mpild:
            ld_so = fix_linker_cmd(mpild,  ld_so)
        elif (mpicc or mpicxx):
            if lang == 'c':
                mpild = mpicc
            elif lang == 'c++':
                mpild = mpicxx
            else:
                mpild = mpicc or mpicxx
            ld_so = fix_linker_cmd(mpild, ld_so)
        # Environment handling
        CPPFLAGS = environ.get('CPPFLAGS', '')
        CFLAGS   = environ.get('CFLAGS',   '')
        CXXFLAGS = environ.get('CXXFLAGS', '')
        LDFLAGS  = environ.get('LDFLAGS',  '')
        if CPPFLAGS:
            cppflags = cppflags + ' ' + CPPFLAGS
            cflags   = cflags   + ' ' + CPPFLAGS
            cxxflags = cxxflags + ' ' + CPPFLAGS
            ldflags  = ldflags  + ' ' + CPPFLAGS
        if CFLAGS:
            cflags   = cflags   + ' ' + CFLAGS
            ldflags  = ldflags  + ' ' + CFLAGS
        if CXXFLAGS:
            cxxflags = cxxflags + ' ' + CXXFLAGS
            ldflags  = ldflags  + ' ' + CXXFLAGS
        if LDFLAGS:
            ldflags  = ldflags  + ' ' + LDFLAGS
        ccshared   = environ.get('CCSHARED',   ccshared   or '')
        basecflags = environ.get('BASECFLAGS', basecflags or '')
        optcflags  = environ.get('OPTCFLAGS',  optcflags  or '')
        cflags     = (basecflags + ' ' +
                      optcflags  + ' ' +
                      cflags)
        cxxflags   = (basecflags + ' ' +
                      optcflags  + ' ' +
                      cxxflags)
        cxxflags = cxxflags.replace('-Wstrict-prototypes', '')
        # Distutils compiler setup
        cpp    = os.environ.get('CPP') or (cc + ' -E')
        cc_so  = cc  + ' ' + ccshared
        cxx_so = cxx + ' ' + ccshared
        ld_exe = mpild or cc
        compiler.set_executables(
            preprocessor = cpp    + ' ' + cppflags,
            compiler     = cc     + ' ' + cflags,
            compiler_so  = cc_so  + ' ' + cflags,
            compiler_cxx = cxx_so + ' ' + cxxflags,
            linker_so    = ld_so  + ' ' + ldflags,
            linker_exe   = ld_exe + ' ' + ldflags,
            )
        try: compiler.compiler_cxx.remove('-Wstrict-prototypes')
        except: pass
    if compiler.compiler_type == 'mingw32':
        compiler.set_executables(
            preprocessor = 'gcc -mno-cygwin -E',
            )
    if compiler.compiler_type in ('unix', 'cygwin', 'mingw32'):
        if lang == 'c++':
            def find_cmd_pos(cmd):
                pos = 0
                if os.path.basename(cmd[pos]) == "env":
                    pos = 1
                    while '=' in cmd[pos]:
                        pos = pos + 1
                return pos
            i = find_cmd_pos(compiler.compiler_so)
            j = find_cmd_pos(compiler.compiler_cxx)
            compiler.compiler_so[i] = compiler.compiler_cxx[j]
            try: compiler.compiler_so.remove('-Wstrict-prototypes')
            except: pass

# -----------------------------------------------------------------------------

try:
    from mpiconfig import Config
except ImportError:
    from conf.mpiconfig import Config

def configuration(command_obj, verbose=True):
    config = Config()
    config.setup(command_obj)
    if verbose:
        if config.section and config.filename:
            log.info("MPI configuration: [%s] from '%s'",<commit_msg>Windows: tentative fix for building with Windows SDK 7.1<commit_after># Author:  <NAME>
# Contact: <EMAIL>

"""
Support for building mpi4py with distutils.
"""

# -----------------------------------------------------------------------------

import sys
if sys.version[:3] == '3.0':
    from distutils import version
    version.cmp = lambda a, b : (a > b) - (a < b)
    del version
del sys

# -----------------------------------------------------------------------------

import sys, os, platform, re
from distutils import sysconfig
from distutils.util  import convert_path
from distutils.util  import split_quoted
from distutils.spawn import find_executable
from distutils import log

def fix_config_vars(names, values):
    values = list(values)
    if sys.platform == 'darwin':
        if 'ARCHFLAGS' in os.environ:
            ARCHFLAGS = os.environ['ARCHFLAGS']
            for i, flag in enumerate(list(values)):
                flag, count = re.subn('-arch\s+\w+', ' ', flag)
                if count and ARCHFLAGS:
                    flag = flag + ' ' + ARCHFLAGS
                values[i] = flag
        if 'SDKROOT' in os.environ:
            SDKROOT = os.environ['SDKROOT']
            for i, flag in enumerate(list(values)):
                flag, count = re.subn('-isysroot [^ \t]*', ' ', flag)
                if count and SDKROOT:
                    flag = flag + ' ' + '-isysroot ' + SDKROOT
                values[i] = flag
    return values

def get_config_vars(*names):
    # Core Python configuration
    values = sysconfig.get_config_vars(*names)
    # Do any distutils flags fixup right now
    values = fix_config_vars(names, values)
    return values

def fix_compiler_cmd(mpicc, pycc):
    if not pycc:  return mpicc
    if not mpicc: return pycc
    pycc = split_quoted(pycc)
    i = 0
    if os.path.basename(pycc[0]) == 'env':
        i = 1
        while '=' in pycc[i]:
            i = i + 1
    pycc[i] = mpicc
    mpicc   = ' '.join(pycc)
    return mpicc

def fix_linker_cmd(mpild, pyld):
    if not pyld:  return mpild
    if not mpild: return pyld
    aix_fixup = (sys.platform.startswith('aix') and
                 'ld_so_aix' in pyld)
    pyld = split_quoted(pyld)
    i = 0
    if os.path.basename(pyld[0]) == 'env':
        i = 1
        while '=' in pyld[i]:
            i = i + 1
    if aix_fixup:
        i = i + 1
    pyld[i] = mpild
    mpild   = ' '.join(pyld)
    return mpild

from distutils.unixccompiler import UnixCCompiler
rpath_option_orig = UnixCCompiler.runtime_library_dir_option
def rpath_option(compiler, dir):
    option = rpath_option_orig(compiler, dir)
    if sys.platform.startswith('linux'):
        if option.startswith('-R'):
            option =  option.replace('-R', '-Wl,-rpath,', 1)
        elif option.startswith('-Wl,-R,'):
            option =  option.replace('-Wl,-R,', '-Wl,-rpath,', 1)
    return option
UnixCCompiler.runtime_library_dir_option = rpath_option

def customize_compiler(compiler, lang=None,
                       mpicc=None, mpicxx=None, mpild=None,
                       environ=None):
    if environ is None:
        environ = os.environ
    if compiler.compiler_type == 'unix':
        # Distutils configuration, actually obtained by parsing
        # :file:{prefix}/lib[32|64]/python{X}.{Y}/config/Makefile
        (cc, cxx, ccshared,
         basecflags, optcflags,
         ld_so, so_ext) = \
         get_config_vars('CC', 'CXX', 'CCSHARED',
                         'BASECFLAGS', 'OPT',
                         'LDSHARED', 'SO')
        cc    = cc    .replace('-pthread', '')
        cxx   = cxx   .replace('-pthread', '')
        ld_so = ld_so .replace('-pthread', '')
        cppflags = ''
        cflags   = ''
        cxxflags = ''
        ldflags  = ''
        # Compiler command overriding
        if mpicc:
            cc  = fix_compiler_cmd(mpicc,  cc)
        if mpicxx:
            cxx = fix_compiler_cmd(mpicxx, cxx)
        if mpild:
            ld_so = fix_linker_cmd(mpild,  ld_so)
        elif (mpicc or mpicxx):
            if lang == 'c':
                mpild = mpicc
            elif lang == 'c++':
                mpild = mpicxx
            else:
                mpild = mpicc or mpicxx
            ld_so = fix_linker_cmd(mpild, ld_so)
        # Environment handling
        CPPFLAGS = environ.get('CPPFLAGS', '')
        CFLAGS   = environ.get('CFLAGS',   '')
        CXXFLAGS = environ.get('CXXFLAGS', '')
        LDFLAGS  = environ.get('LDFLAGS',  '')
        if CPPFLAGS:
            cppflags = cppflags + ' ' + CPPFLAGS
            cflags   = cflags   + ' ' + CPPFLAGS
            cxxflags = cxxflags + ' ' + CPPFLAGS
            ldflags  = ldflags  + ' ' + CPPFLAGS
        if CFLAGS:
            cflags   = cflags   + ' ' + CFLAGS
            ldflags  = ldflags  + ' ' + CFLAGS
        if CXXFLAGS:
            cxxflags = cxxflags + ' ' + CXXFLAGS
            ldflags  = ldflags  + ' ' + CXXFLAGS
        if LDFLAGS:
            ldflags  = ldflags  + ' ' + LDFLAGS
        ccshared   = environ.get('CCSHARED',   ccshared   or '')
        basecflags = environ.get('BASECFLAGS', basecflags or '')
        optcflags  = environ.get('OPTCFLAGS',  optcflags  or '')
        cflags     = (basecflags + ' ' +
                      optcflags  + ' ' +
                      cflags)
        cxxflags   = (basecflags + ' ' +
                      optcflags  + ' ' +
                      cxxflags)
        cxxflags = cxxflags.replace('-Wstrict-prototypes', '')
        # Distutils compiler setup
        cpp    = os.environ.get('CPP') or (cc + ' -E')
        cc_so  = cc  + ' ' + ccshared
        cxx_so = cxx + ' ' + ccshared
        ld_exe = mpild or cc
        compiler.set_executables(
            preprocessor = cpp    + ' ' + cppflags,
            compiler     = cc     + ' ' + cflags,
            compiler_so  = cc_so  + ' ' + cflags,
            compiler_cxx = cxx_so + ' ' + cxxflags,
            linker_so    = ld_so  + ' ' + ldflags,
            linker_exe   = ld_exe + ' ' + ldflags,
            )
        try: compiler.compiler_cxx.remove('-Wstrict-prototypes')
        except: pass
    if compiler.compiler_type == 'mingw32':
        compiler.set_executables(
            preprocessor = 'gcc -mno-cygwin -E',
            )
    if compiler.compiler_type in ('unix', 'cygwin', 'mingw32'):
        if lang == 'c++':
            def find_cmd_pos(cmd):
                pos = 0
                if os.path.basename(cmd[pos]) == "env":
                    pos = 1
                    while '=' in cmd[pos]:
                        pos = pos + 1
                return pos
            i = find_cmd_pos(compiler.compiler_so)
            j = find_cmd_pos(compiler.compiler_cxx)
            compiler.compiler_so[i] = compiler.compiler_cxx[j]
            try: compiler.compiler_so.remove('-Wstrict-prototypes')
            except: pass
    if compiler.compiler_type == 'msvc':
        if not compiler.initialized:
            compiler.initialize()
        compiler.ldflags_shared.append('/MANIFEST')
        compiler.ldflags_shared_debug.append('/MANIFEST')

# -----------------------------------------------------------------------------

try:
    from mpiconfig import Config
except ImportError:
    from conf.mpiconfig import Config

def configuration(command_obj, verbose=True):
    config = Config()
    config.setup(command_obj)
    if verbose:
        if config.section and config.filename:
            log.info("MPI configuration: [%s] from '%s'",
{'fraction_non_alphanumeric': 0.14408338442673208, 'fraction_numerical': 0.003678724708767627, 'mean_word_length': 1.6181558765828428, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '7088976', 'n_tokens_mistral': 4694, 'n_tokens_neox': 4547, 'n_words': 1046}