-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
229 lines (200 loc) Β· 8.16 KB
/
setup.py
File metadata and controls
229 lines (200 loc) Β· 8.16 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
"""Setup script for the Draken package.
This script handles the compilation and installation of the Draken Cython/Arrow
interoperability library. It:
- Configures Cython extensions for all vector types and core components
- Sets up platform-specific compilation flags and optimizations
- Manages dependencies and build requirements
- Configures SIMD support for optimal performance
The build process creates optimized Cython extensions that provide zero-copy
interoperability with Apache Arrow for high-performance columnar data processing.
"""
import os
import platform
import sys
from sysconfig import get_config_var
from Cython.Build import cythonize
from setuptools import Extension
from setuptools import find_packages
from setuptools import setup
def is_mac(): # pragma: no cover
return platform.system().lower() == "darwin"
def is_win(): # pragma: no cover
return platform.system().lower() == "windows"
REQUESTED_COMMANDS = {arg.lower() for arg in sys.argv[1:] if arg and not arg.startswith('-')}
SHOULD_BUILD_EXTENSIONS = "clean" not in REQUESTED_COMMANDS
if not SHOULD_BUILD_EXTENSIONS:
REQUESTED_DISPLAY = ", ".join(sorted(REQUESTED_COMMANDS)) or "<none>"
print(
f"\033[38;2;255;208;0mSkipping native extension build for command(s):\033[0m {REQUESTED_DISPLAY}"
)
if SHOULD_BUILD_EXTENSIONS:
LIBRARY = "draken"
machine = platform.machine().lower()
system = platform.system().lower()
CPP_COMPILE_FLAGS = ["-O3"]
C_COMPILE_FLAGS = ["-O3"]
if is_mac():
CPP_COMPILE_FLAGS += ["-std=c++17"]
elif is_win():
CPP_COMPILE_FLAGS += ["/std:c++17"]
else:
# Default to portable flags, then layer in AVX2 where the CPU family supports it.
CPP_COMPILE_FLAGS += ["-std=c++17", "-fvisibility=default"]
C_COMPILE_FLAGS += ["-fvisibility=default"]
if "x86" in machine or "amd64" in machine:
CPP_COMPILE_FLAGS.append("-mavx2")
C_COMPILE_FLAGS.append("-mavx2")
include_dirs = []
# Get the C++ include directory
includedir = get_config_var("INCLUDEDIR")
if includedir:
include_dirs.append(os.path.join(includedir, "c++", "v1"))
# Get the Python include directory
includepy = get_config_var("INCLUDEPY")
if includepy:
include_dirs.append(includepy)
# Check if paths exist
include_dirs = [p for p in include_dirs if os.path.exists(p)]
print("\033[38;2;255;85;85mInclude paths:\033[0m", include_dirs)
__author__ = "notset"
__version__ = "notset"
with open(f"{LIBRARY}/__version__.py", mode="r", encoding="UTF8") as v:
vers = v.read()
exec(vers) # nosec
RELEASE_CANDIDATE = "a" not in __version__ and "b" not in __version__
COMPILER_DIRECTIVES = {"language_level": "3"}
COMPILER_DIRECTIVES["profile"] = not RELEASE_CANDIDATE
COMPILER_DIRECTIVES["linetrace"] = not RELEASE_CANDIDATE
print(f"\033[38;2;255;85;85mBuilding Draken version:\033[0m {__version__}")
with open("README.md", mode="r", encoding="UTF8") as rm:
long_description = rm.read()
#try:
# with open("requirements.txt", "r") as f:
# required = f.read().splitlines()
#except:
# with open(f"{LIBRARY}.egg-info/requires.txt", "r") as f:
# required = f.read().splitlines()
extensions = [
Extension(
"draken.interop.arrow",
sources=["draken/interop/arrow.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=[
"draken/core/buffers.h",
"draken/interop/arrow_c_data_interface.h"
],
),
Extension(
name="draken.vectors.vector",
sources=["draken/vectors/vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.core.ops",
sources=["draken/core/ops.pyx", "draken/core/ops_impl.cpp"],
extra_compile_args=CPP_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h", "draken/core/ops.h"],
language="c++",
),
Extension(
name="draken.vectors.bool_vector",
sources=["draken/vectors/bool_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.vectors.float64_vector",
sources=["draken/vectors/float64_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.vectors.int64_vector",
sources=["draken/vectors/int64_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.vectors.string_vector",
sources=["draken/vectors/string_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.vectors.date32_vector",
sources=["draken/vectors/date32_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.vectors.timestamp_vector",
sources=["draken/vectors/timestamp_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.vectors.time_vector",
sources=["draken/vectors/time_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.vectors.array_vector",
sources=["draken/vectors/array_vector.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=["draken/core/buffers.h"],
),
Extension(
name="draken.morsels.morsel",
sources=["draken/morsels/morsel.pyx"],
extra_compile_args=C_COMPILE_FLAGS,
include_dirs=include_dirs + ["draken"],
depends=[
"draken/core/buffers.h"
"draken/morsels/morsel.h"
],
),
]
# Add SIMD support flags
# AVX2 flags are handled above for x86/AMD64 targets; add ARM NEON support where reasonable.
if machine.startswith("arm") and not machine.startswith("aarch64") and system != "darwin":
# ARM32 NEON is generally safe as baseline
CPP_COMPILE_FLAGS.append("-mfpu=neon")
setup_config = {
"name": LIBRARY,
"version": __version__,
"description": "Cython compatibility layer for Arrow",
"long_description": long_description,
"long_description_content_type": "text/markdown",
"maintainer": "@joocer",
"author": __author__,
"author_email": "justin.joyce@joocer.com",
"packages": find_packages(include=[LIBRARY, f"{LIBRARY}.*"]),
"python_requires": ">=3.9",
"url": "https://github.com/mabel-dev/draken/",
# "install_requires": required,
"ext_modules": cythonize(extensions),
"package_data": {
"draken.core": ["*.pyx", "*.pxd", "*.h", "*.cpp"],
"draken.interop": ["*.pyx", "*.pxd", "*.h"],
"draken.vectors": ["*.pyx", "*.pxd"],
"draken.morsels": ["*.pyx", "*.pxd"],
"draken.compiled": ["*.pyx", "*.pxd"],
"draken.compiled_evaluators": ["*.pyx", "*.pxd"],
"draken.evaluators": ["*.pyx", "*.pxd"],
},
"compiler_directives": COMPILER_DIRECTIVES,
}
setup(**setup_config)