-
Notifications
You must be signed in to change notification settings - Fork 26
/
setup.py
136 lines (122 loc) · 4.44 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
import os
import sys
from setuptools import setup, find_packages, Extension
from find_library import pkgconfig
from collections import defaultdict
VERSION = '1.2.1'
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
BUILD_ARGS = defaultdict(lambda: ['-O3', '-g0'])
for compiler, args in [
('msvc', ['/EHsc', '/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
python_2 = sys.version_info[0] == 2
def read(fname):
with open(fname, 'rU' if python_2 else 'r') as fhandle:
return fhandle.read()
def pandoc_read_md(fname):
if 'PANDOC_PATH' not in os.environ:
raise ImportError("No pandoc path to use")
import pandoc
pandoc.core.PANDOC_PATH = os.environ['PANDOC_PATH']
doc = pandoc.Document()
doc.markdown = read(fname)
return doc.rst
def pypandoc_read_md(fname):
import pypandoc
os.environ.setdefault('PYPANDOC_PANDOC', os.environ['PANDOC_PATH'])
return pypandoc.convert_text(read(fname), 'rst', format='md')
def read_md(fname):
# Utility function to read the README file.
full_fname = os.path.join(os.path.dirname(__file__), fname)
try:
return pandoc_read_md(full_fname)
except (ImportError, AttributeError):
try:
return pypandoc_read_md(full_fname)
except (ImportError, AttributeError):
return read(fname)
else:
return read(fname)
profiling = '--profile' in sys.argv or '-p' in sys.argv
linetrace = '--linetrace' in sys.argv or '-l' in sys.argv
building = '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', '*.lib', '*hpp']
packages = find_packages(exclude=['*.tests', '*.tests.*', 'tests.*', 'tests'])
packages.extend(['dictionaries', 'libs.msvc'])
required = [req.strip() for req in read('requirements.txt').splitlines() if req.strip()]
package_data = {'' : datatypes}
if building:
if (profiling or linetrace) and not force_rebuild:
print("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('hunspell', language='c++')
)
], force=force_rebuild)
else:
from setuptools.command.build_ext import build_ext
ext_modules = [
Extension(
'hunspell.hunspell',
[os.path.join('hunspell', 'hunspell.cpp')],
**pkgconfig('hunspell', language='c++')
)
]
package_data["hunspell"] = ["*.pxd"]
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)
setup(
name='CyHunspell',
version=VERSION,
author='Matthew Seal',
author_email='[email protected]',
description='A wrapper on hunspell for use in Python',
long_description=read_md('README.md'),
ext_modules=ext_modules,
install_requires=required,
cmdclass={ 'build_ext': build_ext_compiler_check },
license='MIT + MPL 1.1/GPL 2.0/LGPL 2.1',
packages=packages,
scripts=['find_library.py', 'tar_download.py'],
test_suite='tests',
zip_safe=False,
url='https://github.com/OpenGov/cython_hunspell',
download_url='https://github.com/OpenGov/cython_hunspell/tarball/v' + VERSION,
package_data=package_data,
keywords=['hunspell', 'spelling', 'correction'],
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Utilities',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3'
]
)