RapidFuzz/setup.py

102 lines
3.0 KiB
Python
Raw Normal View History

2020-02-29 17:17:00 +00:00
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import sys
import os
2021-09-10 10:44:54 +00:00
import numpy as np
# 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': [],
}
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':
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=[
'src/cpp_process.cpp',
'src/rapidfuzz-cpp/rapidfuzz/details/unicode.cpp'
2021-09-15 01:50:30 +00:00
],
2021-10-23 18:25:13 +00:00
include_dirs=["src/rapidfuzz-cpp/", "capi/"],
2021-09-15 01:50:30 +00:00
language='c++',
),
Extension(
name='rapidfuzz.cpp_process_cdist',
sources=[
'src/cpp_process_cdist.cpp',
'src/rapidfuzz-cpp/rapidfuzz/details/unicode.cpp'
2021-03-06 21:52:18 +00:00
],
2021-10-23 18:25:13 +00:00
include_dirs=["src/rapidfuzz-cpp/", "capi/", "3rd-party/taskflow/", np.get_include()],
2021-03-06 21:52:18 +00:00
language='c++',
),
Extension(
name='rapidfuzz.cpp_fuzz',
sources=[
'src/cpp_fuzz.cpp',
'src/rapidfuzz-cpp/rapidfuzz/details/unicode.cpp'
],
2021-10-23 18:25:13 +00:00
include_dirs=["src/rapidfuzz-cpp/", "capi/"],
2021-03-06 21:52:18 +00:00
language='c++',
),
Extension(
name='rapidfuzz.cpp_string_metric',
sources=[
'src/cpp_string_metric.cpp',
'src/rapidfuzz-cpp/rapidfuzz/details/unicode.cpp'
],
2021-10-23 18:25:13 +00:00
include_dirs=["src/rapidfuzz-cpp/", "capi/"],
2021-03-06 21:52:18 +00:00
language='c++',
),
Extension(
name='rapidfuzz.cpp_utils',
sources=[
'src/cpp_utils.cpp',
'src/rapidfuzz-cpp/rapidfuzz/details/unicode.cpp'
],
2021-10-23 18:25:13 +00:00
include_dirs=["src/rapidfuzz-cpp/", "capi/"],
2021-03-06 21:52:18 +00:00
language='c++',
)
]
2021-10-23 18:25:13 +00:00
2021-03-06 21:52:18 +00:00
if __name__ == "__main__":
setup(
cmdclass={'build_ext': BuildExt},
ext_modules = ext_modules
)