-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.py
85 lines (77 loc) · 2.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
from setuptools import setup, Extension
from Cython.Build import cythonize
import subprocess
import sys
srilm_option = ""
copy_args = sys.argv[1:]
if "--srilm-option" in copy_args:
ind = copy_args.index("--srilm-option")
copy_args.pop(ind)
val = copy_args.pop(ind)
srilm_option = "" if val == "null" else val
machine_type = (
subprocess.check_output(["/bin/bash", "../sbin/machine-type"])
.strip()
.decode("ascii")
)
lib_path = machine_type + srilm_option
lib_dirs = []
compile_args = None
link_args = None
if machine_type == "i686-m64":
compile_args = ["-fopenmp"]
link_args = ["-fopenmp"]
elif machine_type == "macosx":
lib_dirs = ["/usr/lib", "/usr/local/lib"]
compact_def_macros = [("USE_SARRAY", 1), ("USE_SARRAY_TRIE", 1), ("USE_SARRAY_MAP2", 1)]
if srilm_option == "_c":
def_macros = compact_def_macros
elif srilm_option == "_s":
def_macros = compact_def_macros + [("USE_SHORT_VOCAB", 1), ("USE_XCOUNTS", 1)]
elif srilm_option == "_l":
def_macros = compact_def_macros + [("USE_LONGLONG_COUNTS", 1), ("USE_XCOUNTS", 1)]
else:
def_macros = []
module_dict = {
"vocab": ["srilm/vocab.pyx"],
"stats": ["srilm/stats.pyx"],
"discount": ["srilm/discount.pyx"],
"base": ["srilm/base.pyx"],
"ngram": ["srilm/ngram.pyx"],
"maxent": ["srilm/maxent.pyx"],
"utils": ["srilm/utils.pyx"],
}
modules = []
for n, s in module_dict.items():
modules.append(
Extension(
name=n,
sources=s,
language="c++",
define_macros=[("HAVE_ZOPEN", "1")] + def_macros,
include_dirs=["../include"],
libraries=["lbfgs", "iconv"],
library_dirs=["../lib/%s" % lib_path] + lib_dirs,
extra_compile_args=compile_args,
extra_link_args=link_args,
extra_objects=[
"../lib/%s/liboolm.a" % lib_path,
"../lib/%s/libdstruct.a" % lib_path,
"../lib/%s/libmisc.a" % lib_path,
"../lib/%s/libz.a" % lib_path,
],
cython_directives={"embedsignature": True},
)
)
setup(
name="srilm",
version="3.0.0",
description="Python binding for SRI Language Modeling Toolkit implemented in Cython",
author="Yi Su",
author_email="[email protected]",
license="MIT",
packages=["srilm"],
ext_package="srilm",
ext_modules=cythonize(modules, annotate=True, language_level="3"),
script_args=copy_args,
)