-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
115 lines (96 loc) · 3.13 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
import setuptools # noqa
from numpy.distutils.core import setup
from numpy.distutils.extension import Extension
metadata = dict(
name='pymbd',
version='0.2',
description='Many-body Dispersion',
long_description='See README.md for details.',
author='nickcafferry',
author_email='nickcafferry@gmail.com',
url='https://github.com/nickcafferry/Machine-Learning-in-Molecular-Sciences/',
packages=['pymbd'],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Natural Language :: English',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Unix',
'Programming Language :: Fortran',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Chemistry',
'Topic :: Scientific/Engineering :: Physics',
],
license='Mozilla Public License 2.0',
install_requires=['numpy'],
test_suite='pymbd.tests',
)
def get_setup():
kwargs = metadata.copy()
kwargs['ext_modules'] = [
get_mbd_extension(),
]
kwargs['cmdclass'] = {'build_ext': get_build_ext()}
return kwargs
def get_mbd_extension():
sources = [
'src/mbd_interface.f90',
'src/mbd_helper.f90',
'src/mbd_helper_dev.f90',
]
if MPI_STUBS:
sources.insert(0, MPI_STUBS)
kwargs = dict(
name='pymbd.lib',
sources=[
'src/mbd.f90',
'src/mbd_math.f90',
'src/mbd_repulsion.f90'
],
libraries=[
('mbdlib', dict(
sources=sources,
language='f90',
))
],
)
mod_lapack(kwargs)
return Extension(**kwargs)
def get_build_ext():
# patch build_ext to compile everything in the top-level temporary directory
from numpy.distutils.command.build_ext import build_ext
class my_build_ext(build_ext):
def get_ext_filename(self, ext_name):
filename = build_ext.get_ext_filename(self, ext_name)
return filename.split('/')[-1]
return my_build_ext
def mod_lapack(kwargs):
from numpy.distutils.system_info import get_info
for arg, val in get_info('lapack_opt', 2).items():
if arg == 'libraries':
kwargs['libraries'].extend(val)
else:
kwargs[arg] = val
MPI_STUBS = None
def setup_mpi():
global MPI_STUBS
try:
import mpi4py
except ImportError:
MPI_STUBS = 'src/mpi_stubs.f90'
return
# patch find_executables to insert the MPI compiler before FC or
# --f90exec is checked
from numpy.distutils.fcompiler import FCompiler
from functools import wraps
_find_executables = FCompiler.find_executables
@wraps(FCompiler.find_executables) # noqa
def find_executables(self):
self.executables['compiler_f90'][0] = mpi4py.get_config()['mpif90']
return _find_executables(self)
FCompiler.find_executables = find_executables
setup_mpi()
setup(**get_setup())