forked from tmikus/pycld2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·130 lines (120 loc) · 4.35 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import io
from os import path
import platform
import re
import setuptools
HERE = path.abspath(path.dirname(__file__))
CLD2_PATH = path.join(HERE, "cld2")
BIND_PATH = path.join(HERE, "bindings")
# See internal/compile_libs.sh for some detail. Note that this is *not*
# simply internal/*.cc. Issue #23: keep these relative for manifest.
src_files = [
path.join("cld2/internal/", i)
for i in (
"cld2_generated_cjk_compatible.cc",
"cld2_generated_deltaocta0122.cc",
"cld2_generated_distinctocta0122.cc",
"cld2_generated_quad0122.cc",
"cld_generated_cjk_delta_bi_32.cc",
"cld_generated_cjk_uni_prop_80.cc",
"cld_generated_score_quad_octa_0122.cc",
"cldutil.cc",
"cldutil_shared.cc",
"compact_lang_det.cc",
"compact_lang_det_hint_code.cc",
"compact_lang_det_impl.cc",
"debug.cc",
"fixunicodevalue.cc",
"generated_distinct_bi_0.cc",
"generated_entities.cc",
"generated_language.cc",
"generated_ulscript.cc",
"getonescriptspan.cc",
"lang_script.cc",
"offsetmap.cc",
"scoreonescriptspan.cc",
"tote.cc",
"utf8statetable.cc",
)
]
src_files.extend(
["bindings/pycldmodule.cc", "bindings/encodings.cc"]
)
for i in src_files:
if not path.exists(i):
raise RuntimeError("Missing source file: %s" % i)
include_dirs = [path.join(CLD2_PATH, "internal"), path.join(CLD2_PATH, "public")]
compile_args = ["-w", "-O2", "-fPIC"]
if platform.machine() == 'x86_64':
compile_args.append('-m64')
elif platform.machine() == 'aarch64' or platform.machine() == 'arm64':
compile_args.append('-march=armv8-a')
module = setuptools.Extension(
# First arg (name) is the full name of the extension, including
# any packages - ie. not a filename or pathname, but Python dotted
# name.
"pycld2._pycld2",
sources=src_files,
include_dirs=include_dirs,
language="c++",
# TODO: -m64 may break 32 bit builds
extra_compile_args=compile_args,
)
# We define version as PYCLD2_VERSION in the C++ module.
# Note: we could also use `define_macros` arg to setup()
VERSION = re.search(
r'^#define\s+PYCLD2_VERSION\s+"([^"]+)"$',
io.open(path.join(BIND_PATH, "pycldmodule.cc"), encoding="utf-8").read(),
re.M,
).group(1)
if __name__ == "__main__":
setuptools.setup(
name="pycld2-chatbees-fork",
version=VERSION,
author="ChatBees",
author_email="build@chatbees.ai",
maintainer="Chat Bees",
maintainer_email="build@chatbees.ai",
description="Python bindings around Google Chromium's embedded compact language detection library (CLD2)",
long_description=io.open(
path.join(HERE, "README.md"),
encoding="utf-8"
).read(),
long_description_content_type="text/markdown",
license="Apache2",
url="https://github.com/aboSamoor/pycld2",
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: C++",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Topic :: Text Processing :: Linguistic",
],
packages=["pycld2"],
ext_modules=[module],
)