-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup.py
151 lines (118 loc) · 4.26 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
148
149
150
151
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import glob
if any((x in sys.argv for x in ('develop', 'bdist'))):
# use setuptools for develop, but nothing else
from setuptools import setup
from distutils.core import Command
else:
from distutils.core import setup, Command
with open('README.rst') as file:
long_description = file.read()
#with open('CHANGES') as file:
# long_description += file.read()
__version__ = ""
with open("pyradex/version.py") as f:
exec(f.read())
#import os
#if not os.path.exists('pyradex/radex/radex.so'):
# import install_radex
# install_radex.install_radex()
class InstallRadex(Command):
"""
Compile the f2py radex modules needed for the python wrapper
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import install_radex
install_radex.install_radex()
class BuildRadexExecutable(Command):
"""
Create the files radex_sphere, radex_lvg, radex_slab in the Radex/bin/
directory
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import install_radex
install_radex.build_radex_executable()
class InstallFjdu(Command):
"""
Compile Fujun Du's "myradex"
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
cwd = os.getcwd()
os.chdir('myRadex')
if os.path.exists('wrapper_my_radex.so'):
os.remove('wrapper_my_radex.so')
os.system('make clean')
os.system('make wrapper')
result = os.system('make sub_trivials.o')
if result != 0:
raise ValueError("Compilation has failed. Check gfortran version?")
os.chdir(cwd)
for fn in glob.glob('myRadex/wrapper_my_radex*.so'):
outpath = 'pyradex/fjdu/{0}'.format(os.path.basename(fn))
if os.path.exists(outpath):
os.remove(outpath)
os.link(fn, outpath)
os.chdir('myRadex')
os.system('make clean')
os.chdir(cwd)
import subprocess
import shutil
import os
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if os.path.exists('build'):
shutil.rmtree('build')
#errno1 = subprocess.call(['py.test','--genscript=runtests.py'])
errno2 = subprocess.call([sys.executable, 'runtests.py'])
raise SystemExit(errno2)
radex_shared_object_files = [os.path.basename(fn) for fn in glob.glob("pyradex/radex/*.so")]
myradex_shared_object_files = [os.path.basename(fn) for fn in glob.glob("pyradex/fjdu/*.so")]
print(f"Found shared object files={radex_shared_object_files} for RADEX. (if that is a blank, it means radex didn't install successfully)")
print(f"Found shared object files={myradex_shared_object_files} for RADEX. (if that is a blank, it means fjdu's myradex didn't install successfully)")
setup(name='pyradex',
version=__version__,
description='Python-RADEX',
long_description=long_description,
author='Adam Ginsburg & Julia Kamenetzky',
author_email='[email protected]',
url='http://github.com/keflavich/pyradex/',
packages=['pyradex','pyradex.radex','pyradex.tests','pyradex.fjdu'],
package_data={'pyradex.radex':['radex.so'] + radex_shared_object_files,
'pyradex.fjdu':['wrapper_my_radex.so'] + myradex_shared_object_files,
'pyradex.tests':['data/example.out']},
requires=['requests', 'astroquery', ],
install_requires=['astropy>=0.4.1', 'requests>=2.4.1',],
cmdclass={'test': PyTest,
'install_radex': InstallRadex,
'build_radex_exe': BuildRadexExecutable,
'install_myradex': InstallFjdu,
'install_fjdu': InstallFjdu,
},
#include_package_data=True,
)
if os.getenv('RADEX_DATAPATH'):
print("Installation has completed. RADEX_DATAPATH={0}".format(os.getenv('RADEX_DATAPATH')))
else:
print("Installation has completed. Make sure to set your RADEX_DATAPATH variable!")