-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
182 lines (145 loc) · 5.56 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Originally by Gerhard Häring, zlib license
# https://github.com/ghaering/pysqlite
# Modified by Charles Leifer
# https://github.com/coleifer/pysqlite3
# Modified by Anton Zhiyanov
# https://github.com/nalgeon/sqlean.py
# Modified by Shahriar Nasim Nafi
# https://github.com/GreentechApps/sqlite3_arabic_tokenizer.py
# SQLite Python wrapper bundled with Sqlean extensions.
import logging
import os
from pathlib import Path
import setuptools
import sys
from setuptools.command.build_ext import build_ext
from setuptools import Extension
log = logging.getLogger(__name__)
PACKAGE_NAME = "sqlite3_arabic_tokenizer"
ARABIC_TOKENIZER_VERSION = "0.0.1"
VERSION = "3.46.0"
SHORT_DESCRIPTION = "sqlite3_arabic_tokenizer with custom sqlite3"
LONG_DESCRIPTION = Path("README.md").read_text()
# Module sources
sources = [
os.path.join("src", source)
for source in [
"module.c",
"connection.c",
"cursor.c",
"cache.c",
"microprotocols.c",
"prepare_protocol.c",
"statement.c",
"util.c",
"row.c",
"blob.c",
]
]
# Packages
packages = [PACKAGE_NAME]
# Work around clang raising hard error for unused arguments
if sys.platform == "darwin":
os.environ["CFLAGS"] = "-Qunused-arguments"
log.info("CFLAGS: " + os.environ["CFLAGS"])
def quote_argument(arg):
q = '\\"' if sys.platform == "win32" and sys.version_info < (3, 7) else '"'
return q + arg + q
define_macros = [("MODULE_NAME", quote_argument(PACKAGE_NAME + ".dbapi2"))]
class Builder(build_ext):
description = "Builds a C extension using a sqlite3 amalgamation"
amalgamation_root = "sqlite"
def build_extension(self, ext):
log.info(self.description)
# gcc optimization level
ext.extra_compile_args.append("-O1")
self._setup_defines(ext)
self._setup_sources(ext)
if sys.platform != "win32":
# Include math library, required for fts5.
ext.extra_link_args.append("-lm")
build_ext.build_extension(self, ext)
def _setup_defines(self, ext):
# sqlite options
features = (
"ENABLE_DBPAGE_VTAB",
"ENABLE_DBSTAT_VTAB",
"ENABLE_EXPLAIN_COMMENTS",
"ENABLE_FTS4",
"ENABLE_FTS5",
"ENABLE_GEOPOLY",
"ENABLE_JSON1",
"ENABLE_MATH_FUNCTIONS",
"ENABLE_RTREE",
"ENABLE_STAT4",
"ENABLE_STMTVTAB",
"LIKE_DOESNT_MATCH_BLOBS",
"USE_URI",
)
for feature in features:
ext.define_macros.append(("SQLITE_%s" % feature, "1"))
# Always use memory for temp store.
ext.define_macros.append(("SQLITE_TEMP_STORE", "3"))
# Increase the maximum number of "host parameters" which SQLite will accept
ext.define_macros.append(("SQLITE_MAX_VARIABLE_NUMBER", "250000"))
# Increase maximum allowed memory-map size to 1TB
ext.define_macros.append(("SQLITE_MAX_MMAP_SIZE", str(2**40)))
# Auto-load sqlite3_arabic_tokenizer extensions
ext.define_macros.append(("SQLITE_EXTRA_INIT", "core_init"))
ext.define_macros.append(("PACKAGE_VERSION", quote_argument(ARABIC_TOKENIZER_VERSION)))
# Extension-specific flags
ext.define_macros.append(("PCRE2_CODE_UNIT_WIDTH", "8"))
ext.define_macros.append(("LINK_SIZE", "2"))
ext.define_macros.append(("HAVE_CONFIG_H", "1"))
ext.define_macros.append(("SUPPORT_UNICODE", "1"))
if sys.platform == "win32":
ext.define_macros.append(("BYTE_ORDER", "LITTLE_ENDIAN"))
ext.define_macros.append(("PCRE2_STATIC", "1"))
def _setup_sources(self, ext):
ext.include_dirs.append(self.amalgamation_root)
ext.sources.append(os.path.join(self.amalgamation_root, "sqlite3.c"))
ext.sources.append(os.path.join(self.amalgamation_root, "sqlite3-arabic-tokenizer.c"))
ext.sources.append(os.path.join("src", "arabic_tokenizer.c"))
def __setattr__(self, k, v):
# Make sure we don't link against the SQLite
# library, no matter what setup.cfg says
if k == "libraries":
v = None
self.__dict__[k] = v
def get_setup_args():
return dict(
name=f"{PACKAGE_NAME}",
version=ARABIC_TOKENIZER_VERSION,
description=SHORT_DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
author="Shahriar Nasim Nafi",
author_email="[email protected]",
license="zlib/libpng",
platforms="ALL",
url="https://github.com/GreentechApps/sqlite3_arabic_tokenizer.py",
package_dir={PACKAGE_NAME: PACKAGE_NAME},
packages=packages,
ext_modules=[
Extension(
name=f"{PACKAGE_NAME}._sqlite3",
sources=sources,
define_macros=define_macros,
)
],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: zlib/libpng License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: C",
"Programming Language :: Python",
"Topic :: Database :: Database Engines/Servers",
"Topic :: Software Development :: Libraries :: Python Modules",
],
cmdclass={"build_ext": Builder},
)
if __name__ == "__main__":
setuptools.setup(**get_setup_args())