-
Notifications
You must be signed in to change notification settings - Fork 70
/
setup.py
210 lines (186 loc) · 5.86 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import io
import os
import platform
import sys
from setuptools import setup, find_packages, Extension
with io.open("README.rst", mode="rt", encoding="utf-8") as readme_file:
readme = readme_file.read()
# Setup flags
USE_STATIC = False
USE_CYTHON = False
PLATFORM = "windows_nt" if platform.system() == "Windows" else "posix"
INCLUDE_LEXBOR = bool(os.environ.get("USE_LEXBOR", True))
ARCH = platform.architecture()[0]
try:
from Cython.Build import cythonize
HAS_CYTHON = True
USE_CYTHON = True
except ImportError as err:
HAS_CYTHON = False
if "--static" in sys.argv:
USE_STATIC = True
sys.argv.remove("--static")
if "--lexbor" in sys.argv:
INCLUDE_LEXBOR = True
sys.argv.remove("--lexbor")
if "--cython" in sys.argv:
if HAS_CYTHON:
USE_CYTHON = True
else:
raise ImportError("No module named 'Cython'")
sys.argv.remove("--cython")
# If there are no pretranspiled source files
if HAS_CYTHON and not os.path.exists("selectolax/parser.c"):
USE_CYTHON = True
COMPILER_DIRECTIVES = {
"language_level": 3,
"embedsignature": True,
"annotation_typing": False,
"emit_code_comments": True,
"boundscheck": False,
"wraparound": False,
}
def find_modest_files(modest_path="modest/source"):
c_files = []
if os.path.exists(modest_path):
for root, dirs, files in os.walk(modest_path):
for file in files:
if file.endswith(".c"):
file_path = os.path.join(root, file)
# Filter platform specific files
if (file_path.find("myport") >= 0) and (
not file_path.find(PLATFORM) >= 0
):
continue
if INCLUDE_LEXBOR:
if (file_path.find("ports") >= 0) and (
not file_path.find(PLATFORM) >= 0
):
continue
c_files.append(file_path)
return c_files
def make_extensions():
files_to_compile_lxb = []
extra_objects_lxb, extra_objects = [], []
if USE_CYTHON:
files_to_compile = [
"selectolax/parser.pyx",
]
if INCLUDE_LEXBOR:
files_to_compile_lxb = [
"selectolax/lexbor.pyx",
]
else:
files_to_compile = ["selectolax/parser.c"]
if INCLUDE_LEXBOR:
files_to_compile_lxb = [
"selectolax/lexbor.c",
]
if USE_STATIC:
extra_objects = ["modest/lib/libmodest_static.a"]
if INCLUDE_LEXBOR:
extra_objects_lxb = ["lexbor/liblexbor_static.a"]
else:
files_to_compile.extend(find_modest_files("modest/source"))
if INCLUDE_LEXBOR:
files_to_compile_lxb.extend(find_modest_files("lexbor/source"))
compile_arguments_lxb = [
"-DLEXBOR_STATIC",
]
compile_arguments = [
"-DMODEST_BUILD_OS=%s" % platform.system(),
"-DMyCORE_OS_%s" % platform.system(),
"-DMODEST_PORT_NAME=%s" % PLATFORM,
"-DMyCORE_BUILD_WITHOUT_THREADS=YES",
"-DMyCORE_BUILD_DEBUG=NO",
]
if PLATFORM == "posix":
args = [
"-pedantic",
"-fPIC",
"-Wno-unused-variable",
"-Wno-unused-function",
"-std=c99",
"-O2",
]
compile_arguments.extend(args)
compile_arguments_lxb.extend(args)
elif PLATFORM == "windows_nt":
compile_arguments_lxb.extend(
[
"-D_WIN64" if ARCH == "64bit" else "-D_WIN32",
]
)
extensions = [
Extension(
"selectolax.parser",
files_to_compile,
language="c",
include_dirs=[
"modest/include/",
],
extra_objects=extra_objects,
extra_compile_args=compile_arguments,
),
]
if INCLUDE_LEXBOR:
extensions.append(
Extension(
"selectolax.lexbor",
files_to_compile_lxb,
language="c",
include_dirs=[
"lexbor/source/",
],
extra_objects=extra_objects_lxb,
extra_compile_args=compile_arguments_lxb,
)
)
if USE_CYTHON:
extensions = cythonize(extensions, compiler_directives=COMPILER_DIRECTIVES)
return extensions
setup(
name="selectolax",
version='0.3.26',
description="Fast HTML5 parser with CSS selectors.",
long_description=readme,
author="Artem Golubin",
author_email="[email protected]",
url="https://github.com/rushter/selectolax",
packages=find_packages(include=["selectolax"]),
package_data={"selectolax": ["py.typed"]},
include_package_data=True,
extras_require={
"cython": "Cython==3.0.11",
},
license="MIT license",
zip_safe=False,
keywords="selectolax",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Topic :: Text Processing :: Markup :: HTML",
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
],
test_suite="tests",
tests_require=[
"pytest",
],
project_urls={
"Source code": "https://github.com/rushter/selectolax",
},
ext_modules=make_extensions(),
)