-
Notifications
You must be signed in to change notification settings - Fork 45
/
setup.py
147 lines (130 loc) · 4.67 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
import os
import platform
import shutil
import sys
from pathlib import Path
# Available at setup time due to pyproject.toml
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup
HERE = Path(__file__).parent
about = {}
with open(HERE / "src" / "pye57" / "__version__.py") as f:
exec(f.read(), about)
version = about["__version__"]
libE57_cpp = sorted(map(str, (HERE / "libE57Format" / "src").glob("*.cpp")))
libraries = []
library_dirs = []
include_dirs = [
"libE57Format/include",
"libE57Format/src",
"libE57Format/extern/CRCpp/inc",
]
package_data = []
extra_link_args = []
if platform.system() == "Windows":
libraries.append("xerces-c_3")
# using conda
conda_library_dir = Path(sys.executable).parent / "Library"
if conda_library_dir.exists():
library_dirs.append(str(conda_library_dir / "lib"))
include_dirs.append(str(conda_library_dir / "include"))
# using cibuildwheel
xerces_dir = Path(os.environ["TEMP"]) / "xerces_c"
if xerces_dir.exists():
library_dirs.append(str(xerces_dir / "lib"))
include_dirs.append(str(xerces_dir / "include"))
# include xerces-c dll in the package
shutil.copy2(xerces_dir / "bin" / "xerces-c_3_2.dll", HERE / "src" / "pye57")
package_data.append("xerces-c_3_2.dll")
elif platform.system() == "Darwin":
xerces_dir = Path("/usr/local/")
if xerces_dir.exists():
# include xerces-c dylib in the package
shutil.copy2(xerces_dir / "lib" / "libxerces-c-3.2.dylib", HERE / "src" / "pye57")
library_dirs.append(str(xerces_dir / "lib"))
include_dirs.append(str(xerces_dir / "include"))
package_data.append("libxerces-c-3.2.dylib")
libraries.append("xerces-c")
extra_link_args = [
f"-Wl,-rpath,@loader_path",
f"-L{str(HERE / 'src' / 'pye57')}",
"-lxerces-c",
]
else:
libraries.append("xerces-c")
ext_modules = [
Pybind11Extension(
"pye57.libe57",
["src/pye57/libe57_wrapper.cpp"] + libE57_cpp,
define_macros=[("E57_DLL", "")],
include_dirs=include_dirs,
libraries=libraries,
library_dirs=library_dirs,
language="c++",
extra_link_args=extra_link_args,
),
]
export_header_path = HERE / "libE57Format" / "include" / "E57Export.h"
class BuildExt(build_ext):
"""A custom build extension for adding compiler-specific options."""
def build_extensions(self):
ct = self.compiler.compiler_type
opts = []
revision_id = "pye57-" + version
if ct == "unix":
opts.append(f'-DVERSION_INFO="{version}"')
opts.append(f'-DREVISION_ID="{revision_id}"')
opts.append("-DCRCPP_USE_CPP11")
opts.append("-DCRCPP_BRANCHLESS")
opts.append("-Wno-unused-variable")
opts.append("-DE57_ENABLE_DIAGNOSTIC_OUTPUT")
elif ct == "msvc":
opts.append(f'/DVERSION_INFO="{version}"')
opts.append(rf'/DREVISION_ID="\"{revision_id}\""')
opts.append("/DCRCPP_USE_CPP11")
opts.append("/DCRCPP_BRANCHLESS")
opts.append("/DWINDOWS")
opts.append("/DE57_ENABLE_DIAGNOSTIC_OUTPUT")
for ext in self.extensions:
ext.extra_compile_args = opts
export_header_path.touch()
try:
super().build_extensions()
finally:
export_header_path.unlink()
with open(HERE / "README.md") as f:
long_description = "\n" + f.read()
setup(
name="pye57",
version=version,
author="David Caron",
author_email="[email protected]",
maintainer="Graham Knapp",
maintainer_email="[email protected]",
url="https://www.github.com/davidcaron/pye57",
description="Python .e57 files reader/writer",
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=["numpy", "pyquaternion"],
ext_modules=ext_modules,
packages=["pye57"],
package_dir={"": "src"},
# include_package_data=True,
package_data={"pye57": package_data},
extras_require={"test": "pytest"},
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"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",
"Programming Language :: Python :: Implementation :: CPython",
],
cmdclass={"build_ext": BuildExt},
zip_safe=False,
python_requires=">=3.9",
)