Path: blob/master/python/cython/setup_parallel.py
2574 views
# usually the name should only be setup.py1# on the terminal run2# python setup_parallel.py install3import os4import sys5import glob6import numpy as np7from setuptools import Extension, setup8try:9from Cython.Build import cythonize10use_cython = True11except ImportError:12use_cython = False1314# top-level information15NAME = 'pairwise3'16VERSION = '0.0.1'17USE_OPENMP = True181920def set_gcc(use_openmp):21"""22Try to find and use GCC on OSX for OpenMP support2324References25----------26https://github.com/maciejkula/glove-python/blob/master/setup.py27"""28# For macports and homebrew29patterns = ['/opt/local/bin/gcc-mp-[0-9].[0-9]',30'/opt/local/bin/gcc-mp-[0-9]',31'/usr/local/bin/gcc-[0-9].[0-9]',32'/usr/local/bin/gcc-[0-9]']3334if 'darwin' in sys.platform.lower():35gcc_binaries = []36for pattern in patterns:37gcc_binaries += glob.glob(pattern)3839gcc_binaries.sort()4041if gcc_binaries:42_, gcc = os.path.split(gcc_binaries[-1])43os.environ['CC'] = gcc4445else:46use_openmp = False4748return use_openmp495051def define_extensions(use_cython, use_openmp):52"""53boilerplate to compile the extension the only thing that we need to54worry about is the modules part, where we define the extension that55needs to be compiled56"""57if sys.platform.startswith('win'):58# compile args from59# https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx60link_args = []61compile_args = ['/O2', '/openmp']62else:63link_args = []64compile_args = ['-Wno-unused-function', '-Wno-maybe-uninitialized', '-O3', '-ffast-math']65if use_openmp:66compile_args.append('-fopenmp')67link_args.append('-fopenmp')6869if 'anaconda' not in sys.version.lower():70compile_args.append('-march=native')7172# recommended approach is that the user can choose not to73# compile the code using cython, they can instead just use74# the .c file that's also distributed75# http://cython.readthedocs.io/en/latest/src/reference/compilation.html#distributing-cython-modules76src_ext = '.pyx' if use_cython else '.c'77names = ['pairwise3']78modules = [Extension(name,79[os.path.join(name + src_ext)],80extra_compile_args = compile_args,81extra_link_args = link_args) for name in names]8283if use_cython:84return cythonize(modules)85else:86return modules878889USE_OPENMP = set_gcc(USE_OPENMP)90setup(91name = NAME,92version = VERSION,93description = 'pairwise distance quickstart',94ext_modules = define_extensions(use_cython, USE_OPENMP),95include_dirs = [np.get_include()]96)979899