Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
133 lines (109 loc) · 3.65 KB
/
Copy pathsetup.py
File metadata and controls
133 lines (109 loc) · 3.65 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
#!/usr/bin/env python
"""diffpy.srreal - calculators for PDF, bond valence sum, and other
quantities based on atom pair interaction.
Packages: diffpy.srreal
"""
importglob
importos
importsys
fromctypes.utilimportfind_library
frompathlibimportPath
importnumpy
fromsetuptoolsimportExtension, setup
defget_boost_libraries():
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")
ifconda_prefix:
libdir=os.path.join(conda_prefix, "lib")
fornameincandidates:
so=f"lib{name}.so"
ifos.path.isfile(os.path.join(libdir, so)):
return [name]
# fallback to ldconfig
fornameincandidates:
found=find_library(name)
iffound:
return [name]
raiseRuntimeError("Cannot find a suitable Boost.Python library.")
defget_boost_config():
boost_path=os.environ.get("BOOST_PATH", "")
ifboost_path:
inc=Path(boost_path) /"include"
lib=Path(boost_path) /"lib"
else:
conda_prefix=os.environ.get("CONDA_PREFIX")
ifnotconda_prefix:
raiseEnvironmentError(
"Neither BOOST_PATH nor CONDA_PREFIX are set. "
"Please install Boost or set BOOST_PATH."
)
ifos.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)]}
defget_objcryst_libraries():
conda_prefix=os.environ.get("CONDA_PREFIX")
ifnotconda_prefix:
raiseEnvironmentError(
"CONDA_PREFIX is not set. "
"Please install ObjCryst using conda and activate the environment."
)
ifos.name=="nt":
libdir=Path(conda_prefix) /"Library"/"lib"
else:
libdir=Path(conda_prefix) /"lib"
libs= []
forfninos.listdir(libdir):
stem=Path(fn).stem
if"objcryst"notinstem.lower():
continue
# strip a leading "lib"
# so that setuptools does -lObjCryst, not -llibObjCryst
ifos.name!="nt"andstem.startswith("lib"):
stem=stem[3:]
libs.append(stem)
ifnotlibs:
raiseRuntimeError(f"No ObjCryst libraries found in {libdir}")
returnlibs
ifos.name=="nt":
compile_args= ["/std:c++14"]
macros= [("_USE_MATH_DEFINES", None)]
extra_link_args= ["/FORCE:MULTIPLE"]
else:
compile_args= ["-std=c++11"]
macros= []
extra_link_args= []
boost_cfg=get_boost_config()
objcryst_libs=get_objcryst_libraries()
ext_kws= {
"libraries": ["diffpy"] +get_boost_libraries() +objcryst_libs,
"extra_compile_args": compile_args,
"extra_link_args": extra_link_args,
"include_dirs": [numpy.get_include()] +boost_cfg["include_dirs"],
"library_dirs": boost_cfg["library_dirs"],
# "runtime_library_dirs": boost_cfg["library_dirs"],
"define_macros": macros,
}
defcreate_extensions():
"Initialize Extension objects for the setup function."
ext=Extension(
"diffpy.srreal.srreal_ext",
glob.glob("src/extensions/*.cpp"),
**ext_kws,
)
return [ext]
# Extensions not included in pyproject.toml
defext_modules():
ifset(sys.argv) & {"build_ext", "bdist_wheel", "install"}:
returncreate_extensions()
return []
if__name__=="__main__":
setup(ext_modules=ext_modules())