FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
zed-python-api/src/setup.py at master · stereolabs/zed-python-api · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
stereolabs
/
zed-python-api
Public
Notifications
You must be signed in to change notification settings
Fork
100
Star
258
Code
Issues
23
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
zed-python-api
/
src
/
setup.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
313 lines (266 loc) · 11 KB
Breadcrumbs
zed-python-api
/
src
/
setup.py
Copy path
File metadata and controls
313 lines (266 loc) · 11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# !/usr/bin/env python
########################################################################
#
# Copyright (c) 2022, STEREOLABS.
#
# All rights reserved.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
########################################################################
"""
Setup file to build, install, clean the pyzed package.
"""
import
os
import
sys
import
shutil
import
re
# FORCE CYTHON TO IGNORE PYTHRAN
# On some Linux systems (e.g. Jetson/Debian), Cython detects the system-installed 'pythran'
# package. Pythran then attempts to import the system 'scipy', which is linked against an older,
# system-provided NumPy (1.x). This triggers a binary incompatibility when running in a
# build environment that provides a newer NumPy (2.x).
sys
.
modules
[
'pythran'
]
=
None
# PRIORITIZE BUILD ENVIRONMENT OVER SYSTEM PACKAGES
# Standard system paths (like /usr/lib/python3/dist-packages) can sometimes take precedence
# over virtual environments or isolated build environments. If the system has an old NumPy (1.x)
# installed, setup.py might link against it instead of the NumPy 2.x we just installed in the
# build environment, leading to "numpy.dtype size changed" errors at runtime.
# We move system paths to the end of sys.path to ensure build dependencies are found first.
sys
.
path
=
[
p
for
p
in
sys
.
path
if
"/usr/lib/python3/dist-packages"
not
in
p
]
+
\
[
p
for
p
in
sys
.
path
if
"/usr/lib/python3/dist-packages"
in
p
]
import
numpy
as
np
import
subprocess
from
setuptools
import
setup
,
Extension
# Import Cython being careful with capitalization for non-modern Python environments
try
:
from
Cython
.
Build
import
cythonize
except
ModuleNotFoundError
as
e
:
if
not
sys
.
platform
.
startswith
(
'win'
):
raise
ModuleNotFoundError
(
e
)
# This is a workaround for Cython installation issues on Windows
# where the package is installed as 'cython' but internal imports expect 'Cython'
import
sys
try
:
import
cython
# Add the cython module as 'Cython' in sys.modules so internal imports work
sys
.
modules
[
'Cython'
]
=
cython
# Also need to map the submodules
import
cython
.
Build
import
cython
.
Compiler
sys
.
modules
[
'Cython.Build'
]
=
cython
.
Build
sys
.
modules
[
'Cython.Compiler'
]
=
cython
.
Compiler
# Import all submodules that are needed
for
attr_name
in
dir
(
cython
):
attr
=
getattr
(
cython
,
attr_name
)
if
hasattr
(
attr
,
'__name__'
)
and
attr
.
__name__
.
startswith
(
'cython.'
):
capitalized_name
=
attr
.
__name__
.
replace
(
'cython.'
,
'Cython.'
)
sys
.
modules
[
capitalized_name
]
=
attr
# Now try the import again
from
Cython
.
Build
import
cythonize
print
(
"Successfully imported cythonize using workaround"
)
except
(
ImportError
,
ModuleNotFoundError
,
AttributeError
)
as
e
:
print
(
f"Cython import failed:
{
e
}
"
)
raise
ImportError
(
"Cython is not installed or not properly configured. Please install Cython to proceed."
)
incDirs
=
""
libDirs
=
""
libs
=
""
cflags
=
""
ZED_SDK_MAJOR
=
"5"
ZED_SDK_MINOR
=
"0"
cuda_path
=
"/usr/local/cuda"
def
check_zed_sdk_version_private
(
file_path
):
global
ZED_SDK_MAJOR
global
ZED_SDK_MINOR
with
open
(
file_path
,
"r"
,
encoding
=
"utf-8"
)
as
myfile
:
data
=
myfile
.
read
()
p
=
re
.
compile
(
"ZED_SDK_MAJOR_VERSION (.*)"
)
major
=
p
.
search
(
data
).
group
(
1
)
p
=
re
.
compile
(
"ZED_SDK_MINOR_VERSION (.*)"
)
minor
=
p
.
search
(
data
).
group
(
1
)
p
=
re
.
compile
(
"ZED_SDK_PATCH_VERSION (.*)"
)
patch
=
p
.
search
(
data
).
group
(
1
)
if
major
==
ZED_SDK_MAJOR
and
minor
>=
ZED_SDK_MINOR
:
print
(
"ZED SDK Version: OK"
)
ZED_SDK_MAJOR
=
major
ZED_SDK_MINOR
=
minor
else
:
print
(
"WARNING ! Required ZED SDK version: "
+
ZED_SDK_MAJOR
+
"."
+
ZED_SDK_MINOR
)
print
(
"ZED SDK detected: "
+
major
+
"."
+
minor
+
"."
+
patch
)
print
(
"Aborting"
)
sys
.
exit
(
1
)
def
check_zed_sdk_version
(
file_path_
):
dev_file_path
=
file_path_
+
"/sl_zed/defines.hpp"
file_path
=
file_path_
+
"/sl/Camera.hpp"
if
os
.
path
.
isfile
(
dev_file_path
):
# internal dev mode
check_zed_sdk_version_private
(
dev_file_path
)
else
:
check_zed_sdk_version_private
(
file_path
)
def
clean_cpp
():
files_to_remove
=
[
"pyzed/camera.cpp"
,
"pyzed/core.cpp"
,
"pyzed/defines.cpp"
,
"pyzed/mesh.cpp"
,
"pyzed/types.cpp"
]
for
f_path
in
files_to_remove
:
if
os
.
path
.
isfile
(
f_path
):
os
.
remove
(
f_path
)
if
"clean"
in
""
.
join
(
sys
.
argv
[
1
:]):
target
=
"clean"
else
:
clean_cpp
()
target
=
"build"
if
"cleanall"
in
""
.
join
(
sys
.
argv
[
1
:]):
target
=
"clean"
print
(
"Deleting Cython files .."
)
clean_cpp
()
sys
.
argv
[
1
]
=
"clean"
if
os
.
path
.
isdir
(
"build"
):
shutil
.
rmtree
(
"build"
)
sys
.
exit
()
if
sys
.
platform
==
"win32"
:
if
os
.
getenv
(
"ZED_SDK_ROOT_DIR"
)
is
None
:
print
(
"Error: ZED_SDK_ROOT_DIR is not set. You must install the ZED SDK and set this environment variable."
)
sys
.
exit
(
1
)
elif
os
.
getenv
(
"CUDA_PATH"
)
is
None
:
print
(
"Error: CUDA_PATH is not set. You must install Cuda and set this environment variable."
)
sys
.
exit
(
1
)
else
:
check_zed_sdk_version
(
os
.
getenv
(
"ZED_SDK_ROOT_DIR"
)
+
"/include"
)
incDirs
=
[
np
.
get_include
(),
os
.
getenv
(
"ZED_SDK_ROOT_DIR"
)
+
"/include"
,
os
.
getenv
(
"CUDA_PATH"
)
+
"/include"
]
libDirs
=
[
os
.
getenv
(
"ZED_SDK_ROOT_DIR"
)
+
"/lib"
,
os
.
getenv
(
"CUDA_PATH"
)
+
"/lib/x64"
]
libs
=
[
"sl_zed64"
]
elif
"linux"
in
sys
.
platform
:
zed_path
=
"/usr/local/zed"
if
not
os
.
path
.
isdir
(
zed_path
):
print
(
f"Error: ZED SDK not found at
{
zed_path
}
. You must install the ZED SDK."
)
sys
.
exit
(
1
)
elif
not
os
.
path
.
isdir
(
cuda_path
):
print
(
f"Error: CUDA not found at
{
cuda_path
}
. You must install Cuda."
)
sys
.
exit
(
1
)
else
:
check_zed_sdk_version
(
zed_path
+
"/include"
)
incDirs
=
[
np
.
get_include
(),
zed_path
+
"/include"
,
cuda_path
+
"/include"
]
libDirs
=
[
zed_path
+
"/lib"
,
cuda_path
+
"/lib64"
]
libs
=
[
"sl_zed"
,
"usb-1.0"
]
cflags
=
[
"-std=c++14"
,
"-Wno-reorder"
,
"-Wno-deprecated-declarations"
,
"-Wno-cpp"
,
"-O3"
]
else
:
print
(
"Unknown system.platform: %s Installation failed, see setup.py."
%
sys
.
platform
)
sys
.
exit
(
1
)
print
(
"compilation flags:"
,
cflags
)
print
(
"include dirs:"
,
incDirs
)
print
(
"library dirs:"
,
libDirs
)
print
(
"libraries:"
,
libs
)
cython_directives
=
{
"embedsignature"
:
True
,
"language_level"
:
"3"
}
def
create_extension
(
name
,
sources
):
global
incDirs
global
libDirs
global
libs
global
cflags
if
sys
.
platform
==
"win32"
:
ext
=
Extension
(
name
,
sources
=
sources
,
include_dirs
=
incDirs
,
library_dirs
=
libDirs
,
libraries
=
libs
,
language
=
"c++"
)
return
ext
elif
"linux"
in
sys
.
platform
:
ext
=
Extension
(
name
,
sources
=
sources
,
include_dirs
=
incDirs
,
library_dirs
=
libDirs
,
libraries
=
libs
,
runtime_library_dirs
=
libDirs
,
language
=
"c++"
,
extra_compile_args
=
cflags
)
return
ext
else
:
print
(
"Unknown system.platform: %s"
%
sys
.
platform
)
return
None
extensions
=
list
()
py_packages
=
[
"pyzed"
]
GPUmodulesTable
=
[(
"pyzed.sl"
, [
"pyzed/sl.pyx"
])]
for
mod
in
GPUmodulesTable
:
print
(
"Building module:"
,
mod
)
extension
=
create_extension
(
mod
[
0
],
mod
[
1
])
if
extension
is
None
:
print
(
f"ERROR: Failed to create extension for
{
mod
[
0
]
}
. Platform
{
sys
.
platform
}
might not be supported or configured correctly."
)
sys
.
exit
(
1
)
extList
=
cythonize
(
extension
,
compiler_directives
=
cython_directives
)
extensions
.
extend
(
extList
)
# Runtime requirements
install_requires
=
[
'cython>=3.0.0'
# NumPy requirement is added below based on Python version
]
# Numpy versioning based on Python version
# Numpy 2.0 dropped support for Python 3.8 and introduced ABI break
if
(
sys
.
version_info
.
major
,
sys
.
version_info
.
minor
)
<=
(
3
,
8
):
install_requires
.
append
(
'numpy>=1.15,<2.0'
)
# oldest-supported-numpy might build against ~1.15 for py38
else
:
install_requires
.
append
(
'numpy>=2.0,<3.0'
)
# For py > 3.8, target numpy 2.x
print
(
"Install requires:"
,
install_requires
)
# Build-time requirements
setup_requires
=
[
'setuptools>=42'
,
# Good to have a recent setuptools for pyproject.toml compatibility (even if not used here)
'cython>=3.0.0'
,
]
# For Python versions that will use numpy < 2.0 at runtime,
# ensure oldest-supported-numpy doesn't try to pull numpy 2.0 at build time.
# oldest-supported-numpy itself handles Python compatibility, but this adds an explicit cap for older Pythons.
if
(
sys
.
version_info
.
major
,
sys
.
version_info
.
minor
)
<=
(
3
,
8
):
setup_requires
.
append
(
'numpy<2.0'
)
print
(
"Setup requires:"
,
setup_requires
)
# Generate stubs if we are not cleaning
if
"clean"
not
in
""
.
join
(
sys
.
argv
[
1
:]):
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
stub_generator_path
=
os
.
path
.
join
(
current_dir
,
"generate_pyzed_stubs.py"
)
if
os
.
path
.
isfile
(
stub_generator_path
):
try
:
print
(
f"Generating .pyi stubs using
{
stub_generator_path
}
..."
)
subprocess
.
check_call
([
sys
.
executable
,
stub_generator_path
,
os
.
path
.
join
(
current_dir
,
"pyzed/sl.pyx"
),
os
.
path
.
join
(
current_dir
,
"pyzed/sl.pyi"
)])
except
Exception
as
e
:
print
(
f"Warning: Failed to generate stubs:
{
e
}
"
)
setup
(
name
=
"pyzed"
,
version
=
ZED_SDK_MAJOR
+
"."
+
ZED_SDK_MINOR
,
author_email
=
"developers@stereolabs.com"
,
description
=
"Use the ZED SDK with Python"
,
url
=
'https://github.com/stereolabs/zed-python-api'
,
packages
=
py_packages
,
ext_modules
=
extensions
,
python_requires
=
'>=3.8'
,
setup_requires
=
setup_requires
,
# ADDED: For build-time dependencies
install_requires
=
install_requires
,
extras_require
=
{
'sample'
: [
'opencv-python'
,
'pyopengl'
,
]
},
package_data
=
{
'pyzed'
: [
'*.pyi'
],
}
)
Back
|
FazBrowse Home
|
New Git URL