-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsetup.py
More file actions
119 lines (95 loc) · 3.22 KB
/
setup.py
File metadata and controls
119 lines (95 loc) · 3.22 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
#!/usr/bin/env python
# Installation script for pyobjcryst
"""pyobjcryst - Python bindings to ObjCryst++ Object-Oriented Crystallographic
Library
Packages: pyobjcryst
"""
import glob
import os
import sys
from ctypes.util import find_library
from pathlib import Path
import numpy as np
from setuptools import Extension, setup
# Helper functions -----------------------------------------------------------
def get_boost_libraries():
# the names we'll search for
major, minor = sys.version_info[:2]
candidates = [
f"boost_python{major}{minor}",
f"boost_python{major}",
"boost_python",
]
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix:
libdir = os.path.join(conda_prefix, "lib")
for name in candidates:
so = f"lib{name}.so"
if os.path.isfile(os.path.join(libdir, so)):
# return the plain "boost_python311" etc (no "lib" prefix or ".so")
return [name]
# fallback to ldconfig
for name in candidates:
found = find_library(name)
if found:
# find_library may return "libboost_python3.so.1.74.0" etc
# strip off lib*.so.* if you like, or just return name
return [name]
raise RuntimeError("Cannot find a suitable Boost.Python library.")
def get_env_config():
conda_prefix = os.environ.get("CONDA_PREFIX")
if not conda_prefix:
raise EnvironmentError(
"CONDA_PREFIX environment variable is not set. "
"Please activate your conda environment before running setup.py."
)
if os.name == "nt":
inc = Path(conda_prefix) / "Library" / "include"
lib = Path(conda_prefix) / "Library" / "lib"
else:
inc = Path(conda_prefix) / "include"
lib = Path(conda_prefix) / "lib"
return {"include_dirs": [str(inc)], "library_dirs": [str(lib)]}
def create_extensions():
include_dirs = get_env_config().get("include_dirs") + [np.get_include()]
library_dirs = get_env_config().get("library_dirs")
if os.name == "nt":
objcryst_lib = "libObjCryst"
else:
objcryst_lib = "ObjCryst"
libraries = [objcryst_lib] + get_boost_libraries()
extra_objects = []
extra_compile_args = []
extra_link_args = []
define_macros = []
if os.name == "nt":
extra_compile_args = [
"-DBOOST_ERROR_CODE_HEADER_ONLY",
"-DREAL=double",
]
else:
extra_compile_args = [
"-std=c++11",
"-DBOOST_ERROR_CODE_HEADER_ONLY",
"-DREAL=double",
"-fno-strict-aliasing",
]
ext_kws = {
"include_dirs": include_dirs,
"libraries": libraries,
"library_dirs": library_dirs,
"define_macros": define_macros,
"extra_compile_args": extra_compile_args,
"extra_link_args": extra_link_args,
"extra_objects": extra_objects,
}
ext = Extension(
"pyobjcryst._pyobjcryst", glob.glob("src/extensions/*.cpp"), **ext_kws
)
return [ext]
def ext_modules():
if set(sys.argv) & {"build_ext", "bdist_wheel", "install"}:
return create_extensions()
return []
if __name__ == "__main__":
setup(ext_modules=ext_modules())