Example #1
0
def get_config():
    from setup_common import get_metadata_and_options, enabled, create_release_file

    interpreter_arch = get_build_architecture()
    machine_arch = platform.machine()
    metadata, options = get_metadata_and_options()

    connector = options.get('connector')
    if not connector and machine_arch == 'AMD64' and interpreter_arch == 'Intel':
        connector = 'C:\Program Files (x86)\MySQL\MySQL Connector C 6.1'
    elif not connector:
        connector = 'C:\Program Files\MySQL\MySQL Connector C 6.1'

    extra_objects = []

    client = "mysqlclient"
    # client = "mariadbclient"

    vcversion = int(get_build_version())
    if client == "mariadbclient":
        library_dirs = [os.path.join(connector, 'lib', 'mariadb')]
        libraries = [
            'kernel32', 'advapi32', 'wsock32', 'shlwapi', 'Ws2_32', client
        ]
        include_dirs = [os.path.join(connector, 'include', 'mariadb')]
    else:
        library_dirs = [
            os.path.join(connector, r'lib\vs%d' % vcversion),
            os.path.join(connector, "lib")
        ]
        libraries = ['kernel32', 'advapi32', 'wsock32', client]
        include_dirs = [os.path.join(connector, r'include')]

    extra_compile_args = ['/Zl', '/D_CRT_SECURE_NO_WARNINGS']
    extra_link_args = ['/MANIFEST']

    name = "mysqlclient"
    metadata['name'] = name

    define_macros = [
        ('version_info', metadata['version_info']),
        ('__version__', metadata['version']),
    ]
    create_release_file(metadata)
    del metadata['version_info']
    ext_options = dict(
        library_dirs=library_dirs,
        libraries=libraries,
        extra_compile_args=extra_compile_args,
        extra_link_args=extra_link_args,
        include_dirs=include_dirs,
        extra_objects=extra_objects,
        define_macros=define_macros,
    )
    return metadata, ext_options
Example #2
0
def lib_from_def(def_file, arch=None):
    if not arch:
        arch = get_build_architecture()
        if arch == 'Intel':
            arch = 'x86'
        elif arch == 'Itanium':
            arch = 'IA64'
        else:
            arch = 'x64'
    lib_file = '%s.lib' % os.path.splitext(def_file)[0]
    compiler.spawn([compiler.lib, '/nologo', '/MACHINE:%s' % arch,
                   '/DEF:%s' % def_file, '/OUT:%s' % lib_file])
Example #3
0
def lib_from_def(def_file, arch=None):
    if not arch:
        arch = get_build_architecture()
        if arch == 'Intel':
            arch = 'x86'
        elif arch == 'Itanium':
            arch = 'IA64'
        else:
            arch = 'x64'
    lib_file = f'{os.path.splitext(def_file)[0]}.lib'
    compiler.spawn([
        compiler.lib, '/nologo', f'/MACHINE:{arch}', f'/DEF:{def_file}',
        f'/OUT:{lib_file}'
    ])
Example #4
0
from distutils import msvccompiler as comp

print(comp.get_build_version())
print(comp.get_build_architecture())



Example #5
0
    def generate_config_h(ext, build_dir):
        target = join(build_dir, 'config.h')
        if newer(__file__, target):
            config_cmd = config.get_config_cmd()
            log.info('Generating %s', target)
            tc = generate_testcode(target)
            from distutils import sysconfig
            python_include = sysconfig.get_python_inc()
            python_h = join(python_include, 'Python.h')
            if not os.path.isfile(python_h):
                raise SystemError,\
                      "Non-existing %s. Perhaps you need to install"\
                      " python-dev|python-devel." % (python_h)
            result = config_cmd.try_run(tc,
                                        include_dirs=[python_include],
                                        library_dirs=default_lib_dirs)
            if not result:
                raise SystemError,"Failed to test configuration. "\
                      "See previous error messages for more information."

                # Python 2.3 causes a segfault when
                #  trying to re-acquire the thread-state
                #  which is done in error-handling
                #  ufunc code.  NPY_ALLOW_C_API and friends
                #  cause the segfault. So, we disable threading
                #  for now.
            if sys.version[:5] < '2.4.2':
                nosmp = 1
            else:
                # Perhaps a fancier check is in order here.
                #  so that threads are only enabled if there
                #  are actually multiple CPUS? -- but
                #  threaded code can be nice even on a single
                #  CPU so that long-calculating code doesn't
                #  block.
                try:
                    nosmp = os.environ['NPY_NOSMP']
                    nosmp = 1
                except KeyError:
                    nosmp = 0
            if nosmp: moredefs = [('NPY_ALLOW_THREADS', '0')]
            else: moredefs = []
            #
            mathlibs = []
            tc = testcode_mathlib()
            mathlibs_choices = [[], ['m'], ['cpml']]
            mathlib = os.environ.get('MATHLIB')
            if mathlib:
                mathlibs_choices.insert(0, mathlib.split(','))
            for libs in mathlibs_choices:
                if config_cmd.try_run(tc, libraries=libs):
                    mathlibs = libs
                    break
            else:
                raise EnvironmentError("math library missing; rerun "
                                       "setup.py after setting the "
                                       "MATHLIB env variable")
            ext.libraries.extend(mathlibs)
            moredefs.append(('MATHLIB', ','.join(mathlibs)))

            def check_func(func_name):
                return config_cmd.check_func(func_name,
                                             libraries=mathlibs,
                                             decl=False,
                                             headers=['math.h'])

            for func_name, defsymbol in FUNCTIONS_TO_CHECK:
                if check_func(func_name):
                    moredefs.append(defsymbol)

            if sys.platform == 'win32':
                moredefs.append('NPY_NO_SIGNAL')

            if sys.version[:3] > '2.4' and (sys.platform == 'win32'
                                            or os.name == 'nt'):
                from distutils.msvccompiler import get_build_architecture
                a = get_build_architecture()
                print 'BUILD_ARCHITECTURE: %r, os.name=%r, sys.platform=%r' % (
                    a, os.name, sys.platform)
                if a == 'AMD64':
                    moredefs.append('DISTUTILS_USE_SDK')

            if sys.version[:3] < '2.4':
                if config_cmd.check_func('strtod',
                                         decl=False,
                                         headers=['stdlib.h']):
                    moredefs.append(('PyOS_ascii_strtod', 'strtod'))

            target_f = open(target, 'a')
            for d in moredefs:
                if isinstance(d, str):
                    target_f.write('#define %s\n' % (d))
                else:
                    target_f.write('#define %s %s\n' % (d[0], d[1]))
            if not nosmp:  # default is to use WITH_THREAD
                target_f.write(
                    '#ifdef WITH_THREAD\n#define NPY_ALLOW_THREADS 1\n#else\n#define NPY_ALLOW_THREADS 0\n#endif\n'
                )
            target_f.close()
            print 'File:', target
            target_f = open(target)
            print target_f.read()
            target_f.close()
            print 'EOF'
        else:
            mathlibs = []
            target_f = open(target)
            for line in target_f.readlines():
                s = '#define MATHLIB'
                if line.startswith(s):
                    value = line[len(s):].strip()
                    if value:
                        mathlibs.extend(value.split(','))
            target_f.close()

        ext.libraries.extend(mathlibs)

        incl_dir = os.path.dirname(target)
        if incl_dir not in config.numpy_include_dirs:
            config.numpy_include_dirs.append(incl_dir)

        config.add_data_files((header_dir, target))
        return target