-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
101 lines (84 loc) · 3.54 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
import os
import pathlib
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as build_ext_orig
from shutil import copytree, copy as copyfile
class CMakeExtension(Extension):
def __init__(self, name):
# don't invoke the original build_ext for this special extension
super().__init__(name, sources=[])
class build_ext(build_ext_orig):
def run(self):
for ext in self.extensions:
self.build_cmake(ext)
super().run()
def build_cmake(self, ext):
cwd = pathlib.Path().absolute()
# these dirs will be created in build_py, so if you don't have
# any python sources to bundle, the dirs will be missing
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
extdir.mkdir(parents=True, exist_ok=True)
print(f'build_temp: {build_temp}')
print(f'extdir: {extdir}')
# example of cmake args
config = 'Debug' if self.debug else 'Release'
cmake_args = [
'-DDOWNLOAD_DEPENDENCIES=ON',
'-DTRY_SYSTEM_DEPENDENCIES=OFF',
'-DCPM_SOURCE_CACHE=' + str(package_root / 'CPM_CACHE'), # Use local CPM cache
'-DWITH_GROMACS=OFF',
'-DWITH_OPENBABEL=OFF',
'-DWITH_TNG=OFF',
'-DMAKE_TEST=OFF',
'-DMAKE_EXAMPLES=OFF',
'-DMAKE_TOOLS=OFF',
#'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute() / 'pteros'),
'-DCMAKE_BUILD_TYPE=' + config,
'-DPY_INST_DIR=' + str(extdir.parent.absolute()),
#'-DCMAKE_INSTALL_PREFIX=' + str(build_temp / 'tmp_install'),
]
# example of build args
build_args = [
'--config', config,
'--', f'-j{os.cpu_count()}'
]
os.chdir(str(build_temp))
self.spawn(['cmake', str(cwd)] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.', '--target', 'install'] + build_args)
#self.spawn(['cmake', '--build', '.'] + build_args)
# Troubleshooting: if fail on line above then delete all possible
# temporary CMake files including "CMakeCache.txt" in top level dir.
os.chdir(str(cwd))
# Before running setup we need to form a correct file structure for setup.py
# We create a pteros directory and copy necessary *py files there
cwd = pathlib.Path().absolute()
package_root = cwd/'_pteros'
copytree(cwd/'src'/'python'/'pteros', package_root, dirs_exist_ok=True)
setup(
name='pteros',
version='3.0',
author='Semen Yesylevskyy',
author_email='yesint4@yahoo.com',
description='Pteros molecular modeling library',
long_description=open("./README.md", 'r').read(),
long_description_content_type="text/markdown",
keywords="molecular modeling, extension, molecular dynamics",
classifiers=["Intended Audience :: Science/Research",
"Intended Audience :: Information Technology",
"License :: OSI Approved :: Artistic License",
"Natural Language :: English",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Python",
],
license='Artistic License',
packages=['pteros','pteros.extras'],
package_dir={'pteros':'_pteros', 'pteros.extras':'_pteros/extras'},
ext_modules=[CMakeExtension('pteros')],
cmdclass={
'build_ext': build_ext,
}
)