-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py.tmpl
112 lines (95 loc) · 4.09 KB
/
setup.py.tmpl
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
#!/usr/bin/env python
import os, sys, subprocess, platform
import mpi4py
import numpy as np
from distutils.core import setup, Extension
from distutils.command import build_ext
from os.path import exists, abspath, dirname, join
cmake_cmd_args = []
for f in sys.argv:
if f.startswith('-D'):
cmake_cmd_args.append(f)
class CMakeExtension(Extension):
def __init__(self, name, target='all', cmake_lists_dir='.', **kwa):
Extension.__init__(self, name, sources=[], **kwa)
self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)
self.target = target
class cmake_build_ext(build_ext.build_ext):
def build_extensions(self):
# Ensure that CMake is present and working
try:
out = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError('Cannot find CMake executable')
options = { 'debug': False }
if os.environ.get('NEUROH5_DEBUG', False):
options['debug'] = True
for ext in self.extensions:
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cfg = 'Debug' if options.get('debug', False) else 'Release'
cmake_args = [
'-DCMAKE_BUILD_TYPE=%s' % cfg,
# Ask CMake to place the resulting library in the directory
# containing the extension
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir),
# Other intermediate static libraries are placed in a
# temporary build directory instead
'-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), self.build_temp),
# Hint CMake to use the same Python executable that
# is launching the build, prevents possible mismatching if
# multiple versions of Python are installed
'-DPYTHON_EXECUTABLE={}'.format(sys.executable),
# Add other project-specific CMake arguments if needed
# ...
]
# We can handle some platform-specific settings at our discretion
if platform.system() == 'Windows':
plat = ('x64' if platform.architecture()[0] == '64bit' else 'Win32')
cmake_args += [
# These options are likely to be needed under Windows
'-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE',
'-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir),
]
# Assuming that Visual Studio and MinGW are supported compilers
if self.compiler.compiler_type == 'msvc':
cmake_args += [
'-DCMAKE_GENERATOR_PLATFORM=%s' % plat,
]
else:
cmake_args += [
'-G', 'MinGW Makefiles',
]
cmake_args += cmake_cmd_args
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
# Config
subprocess.check_call(['cmake', ext.cmake_lists_dir] + cmake_args,
cwd=self.build_temp)
# Build
subprocess.check_call(['cmake', '--build', '.', '--config', cfg, '--target', ext.target],
cwd=self.build_temp)
setup(
name='NeuroH5',
package_dir = {'': 'python'},
packages = ["neuroh5"],
version='@NEUROH5_VERSION@',
maintainer = "Ivan Raikov",
maintainer_email = "ivan.g.raikov@gmail.com",
description = "NeuroH5 library",
url = "http://github.com/iraikov/neuroh5",
include_package_data=True,
install_requires=[
'click', 'h5py', 'numpy', 'mpi4py'
],
entry_points='''
[console_scripts]
initrange=neuroh5.initrange:cli
initprj=neuroh5.initprj:cli
importdbs=neuroh5.importdbs:cli
importcoords=neuroh5.importcoords:cli
''',
cmdclass = {'build_ext': cmake_build_ext},
ext_modules = [
CMakeExtension('neuroh5.io', target='python_neuroh5_io')
]
)