|
1 | | -import sys |
| 1 | +"""import sys |
2 | 2 | from setuptools import setup, Extension |
3 | 3 | from setuptools.command.build_ext import build_ext |
4 | 4 | import os |
|
40 | 40 | ext_modules = cythonize([ext]) if use_cython else [ext] |
41 | 41 |
|
42 | 42 | setup(ext_modules=ext_modules) |
| 43 | +""" |
| 44 | +import sys |
| 45 | +from setuptools import setup, find_packages, Extension |
| 46 | + |
| 47 | +try: |
| 48 | + from Cython.Build import cythonize |
| 49 | +except ImportError: |
| 50 | + use_cython = False |
| 51 | +else: |
| 52 | + use_cython = True |
| 53 | + |
| 54 | +on_mac = sys.platform.startswith('darwin') |
| 55 | +on_windows = sys.platform.startswith('win') |
| 56 | + |
| 57 | +MOD_NAME = 'brute_force_cython_ext' |
| 58 | +MOD_PATH = 'imagededup/handlers/search/brute_force_cython_ext' |
| 59 | +COMPILE_LINK_ARGS = ['-O3', '-march=native', '-mtune=native'] |
| 60 | +# On Mac, use libc++ because Apple deprecated use of libstdc |
| 61 | +COMPILE_ARGS_OSX = ['-stdlib=libc++'] |
| 62 | +LINK_ARGS_OSX = ['-lc++', '-nodefaultlibs'] |
| 63 | + |
| 64 | +ext_modules = [] |
| 65 | +if use_cython and on_mac: |
| 66 | + ext_modules += cythonize([ |
| 67 | + Extension( |
| 68 | + MOD_NAME, |
| 69 | + [MOD_PATH + '.pyx'], |
| 70 | + language='c++', |
| 71 | + extra_compile_args=COMPILE_LINK_ARGS + COMPILE_ARGS_OSX, |
| 72 | + extra_link_args=COMPILE_LINK_ARGS + LINK_ARGS_OSX, |
| 73 | + ) |
| 74 | + ]) |
| 75 | +elif use_cython and on_windows: |
| 76 | + ext_modules += cythonize([ |
| 77 | + Extension( |
| 78 | + MOD_NAME, |
| 79 | + [MOD_PATH + '.pyx'], |
| 80 | + language='c++', |
| 81 | + ) |
| 82 | + ]) |
| 83 | +elif use_cython: |
| 84 | + ext_modules += cythonize([ |
| 85 | + Extension( |
| 86 | + MOD_NAME, |
| 87 | + [MOD_PATH + '.pyx'], |
| 88 | + language='c++', |
| 89 | + extra_compile_args=COMPILE_LINK_ARGS, |
| 90 | + extra_link_args=COMPILE_LINK_ARGS, |
| 91 | + ) |
| 92 | + ]) |
| 93 | +else: |
| 94 | + if on_mac: |
| 95 | + ext_modules += [Extension(MOD_NAME, |
| 96 | + [MOD_PATH + '.cpp'], |
| 97 | + extra_compile_args=COMPILE_ARGS_OSX, |
| 98 | + extra_link_args=LINK_ARGS_OSX, |
| 99 | + ) |
| 100 | + ] |
| 101 | + else: |
| 102 | + ext_modules += [Extension(MOD_NAME, |
| 103 | + [MOD_PATH + '.cpp'], |
| 104 | + ) |
| 105 | + ] |
0 commit comments