forked from plumed/plumed2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
153 lines (135 loc) · 5.31 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
#/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Copyright (c) 2011-2016 The plumed team
# (see the PEOPLE file at the root of the distribution for a list of names)
#
# See http://www.plumed.org for more information.
#
# This file is part of plumed, version 2.
#
# plumed is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# plumed is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with plumed. If not, see <http://www.gnu.org/licenses/>.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#
# This python routine builds an interface between plumed and python using cython
#
from setuptools import setup
from setuptools import Extension
import subprocess
import os
import os.path
import sys
from shutil import copyfile
import platform
from distutils.sysconfig import get_config_var
from distutils.version import LooseVersion
if sys.version_info < (3,):
raise ImportError("PLUMED 2.6 only supports Python 3")
def is_platform_mac():
return sys.platform == 'darwin'
if os.getenv("plumed_macports") is not None:
copyfile("../VERSION","VERSION")
try:
os.mkdir("include")
except OSError:
pass
copyfile("../src/wrapper/Plumed.h","include/Plumed.h")
plumedname = os.getenv("plumed_program_name")
if plumedname is None:
plumedname = "plumed"
plumedversion = os.getenv("plumed_version")
if plumedversion is None:
plumedversion = subprocess.check_output(['grep','-v','#','./VERSION']).decode("utf-8").rstrip()
print( "Module name " + plumedname )
print( "Version number " + plumedversion )
extra_compile_args=['-D__PLUMED_HAS_DLOPEN','-D__PLUMED_WRAPPER_LINK_RUNTIME=1','-D__PLUMED_WRAPPER_CXX=1','-D__PLUMED_WRAPPER_IMPLEMENTATION=1','-D__PLUMED_WRAPPER_EXTERN=0','-D__PLUMED_WRAPPER_CXX_DEFAULT_INVALID=1']
defaultkernel=os.getenv("plumed_default_kernel")
if defaultkernel is not None:
extra_compile_args.append("-D__PLUMED_DEFAULT_KERNEL=" + os.path.abspath(defaultkernel))
print( "Hardcoded PLUMED_KERNEL " + os.path.abspath(defaultkernel))
# Fixes problem with compiling the PYTHON interface in Mac OS 10.14 and higher.
# Sets the deployment target to 10.9 when compiling on version 10.9 and above,
# overriding distutils behaviour to target the Mac OS version python was built for.
# This can be overridden by setting MACOSX_DEPLOYMENT_TARGET before compiling the
# python interface.
# This fix is taken from https://github.com/pandas-dev/pandas/pull/24274/files
if is_platform_mac():
if 'MACOSX_DEPLOYMENT_TARGET' not in os.environ:
current_system = LooseVersion(platform.mac_ver()[0])
python_target = LooseVersion(get_config_var('MACOSX_DEPLOYMENT_TARGET'))
if python_target < '10.9' and current_system >= '10.9':
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
def readme():
with open('README.rst') as f:
return f.read()
try:
include_dirs=[os.environ["plumed_include_dir"]]
except KeyError:
include_dirs=["./include"]
# allow one to force using cython with env var plumed_force_cython=yes
USE_CYTHON = False
try:
if(os.environ["plumed_force_cython"]=="yes"):
print('plumed_force_cython=yes')
USE_CYTHON = True
except KeyError:
pass
# if plumed.cpp is available, do not need cython
if not USE_CYTHON:
if not os.path.isfile("plumed.cpp"):
print('plumed.cpp not found, cython is needed')
USE_CYTHON = True
# try to import cython
if USE_CYTHON:
try:
print('importing cython')
from Cython.Build import cythonize
extension="pyx"
except ImportError:
print('Error: building ' + plumedname + ' requires cython. Please install it first with pip install cython')
sys.exit(-1)
else:
print('using available plumed.cpp file')
extension="cpp"
ext_modules=[Extension(
name=plumedname,
sources=["plumed." + extension],
language="c++",
include_dirs=include_dirs,
extra_compile_args=extra_compile_args
)]
if USE_CYTHON:
ext_modules=cythonize(ext_modules,language_level=3)
setup(
name=plumedname,
version=plumedversion,
description='Python interface to PLUMED',
long_description=readme(),
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Scientific/Engineering :: Chemistry',
'Topic :: Scientific/Engineering :: Physics',
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
author='Gareth A. Tribello',
author_email='plumed-users@googlegroups.com',
url='http://www.plumed.org',
ext_modules = ext_modules,
zip_safe=False,
test_suite='nose.collector',
python_requires='>=3'
)