-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
144 lines (125 loc) · 5.57 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
import glob
import os
import sys
import subprocess
from numpy.distutils.core import setup
from numpy.distutils.core import Extension
from numpy.distutils.misc_util import has_cxx_sources
import numpy as np
import pele
## Numpy header files
numpy_lib = os.path.split(np.__file__)[0]
numpy_include = os.path.join(numpy_lib, 'core/include')
# find pele path
# note: this is used both for the c++ source files and for the cython pxd files,
# neither of which are "installed". This should really point to the source directory.
# So this will only work if pele was built in-place
try:
pelepath = os.path.dirname(pele.__file__)[:-5]
except:
sys.stderr.write("WARNING: could't find path to pele\n")
sys.exit()
def generate_cython():
cwd = os.path.abspath(os.path.dirname(__file__))
print("Cythonizing sources")
p = subprocess.call([sys.executable,
os.path.join(cwd, 'cythonize.py'),
'mcpele', "-I %s/pele/potentials/" % pelepath],
cwd=cwd)
if p != 0:
raise RuntimeError("Running cythonize failed!")
generate_cython()
#
# compile fortran extension modules
#
class ModuleList:
def __init__(self, **kwargs):
self.module_list = []
self.kwargs = kwargs
def add_module(self, filename):
modname = filename.replace("/", ".")
modname, ext = os.path.splitext(modname)
self.module_list.append(Extension(modname, [filename], **self.kwargs))
setup(name='mcpele',
version='0.1',
description="mcpele is a library of monte carlo and parallel tempering routines buil on the pele foundation",
url='https://github.com/pele-python/mcpele',
packages=["mcpele",
"mcpele.monte_carlo",
"mcpele.parallel_tempering",
# add the test directories
"mcpele.monte_carlo.tests",
"mcpele.parallel_tempering.tests",
],
)
#
# build the c++ files
#
include_sources_mcpele = ["source/" + f for f in os.listdir("source/")
if f.endswith(".cpp")]
include_dirs = [numpy_include, "source"]
include_sources_pele = [pelepath+"/source/" + f for f in os.listdir(pelepath+"/source")
if f.endswith(".cpp")]
depends_mcpele = [os.path.join("source/mcpele", f) for f in os.listdir("source/mcpele/")
if f.endswith(".cpp") or f.endswith(".h") or f.endswith(".hpp")]
depends_pele = [os.path.join(pelepath+"/source/pele", f) for f in os.listdir(pelepath+"/source/pele")
if f.endswith(".cpp") or f.endswith(".h") or f.endswith(".hpp")]
# note: on my computer (ubuntu 12.04 gcc version 4.6.3), when compiled with the
# flag -march=native I run into problems. Everything seems to run ok, but when
# I run it through valgrind, valgrind complains about an unrecognized
# instruction. I don't have a clue what is causing this, but it's probably
# better to be on the safe side and not use -march=native
#extra_compile_args = ['-I/home/sm958/Work/pele/source','-std=c++0x',"-Wall", "-Wextra", "-O3", '-funroll-loops']
# uncomment the next line to add extra optimization options
include_pele_source = '-I'+ pelepath + '/source'
extra_compile_args = [include_pele_source,'-std=c++0x',"-Wall", '-Wextra','-pedantic','-O3'] #,'-DDEBUG'
# note: to compile with debug on and to override extra_compile_args use, e.g.
# OPT="-g -O2 -march=native" python setup.py ...
include_sources_all = include_sources_mcpele + include_sources_pele
depends_all = depends_mcpele + depends_pele
cxx_modules = [
Extension("mcpele.monte_carlo._pele_mc",
["mcpele/monte_carlo/_pele_mc.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c++", depends=depends_all,
),
Extension("mcpele.monte_carlo._monte_carlo_cpp",
["mcpele/monte_carlo/_monte_carlo_cpp.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c++", depends=depends_all,
),
Extension("mcpele.monte_carlo._takestep_cpp",
["mcpele/monte_carlo/_takestep_cpp.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c++", depends=depends_all,
),
Extension("mcpele.monte_carlo._accept_test_cpp",
["mcpele/monte_carlo/_accept_test_cpp.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c++", depends=depends_all,
),
Extension("mcpele.monte_carlo._conf_test_cpp",
["mcpele/monte_carlo/_conf_test_cpp.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c++", depends=depends_all,
),
Extension("mcpele.monte_carlo._action_cpp",
["mcpele/monte_carlo/_action_cpp.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c++", depends=depends_all,
),
Extension("mcpele.monte_carlo._nullpotential_cpp",
["mcpele/monte_carlo/_nullpotential_cpp.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
language="c++", depends=depends_all,
),
]
setup(ext_modules=cxx_modules,
)