2020-02-29 17:17:00 +00:00
|
|
|
from setuptools import setup, Extension
|
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
import sys
|
2021-08-31 22:09:36 +00:00
|
|
|
import os
|
2021-09-10 10:44:54 +00:00
|
|
|
import numpy as np
|
2021-08-31 22:09:36 +00:00
|
|
|
|
|
|
|
# use with export RAPIDFUZZ_TRACE=1
|
|
|
|
RAPIDFUZZ_TRACE = os.environ.get("RAPIDFUZZ_TRACE", False)
|
2020-02-29 17:17:00 +00:00
|
|
|
|
|
|
|
class BuildExt(build_ext):
|
|
|
|
"""A custom build extension for adding compiler-specific options."""
|
|
|
|
c_opts = {
|
2021-09-26 14:36:05 +00:00
|
|
|
'msvc': ['/EHsc', '/std:c++14', '/O2', '/W4', '/DNDEBUG'],
|
|
|
|
'unix': ['-O3', '-std=c++14', '-Wextra', '-Wall', '-Wconversion', '-g0', '-DNDEBUG'],
|
2020-02-29 17:17:00 +00:00
|
|
|
}
|
|
|
|
l_opts = {
|
|
|
|
'msvc': [],
|
|
|
|
'unix': [],
|
|
|
|
}
|
|
|
|
|
2021-08-31 22:09:36 +00:00
|
|
|
if RAPIDFUZZ_TRACE:
|
|
|
|
c_opts['msvc'].append("/DCYTHON_TRACE_NOGIL=1")
|
|
|
|
c_opts['unix'].append("-DCYTHON_TRACE_NOGIL=1")
|
|
|
|
|
2020-02-29 17:17:00 +00:00
|
|
|
if sys.platform == 'darwin':
|
2020-04-03 12:38:34 +00:00
|
|
|
darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.9']
|
2020-02-29 17:17:00 +00:00
|
|
|
c_opts['unix'] += darwin_opts
|
|
|
|
l_opts['unix'] += darwin_opts
|
2021-09-26 14:36:05 +00:00
|
|
|
else:
|
|
|
|
linux_opts = ['-pthread']
|
|
|
|
c_opts['unix'] += linux_opts
|
|
|
|
l_opts['unix'] += linux_opts
|
2020-02-29 17:17:00 +00:00
|
|
|
|
|
|
|
def build_extensions(self):
|
|
|
|
ct = self.compiler.compiler_type
|
|
|
|
opts = self.c_opts.get(ct, [])
|
|
|
|
link_opts = self.l_opts.get(ct, [])
|
|
|
|
if ct == 'unix':
|
|
|
|
opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version())
|
|
|
|
elif ct == 'msvc':
|
|
|
|
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
|
|
|
|
for ext in self.extensions:
|
2021-03-03 14:20:31 +00:00
|
|
|
ext.extra_compile_args += opts
|
|
|
|
ext.extra_link_args += link_opts
|
2020-02-29 17:17:00 +00:00
|
|
|
build_ext.build_extensions(self)
|
|
|
|
|
2021-03-06 21:52:18 +00:00
|
|
|
ext_modules = [
|
|
|
|
Extension(
|
2021-05-23 20:09:03 +00:00
|
|
|
name='rapidfuzz.cpp_process',
|
2021-03-06 21:52:18 +00:00
|
|
|
sources=[
|
2021-11-05 19:49:01 +00:00
|
|
|
'src/cpp_process.cpp'
|
2021-09-15 01:50:30 +00:00
|
|
|
],
|
2021-11-06 16:25:39 +00:00
|
|
|
include_dirs=["extern/rapidfuzz-cpp/", "capi/"],
|
2021-09-15 01:50:30 +00:00
|
|
|
language='c++',
|
|
|
|
),
|
|
|
|
Extension(
|
|
|
|
name='rapidfuzz.cpp_process_cdist',
|
|
|
|
sources=[
|
2021-11-05 19:49:01 +00:00
|
|
|
'src/cpp_process_cdist.cpp'
|
2021-03-06 21:52:18 +00:00
|
|
|
],
|
2021-11-06 16:25:39 +00:00
|
|
|
include_dirs=["extern/rapidfuzz-cpp/", "capi/", "extern/taskflow/", np.get_include()],
|
2021-03-06 21:52:18 +00:00
|
|
|
language='c++',
|
|
|
|
),
|
|
|
|
Extension(
|
|
|
|
name='rapidfuzz.cpp_fuzz',
|
|
|
|
sources=[
|
2021-11-07 03:54:12 +00:00
|
|
|
'src/cpp_fuzz.cpp',
|
|
|
|
'extern/rapidfuzz-cpp/rapidfuzz/details/unicode.cpp'
|
2021-03-06 21:52:18 +00:00
|
|
|
],
|
2021-11-06 16:25:39 +00:00
|
|
|
include_dirs=["extern/rapidfuzz-cpp/", "capi/"],
|
2021-03-06 21:52:18 +00:00
|
|
|
language='c++',
|
|
|
|
),
|
|
|
|
Extension(
|
|
|
|
name='rapidfuzz.cpp_string_metric',
|
|
|
|
sources=[
|
2021-11-05 15:28:55 +00:00
|
|
|
'src/cpp_string_metric.cpp'
|
2021-03-06 21:52:18 +00:00
|
|
|
],
|
2021-11-06 16:25:39 +00:00
|
|
|
include_dirs=["extern/rapidfuzz-cpp/", "capi/"],
|
2021-03-06 21:52:18 +00:00
|
|
|
language='c++',
|
|
|
|
),
|
|
|
|
Extension(
|
|
|
|
name='rapidfuzz.cpp_utils',
|
|
|
|
sources=[
|
|
|
|
'src/cpp_utils.cpp',
|
2021-11-06 16:25:39 +00:00
|
|
|
'extern/rapidfuzz-cpp/rapidfuzz/details/unicode.cpp'
|
2021-03-06 21:52:18 +00:00
|
|
|
],
|
2021-11-06 16:25:39 +00:00
|
|
|
include_dirs=["extern/rapidfuzz-cpp/", "capi/"],
|
2021-03-06 21:52:18 +00:00
|
|
|
language='c++',
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
setup(
|
|
|
|
cmdclass={'build_ext': BuildExt},
|
|
|
|
ext_modules = ext_modules
|
2021-03-10 12:54:39 +00:00
|
|
|
)
|