/
setup.py
156 lines (137 loc) · 5.91 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
import os
import sys
import versioneer
if sys.version_info < (2, 7):
sys.stderr.write('You must have at least Python 2.7 for ParmEd to work '
'correctly.\n')
sys.exit(1)
try:
if '--no-setuptools' in sys.argv:
sys.argv.remove('--no-setuptools')
raise ImportError() # Don't import setuptools...
from setuptools import setup, Extension
kws = dict(entry_points={
'console_scripts' : ['parmed = parmed.scripts:clapp'],
'gui_scripts' : ['xparmed = parmed.scripts:guiapp']}
)
except ImportError:
from distutils.core import setup, Extension
kws = {'scripts' : [os.path.join('scripts', 'parmed'),
os.path.join('scripts', 'xparmed')]
}
from distutils.command.clean import clean as Clean
class CleanCommand(Clean):
"""python setup.py clean
"""
# lightly adapted from scikit-learn package
description = "Remove build artifacts from the source tree"
def _clean(self, folder):
for dirpath, dirnames, filenames in os.walk(folder):
for filename in filenames:
if (filename.endswith('.so') or filename.endswith('.pyd')
or filename.endswith('.dll')
or filename.endswith('.pyc')):
os.unlink(os.path.join(dirpath, filename))
for dirname in dirnames:
if dirname == '__pycache__':
shutil.rmtree(os.path.join(dirpath, dirname))
def run(self):
Clean.run(self)
if os.path.exists('build'):
shutil.rmtree('build')
self._clean('./')
is_pypy = '__pypy__' in sys.builtin_module_names
if sys.platform == 'darwin' and not is_pypy:
# You *need* to use clang and clang++ for ParmEd extensions on a Mac;
# Anaconda does annoying stuff that breaks this, since their distutils
# automatically tries to use "gcc", which would conflict with the MacPorts
# gcc... sigh.
os.environ['CXX'] = 'clang++'
os.environ['CC'] = 'clang'
# parmed package and all its subpackages
packages = ['parmed', 'parmed.amber', 'parmed.modeller',
'parmed.tinker', 'parmed.unit', 'parmed.amber.mdin',
'parmed.charmm', 'parmed.formats.pdbx', 'parmed.rosetta', 'parmed.rdkit',
'parmed.formats', 'parmed.utils.fortranformat', 'parmed.openmm',
'parmed.utils', 'parmed.gromacs', 'parmed.tools', 'parmed.namd',
'parmed.tools.gui', 'parmed.tools.simulations']
# Optimized readparm
sources = [os.path.join('src', '_rdparm.cpp'),
os.path.join('src', 'readparm.cpp')]
depends = [os.path.join('src', 'CompatabilityMacros.h'),
os.path.join('src', 'readparm.h')]
include_dirs = [os.path.join(os.path.abspath('.'), 'src')]
extensions = [Extension('parmed.amber._rdparm',
sources=sources,
include_dirs=include_dirs,
depends=depends)
]
if __name__ == '__main__':
import shutil
# See if we have the Python development headers. If not, don't build the
# optimized prmtop parser extension
from distutils import sysconfig
if not is_pypy and not os.path.exists(
os.path.join(sysconfig.get_config_vars()['INCLUDEPY'], 'Python.h')):
extensions = []
# Delete old versions with old names of scripts and packages (chemistry and
# ParmedTools for packages, parmed.py and xparmed.py for scripts)
def deldir(folder):
try:
shutil.rmtree(folder)
except OSError:
sys.stderr.write(
'Could not remove old package %s; you should make sure\n'
'this is completely removed in order to make sure you\n'
'do not accidentally use the old version of ParmEd\n' %
folder
)
def delfile(file):
try:
os.unlink(file)
except OSError:
sys.stderr.write(
'Could not remove old script %s; you should make sure\n'
'this is completely removed in order to make sure you\n'
'do not accidentally use the old version of ParmEd\n' %
file
)
for folder in sys.path:
folder = os.path.realpath(os.path.abspath(folder))
if folder == os.path.realpath(os.path.abspath('.')): continue
chem = os.path.join(folder, 'chemistry')
pmdtools = os.path.join(folder, 'ParmedTools')
pmd = os.path.join(folder, 'parmed.py')
xpmd = os.path.join(folder, 'xparmed.py')
pmdc = os.path.join(folder, 'parmed.pyc')
xpmdc = os.path.join(folder, 'xparmed.pyc')
if os.path.isdir(chem): deldir(chem)
if os.path.isdir(pmdtools): deldir(pmdtools)
if os.path.exists(pmd): delfile(pmd)
if os.path.exists(xpmd): delfile(xpmd)
if os.path.exists(pmdc): delfile(pmdc)
if os.path.exists(xpmdc): delfile(xpmdc)
for folder in os.getenv('PATH').split(os.pathsep):
pmd = os.path.join(folder, 'parmed.py')
xpmd = os.path.join(folder, 'xparmed.py')
pmdc = os.path.join(folder, 'parmed.pyc')
xpmdc = os.path.join(folder, 'xparmed.pyc')
if os.path.exists(pmd): delfile(pmd)
if os.path.exists(xpmd): delfile(xpmd)
if os.path.exists(pmdc): delfile(pmdc)
if os.path.exists(xpmdc): delfile(xpmdc)
cmdclass = dict(clean=CleanCommand)
cmdclass.update(versioneer.get_cmdclass())
setup(name='ParmEd',
version=versioneer.get_version(),
description='Amber parameter file editor',
author='Jason Swails',
author_email='jason.swails@gmail.com',
url='http://jswails.wikidot.com/parmed',
license='LGPL (or GPL if released with AmberTools)',
packages=packages,
ext_modules=extensions,
cmdclass=cmdclass,
package_data={'parmed.modeller': ['data/*.lib']},
**kws
)