-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
175 lines (138 loc) · 5.87 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
import sys
import os
def return_major_minor_python():
return str(sys.version_info[0])+"."+str(sys.version_info[1])
def check_python_version():
if sys.version_info[0] >= 3 and sys.version_info[1] >= 5:
return True
return False
def return_include_dir():
from distutils.util import get_platform
return get_platform()+'-'+return_major_minor_python()
def setup_tort_ext(args,parent_package='',top_path=''):
from numpy.distutils.misc_util import Configuration
from os.path import join
config = Configuration('',parent_package,top_path)
tort_src = [join('crystal_torture/','tort.f90')]
config.add_library('_tort', sources=tort_src,
extra_f90_compile_args = args["compile_args"],
extra_link_args=args["link_args"])
sources = [join('crystal_torture','f90wrap_tort.f90')]
config.add_extension(name='_tort',
sources=sources,
extra_f90_compile_args = args["compile_args"],
extra_link_args=args["link_args"],
libraries=['_tort'],
include_dirs=['build/temp.' + return_include_dir()])
dist_src = [join('crystal_torture/','dist.f90')]
config.add_extension(name='dist',
sources=dist_src,
extra_f90_compile_args = args["compile_args"],
extra_link_args=args["link_args"])
return config
def check_f2py_compiler():
from numpy.distutils.fcompiler import get_default_fcompiler, CompilerNotFound
from numpy.distutils.fcompiler import CompilerNotFound
f2py_compiler = get_default_fcompiler()
if f2py_compiler == None:
raise CompilerNotFound('You don\'t have a Fortran compiler installed. Please install one and try again')
sys.exit()
if 'gnu' not in f2py_compiler:
print(' GNU compiler not installed. Checking f2py compiler - this is UNTESTED' )
print(' Speculatively setting flags - if compile fails, or OpenMP doesn\'t work install gfortran and retry')
if 'gnu' in f2py_compiler:
print('Found gnu compiler. Setting OpenMP flag to \'-fopenmp\'')
compile_args = ['-fopenmp', '-lgomp', '-O3']
link_args = ['-lgomp']
elif f2py_compiler =='intel':
print('Found intel compiler. Setting OpenMP flag to \'-openmp\'')
compile_args = ['-qopenmp', '-O3']
link_args = []
elif f2py_compiler == 'intelem':
print('Found intel compiler. Setting OpenMP flag to \'-openmp\'')
compile_args = ['-qopenmp', '-O3']
link_args = []
elif 'pg' in f2py_comopiler:
print('Found portland compiler. Setting OpenMP flag to \'-mp\'')
compile_args = ['-mp', '-O3']
link_args = []
elif 'nag' in f2py_compiler:
print('Found NAG compiler. Setting OpenMP flag to \'-openmp\'')
compile_args = ['-openmp', '-O3']
link_args = []
else:
print('Not sure what compiler f2py uses. Speculatively setting OpenMP flag to \'-openmp\'')
compile_args = ['-openmp', '-O3']
link_args = []
args = {'link_args':link_args,'compile_args':compile_args}
return args
def install_dependencies():
if '--user' in sys.argv:
cmd = ['pip install -r requirements.txt --user']
else:
cmd = ['pip install -r requirements.txt']
subprocess.call(cmd, shell=True)
def install_numpy():
if '--user' in sys.argv:
cmd = ['pip install numpy --user']
else:
cmd = ['pip install numpy']
subprocess.call(cmd, shell=True)
def install_f90wrap():
cmd = ['git clone https://github.com/jameskermode/f90wrap']
subprocess.call(cmd, shell=True)
if '--user' in sys.argv:
cmd = ['pip install ./f90wrap --user']
else:
cmd = ['pip install ./f90wrap']
subprocess.call(cmd, shell=True)
#pip install ./f90wrap
def build_f90_src_for_tests():
os.chdir('crystal_torture/')
subprocess.call('pwd', shell=True)
subprocess.call('ls', shell=True)
subprocess.call('./build_tort.sh', shell=True)
os.chdir('../')
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
if __name__ == '__main__':
import subprocess
# from setuptools import setup
try:
assert(check_python_version() )
except AssertionError:
sys.exit("Exiting: Please use python version > 3.5")
install_numpy()
install_f90wrap()
from numpy.distutils.core import setup
install_dependencies()
build_f90_src_for_tests()
exec(open('crystal_torture/version.py').read())
args = check_f2py_compiler()
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.rst')) as f:
long_description = f.read()
config = {'name':'CrystalTorture',
'version':__version__,
'description':'A Crystal Tortuosity Module',
'long_description': long_description,
'long_description_content_type':"text/x-rst",
'author':'Conn O\'Rourke',
'author_email':'[email protected]',
'url':'https://github.com/connorourke/crystal_torture',
'python_requires':'>=3.7',
'packages':['crystal_torture'],
'package_dir':{'crystal_torture':'crystal_torture'},
'package_data':{'crystal_torture':['*so','*tort*','*dist*','*o*']},
'include_package_data':True,
'license': 'MIT',
'install_requires': ['ddt',
'coverage',
'numpy',
'pymatgen>=2022.0.0'
]
# 'f90wrap' - needs to be installed from repo for bug fix until pypi updated
}
config_tort = setup_tort_ext(args,parent_package='crystal_torture',top_path='')
config2 = dict(config,**config_tort.todict())
setup(**config2)