forked from OpenGov/cython_hunspell
-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup.py
142 lines (127 loc) · 4.94 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import os
import sys
import glob
import shutil
import platform
from warnings import warn
from setuptools import setup, find_packages, Extension
from distutils.command.build import build
from build_hunspell import pkgconfig, repair_darwin_link_dep_path
from collections import defaultdict
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
class bdist_wheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
# Mark us as not a pure python package
self.root_is_pure = False
except ImportError:
print("Could not register bdist_wheel. Make sure the wheel package is installed!")
bdist_wheel = None
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
BUILD_ARGS = defaultdict(lambda: ['-O3', '-g0'])
for compiler, args in [
('msvc', ['/EHsc', '/MD', '/DHUNSPELL_STATIC']),
('gcc', ['-O3', '-g0', '-DHUNSPELL_STATIC'])]:
BUILD_ARGS[compiler] = args
def cleanup_pycs():
file_tree = os.walk(os.path.join(BASE_DIR, 'hunspell'))
to_delete = []
for root, directory, file_list in file_tree:
if len(file_list):
for file_name in file_list:
if file_name.endswith(".pyc"):
to_delete.append(os.path.join(root, file_name))
for file_path in to_delete:
try:
os.remove(file_path)
except:
pass
def read(fname):
with open(fname, 'r') as fhandle:
return fhandle.read()
profiling = '--profile' in sys.argv or '-p' in sys.argv
linetrace = '--linetrace' in sys.argv or '-l' in sys.argv
building_ext = 'build_ext' in sys.argv
force_rebuild = '--force' in sys.argv or '-f' in sys.argv and building
datatypes = ['*.aff', '*.dic', '*.pxd', '*.pyx', '*.pyd', '*.pxd', '*.so', '*.so.*', '*.dylib', '*.dylib.*', '*.lib', '*.hpp', '*.cpp']
packages = find_packages(exclude=['*.tests', '*.tests.*', 'tests.*', 'tests'])
packages.append('hunspell.dictionaries')
required = [req.strip() for req in read('requirements.txt').splitlines() if req.strip()]
required_dev = [req.strip() for req in read('requirements-dev.txt').splitlines() if req.strip()]
required_test = [req.strip() for req in read('requirements-test.txt').splitlines() if req.strip()]
package_data = {'' : datatypes}
if building_ext:
if (profiling or linetrace) and not force_rebuild:
warn("WARNING: profiling or linetracing specified without forced rebuild")
from Cython.Build import cythonize
from Cython.Distutils import build_ext
ext_modules = cythonize([
Extension(
'hunspell.hunspell',
[os.path.join('hunspell', 'hunspell.pyx')],
**pkgconfig()
)
], force=force_rebuild, compiler_directives={'language_level' : "3"})
else:
from setuptools.command.build_ext import build_ext
ext_modules = [
Extension(
'hunspell.hunspell',
[os.path.join('hunspell', 'hunspell.cpp')],
**pkgconfig()
)
]
class build_ext_compiler_check(build_ext):
def build_extensions(self):
compiler = self.compiler.compiler_type
args = BUILD_ARGS[compiler]
for ext in self.extensions:
ext.extra_compile_args = args
build_ext.build_extensions(self)
def run(self):
cleanup_pycs()
build_ext.run(self)
class build_darwin_fix(build):
def run(self):
build.run(self)
# OSX build a shared dependency with an absolute path to the hunspell dylib. This fixes that
if platform.system() == 'Darwin':
repair_darwin_link_dep_path()
def version():
with open(os.path.join(BASE_DIR, 'hunspell', '_version.py'), 'r') as ver:
for line in ver.readlines():
if line.startswith('__version__ ='):
return line.split(' = ')[-1].strip()[1:-1]
raise ValueError('No version found in hunspell/_version.py')
setup(
name='cyhunspell',
version=version(),
author='Matthew Seal',
author_email='[email protected]',
description='A wrapper on hunspell for use in Python',
long_description=read(os.path.join(BASE_DIR, 'README.md')),
long_description_content_type='text/markdown',
ext_modules=ext_modules,
install_requires=required,
cmdclass={ 'build_ext': build_ext_compiler_check, 'build': build_darwin_fix, 'bdist_wheel': bdist_wheel },
extras_require={
'dev': required_dev,
'test': required_test,
},
license='MIT + MPL 1.1/GPL 2.0/LGPL 2.1',
packages=packages,
test_suite='tests',
zip_safe=False,
url='https://github.com/MSeal/cython_hunspell',
download_url='https://github.com/MSeal/cython_hunspell/tarball/v' + version(),
package_data=package_data,
keywords=['hunspell', 'spelling', 'correction'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Topic :: Utilities',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3'
]
)