forked from vallis/libstempo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
88 lines (72 loc) · 2.53 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
import os
import platform
import subprocess
import warnings
from pathlib import Path
import numpy
from setuptools import Extension, setup
# we assume that you have either installed tempo2 via install_tempo2.sh in the default location
# or you have installed in the usual /usr/local
# or you have set the TEMPO2_PREFIX environment variable
# or the tempo2 executable is in your path
def _get_tempo2_install_location():
# from environment variable
tempo2_environ = os.getenv("TEMPO2_PREFIX")
if tempo2_environ is not None:
return tempo2_environ
# first check local install
local = Path(os.getenv("HOME")) / ".local"
if (local / "include/tempo2.h").exists():
return str(local)
# next try global
glbl = Path("/usr/local")
if (glbl / "include/tempo2.h").exists():
return str(glbl)
# if not, check for tempo2 binary in path
try:
out = subprocess.check_output("which tempo2", shell=True)
out = out.decode().strip()
except subprocess.CalledProcessError:
warnings.warn(("tempo2 does not appear to be in your path."))
else:
# the executable should be in in bin/ so navigate back and check include/
root_dir = Path(out).parents[1]
if (root_dir / "include/tempo2.h").exists():
return str(root_dir)
raise RuntimeError(
"""
Cannot find tempo2 install location. Your options are:
1. Use the install_tempo2.sh script without any arguments to install to default location.
2. Install tempo2 globally in /usr/local
3. Set the TEMPO2_PREFIX environment variable:
For example, if the tempo2 executable lives in /opt/local/bin:
TEMPO2_PREFIX=/opt/local pip install libstempo
or
export TEMPO2_PREFIX=/opt/local
pip install libstempo
"""
)
TEMPO2 = _get_tempo2_install_location()
# need rpath links to shared libraries on Linux
if platform.system() == "Linux":
linkArgs = ["-Wl,-R{}/lib".format(TEMPO2)]
else:
linkArgs = []
ext_modules = [
Extension(
"libstempo.libstempo",
["libstempo/libstempo.pyx"],
language="c++",
include_dirs=[TEMPO2 + "/include", numpy.get_include()],
libraries=["tempo2", "tempo2pred"],
library_dirs=[TEMPO2 + "/lib"],
extra_compile_args=["-Wno-unused-function"],
extra_link_args=linkArgs,
),
]
# add language level = 3
for e in ext_modules:
e.cython_directives = {"language_level": "3"}
setup(
ext_modules=ext_modules,
)