forked from vallis/libstempo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
119 lines (106 loc) · 3.91 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
import os
import platform
import subprocess
import warnings
from pathlib import Path
import numpy
from Cython.Build import cythonize
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 = []
setup(
name="libstempo",
version="2.4.5", # remember to change it in __init__.py
description="A Python wrapper for tempo2",
author="Michele Vallisneri",
author_email="[email protected]",
url="https://github.com/vallis/libstempo",
license="MIT",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
packages=["libstempo"],
package_dir={"libstempo": "libstempo"},
package_data={"libstempo": ["data/*", "ecc_vs_nharm.txt"]},
py_modules=[
"libstempo.like",
"libstempo.multinest",
"libstempo.emcee",
"libstempo.plot",
"libstempo.toasim",
"libstempo.spharmORFbasis",
"libstempo.eccUtils",
],
setup_requires=["cython>=0.22", "numpy"],
install_requires=["numpy>=1.15.0", "scipy>=1.2.0", "matplotlib>=3.3.2", "ephem>=3.7.7.1"],
extras_require={"astropy": ["astropy>=4.1"]},
python_requires=">=3.7",
ext_modules=cythonize(
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,
)
),
)