|
a |
|
b/setup.py |
|
|
1 |
#!/usr/bin/env python |
|
|
2 |
from distutils.sysconfig import get_python_inc |
|
|
3 |
|
|
|
4 |
import numpy |
|
|
5 |
from setuptools import Extension, setup |
|
|
6 |
|
|
|
7 |
# See if Cython is installed |
|
|
8 |
try: |
|
|
9 |
from Cython.Build import cythonize |
|
|
10 |
from Cython.Distutils import build_ext |
|
|
11 |
except ImportError: |
|
|
12 |
# Do nothing if Cython is not available |
|
|
13 |
# Got to provide this function. Otherwise, poetry will fail |
|
|
14 |
print("You must install Cython to build this library") |
|
|
15 |
else: |
|
|
16 |
# Cython is installed. Compile |
|
|
17 |
print("Compiling") |
|
|
18 |
|
|
|
19 |
COMPILER_DIRECTIVES = { |
|
|
20 |
"language_level": "3", |
|
|
21 |
} |
|
|
22 |
MOD_NAMES = [ |
|
|
23 |
"edsnlp.matchers.phrase", |
|
|
24 |
"edsnlp.pipes.core.sentences.fast_sentences", |
|
|
25 |
] |
|
|
26 |
|
|
|
27 |
include_dirs = [ |
|
|
28 |
numpy.get_include(), |
|
|
29 |
get_python_inc(plat_specific=True), |
|
|
30 |
] |
|
|
31 |
ext_modules = [] |
|
|
32 |
for name in MOD_NAMES: |
|
|
33 |
mod_path = name.replace(".", "/") + ".pyx" |
|
|
34 |
ext = Extension( |
|
|
35 |
name, |
|
|
36 |
[mod_path], |
|
|
37 |
language="c++", |
|
|
38 |
include_dirs=include_dirs, |
|
|
39 |
extra_compile_args=["-std=c++11"], |
|
|
40 |
) |
|
|
41 |
ext_modules.append(ext) |
|
|
42 |
print("Cythonizing sources") |
|
|
43 |
ext_modules = cythonize(ext_modules, compiler_directives=COMPILER_DIRECTIVES) |
|
|
44 |
|
|
|
45 |
setup( |
|
|
46 |
ext_modules=ext_modules, |
|
|
47 |
package_data={ |
|
|
48 |
"": ["*.dylib", "*.so"], |
|
|
49 |
}, |
|
|
50 |
cmdclass={"build_ext": build_ext}, |
|
|
51 |
) |