2020-02-29 17:17:00 +00:00
|
|
|
from setuptools import setup, Extension
|
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
import sys
|
|
|
|
import setuptools
|
|
|
|
|
2020-03-18 20:34:32 +00:00
|
|
|
from os import path
|
|
|
|
this_dir = path.abspath(path.dirname(__file__))
|
|
|
|
with open(path.join(this_dir, "VERSION"), encoding='utf-8') as version_file:
|
2020-02-29 17:17:00 +00:00
|
|
|
version = version_file.read().strip()
|
|
|
|
|
|
|
|
|
2020-03-18 20:34:32 +00:00
|
|
|
with open(path.join(this_dir, 'README.md'), encoding='utf-8') as f:
|
|
|
|
long_description = f.read()
|
|
|
|
|
|
|
|
|
2020-02-29 17:17:00 +00:00
|
|
|
class get_pybind_include(object):
|
|
|
|
"""Helper class to determine the pybind11 include path
|
|
|
|
|
|
|
|
The purpose of this class is to postpone importing pybind11
|
|
|
|
until it is actually installed, so that the ``get_include()``
|
|
|
|
method can be invoked. """
|
|
|
|
|
|
|
|
def __init__(self, user=False):
|
|
|
|
self.user = user
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
import pybind11
|
|
|
|
return pybind11.get_include(self.user)
|
|
|
|
|
|
|
|
|
|
|
|
ext_modules = [
|
|
|
|
Extension(
|
2020-03-18 23:48:47 +00:00
|
|
|
'_rapidfuzz_cpp',
|
2020-03-18 20:34:32 +00:00
|
|
|
[
|
|
|
|
'python/src/rapidfuzz.cpp',
|
|
|
|
'cpp/src/fuzz.cpp',
|
|
|
|
'cpp/src/process.cpp'
|
|
|
|
],
|
2020-02-29 17:17:00 +00:00
|
|
|
include_dirs=[
|
|
|
|
# Path to pybind11 headers
|
|
|
|
get_pybind_include(),
|
|
|
|
get_pybind_include(user=True),
|
2020-03-18 20:34:32 +00:00
|
|
|
"cpp/src"
|
2020-02-29 17:17:00 +00:00
|
|
|
],
|
2020-03-18 20:34:32 +00:00
|
|
|
language='c++',
|
2020-02-29 17:17:00 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# As of Python 3.6, CCompiler has a `has_flag` method.
|
|
|
|
# cf http://bugs.python.org/issue26689
|
|
|
|
def has_flag(compiler, flagname):
|
|
|
|
"""Return a boolean indicating whether a flag name is supported on
|
|
|
|
the specified compiler.
|
|
|
|
"""
|
|
|
|
import tempfile
|
|
|
|
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
|
|
|
|
f.write('int main (int argc, char **argv) { return 0; }')
|
|
|
|
try:
|
|
|
|
compiler.compile([f.name], extra_postargs=[flagname])
|
|
|
|
except setuptools.distutils.errors.CompileError:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class BuildExt(build_ext):
|
|
|
|
"""A custom build extension for adding compiler-specific options."""
|
|
|
|
c_opts = {
|
2020-03-22 22:12:51 +00:00
|
|
|
'msvc': ['/EHsc', '/O2', '/std:c++17'],
|
|
|
|
'unix': ['-O3', '-std=c++17'],
|
2020-02-29 17:17:00 +00:00
|
|
|
}
|
|
|
|
l_opts = {
|
|
|
|
'msvc': [],
|
|
|
|
'unix': [],
|
|
|
|
}
|
|
|
|
|
|
|
|
if sys.platform == 'darwin':
|
2020-03-22 22:12:51 +00:00
|
|
|
darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.14']
|
2020-02-29 17:17:00 +00:00
|
|
|
c_opts['unix'] += darwin_opts
|
|
|
|
l_opts['unix'] += darwin_opts
|
|
|
|
|
|
|
|
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())
|
|
|
|
if has_flag(self.compiler, '-fvisibility=hidden'):
|
|
|
|
opts.append('-fvisibility=hidden')
|
|
|
|
elif ct == 'msvc':
|
|
|
|
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
|
|
|
|
for ext in self.extensions:
|
|
|
|
ext.extra_compile_args = opts
|
|
|
|
ext.extra_link_args = link_opts
|
|
|
|
build_ext.build_extensions(self)
|
|
|
|
|
|
|
|
setup(
|
|
|
|
name='rapidfuzz',
|
|
|
|
version=version,
|
|
|
|
author='Max Bachmann',
|
|
|
|
author_email='contact@maxbachmann.de',
|
|
|
|
url='https://github.com/rhasspy/rapidfuzz',
|
2020-03-18 20:34:32 +00:00
|
|
|
description='rapid fuzzy string matching',
|
|
|
|
long_description=long_description,
|
|
|
|
long_description_content_type='text/markdown',
|
2020-02-29 17:17:00 +00:00
|
|
|
ext_modules=ext_modules,
|
|
|
|
install_requires=['pybind11>=2.4'],
|
|
|
|
setup_requires=['pybind11>=2.4'],
|
|
|
|
cmdclass={'build_ext': BuildExt},
|
2020-03-18 20:34:32 +00:00
|
|
|
package_data={'': ['LICENSE', 'VERSION']},
|
2020-03-18 23:48:47 +00:00
|
|
|
package_dir={'': 'python/src'},
|
|
|
|
packages=['rapidfuzz'],
|
2020-03-18 20:34:32 +00:00
|
|
|
include_package_data=True,
|
2020-02-29 17:17:00 +00:00
|
|
|
zip_safe=False,
|
2020-03-18 20:34:32 +00:00
|
|
|
classifiers=[
|
|
|
|
"Programming Language :: Python :: 3",
|
|
|
|
"Programming Language :: Python :: 3.5",
|
|
|
|
"Programming Language :: Python :: 3.6",
|
|
|
|
"Programming Language :: Python :: 3.7",
|
|
|
|
"Programming Language :: Python :: 3.8",
|
|
|
|
"License :: OSI Approved :: MIT License",
|
|
|
|
],
|
|
|
|
python_requires=">=3.5",
|
|
|
|
)
|