-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup.py
executable file
·180 lines (147 loc) · 6.29 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python
from __future__ import division, absolute_import, print_function
__author__ = 'andrea tramacere'
from setuptools import setup, find_packages,Extension
# from setuptools.command.install import install
# from distutils.extension import Extension
# import distutils.command.install as orig
from distutils.command.build import build
from setuptools.command.install import install
from distutils.sysconfig import get_python_lib
import os
import glob
import shutil
import fnmatch
import json
import sys
def check_swig():
command = 'swig'
if shutil.which(command) is None:
_mess = """
***********************************************************************************************************
*** you need to install swig v>=3.0.0 to install from source ***
*** ***
*** - on linux Ubuntu: sudo apt-get install swig ***
*** ***
*** - on linux Debian: sudo aptitude install swig ***
*** ***
*** - on linux Fedora: sudo yum install swig ***
*** ***
*** - on mac: ***
*** /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ***
*** brew install swig ***
*** ***
*** visit: http://www.swig.org/ for more info ***
***********************************************************************************************************
"""
raise RuntimeError(_mess)
class CustomBuild(build):
def run(self):
print('-> custom build')
check_swig()
self.run_command('build_ext')
build.run(self)
class CustomInstall(install):
def run(self):
print('-> custom install',self.get_command_name())
check_swig()
self.run_command('build_ext')
install.run(self)
print ('JETSETBESSELBUILD',os.getenv('JETSETBESSELBUILD') == 'TRUE')
if os.getenv('JETSETBESSELBUILD') == 'TRUE':
self.run_command('test')
else:
pass
class CustomClean(install):
def run(self):
try:
shutil.rmtree('dist')
except:
pass
try:
shutil.rmtree('build')
except:
pass
try:
shutil.rmtree(glob.glob('*.egg-info')[0])
except:
pass
try:
os.remove('jetset/jetkernel/jetkernel.py')
except:
pass
try:
os.remove('jetset/jetkernel/jetkernel_wrap.c')
except:
pass
try:
shutil.rmtree('jetset/jetkernel/__pycache__')
except:
pass
# to remove files installed by old versions
site_p=get_python_lib()
for f in glob.glob(site_p+'/*_jetkernel*'):
print ('found .so object:', f)
print ('removing it')
try:
os.remove(f)
except:
pass
custom_cmdclass = {'build': CustomBuild,
'install': CustomInstall,
'clean':CustomClean}
with open('jetset/pkg_info.json') as fp:
_info = json.load(fp)
__version__ = _info['version']
f = open("./requirements.txt",'r')
req=f.readlines()
f.close()
req=[n.strip() for n in req if n.startswith('#') is False]
src_files=['jetset/jetkernel/jetkernel.i']
src_files.extend(glob.glob ('jetkernel_src/src/*.c'))
_module=Extension('jetset.jetkernel/_jetkernel',
sources=src_files,
#extra_compile_args=['-lpthread','-O3'],
language='c',
#extra_compile_options='-fPIC -v -c -m64 -I',
#extra_link_options='-suppress',
swig_opts=['-v','-threads'],
include_dirs=['jetkernel_src/include'])
if os.getenv('JETSETBESSELBUILD') == 'TRUE':
_test_suite = 'jetset.tests.test_build_functions'
else:
_test_suite = None
with open("proj_descr.md", "r") as f:
long_description = f.read()
# this to skip that pip install packages when installing src from conda
is_conda = os.path.exists(os.path.join(sys.prefix, 'conda-meta'))
if is_conda:
install_req=None
else:
install_req=req
print('-> version', __version__, install_req)
setup(name='jetset',
version=__version__,
author='Andrea Tramacere',
url='https://github.com/andreatramacere/jetset',
long_description=long_description,
long_description_content_type='text/markdown',
description="A framework for self-consistent modeling and fitting of astrophysical relativistic jets SEDs",
author_email='andrea.tramacere@gmail.com',
packages=['jetset', 'jetset.leastsqbound', 'jetset.jetkernel','jetset.tests'],
package_data={ 'jetset.Spectral_Templates_Repo':['*.dat'],
'jetset.test_data':['SEDs_data'],
'jetset.test_data.SEDs_data':['*.ecsv'],
'jetset':['requirements.txt'],
'jetset.ebl_data':['*.fits','*.dat','*.ecsv','*.fits.gz'],
'jetset.mathkernel':['*.dat'],
'jetset':['pkg_info.json'],
'jetset.jetkernel':['mathkernel/*dat']},
include_package_data = True,
cmdclass=custom_cmdclass,
ext_modules = [_module],
install_requires=install_req,
py_modules=['jetset.jetkernel/jetkernel'],
python_requires='>=3.8',
test_suite =_test_suite,
zip_safe=True)