forked from BlueBrain/MorphIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
129 lines (105 loc) · 4 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
'''morphio setup.py
It is more or less a wrapper to call 'cmake' and 'cmake --build'
'''
import os
import platform
import re
import subprocess
import sys
from distutils.version import LooseVersion
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
MIN_CPU_CORES = 2
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
def find_cmake():
for candidate in ['cmake', 'cmake3']:
try:
out = subprocess.check_output([candidate, '--version'])
cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)',
out.decode()).group(1))
if cmake_version >= '3.2.0':
return candidate
except OSError:
pass
raise RuntimeError("CMake >= 3.2.0 must be installed to build MorphIO")
def get_cpu_count():
try:
return len(os.sched_getaffinity(0)) # linux only
except:
pass
try:
return os.cpu_count() # python 3.4+
except:
return 1 # default
class CMakeBuild(build_ext):
user_options = build_ext.user_options + [
("cmake-defs=", None, "Additional CMake definitions, comma split")
]
def initialize_options(self):
build_ext.initialize_options(self)
self.cmake_defs = None
def run(self):
cmake = find_cmake()
for ext in self.extensions:
self.build_extension(ext, cmake)
def build_extension(self, ext, cmake):
extdir = os.path.abspath(
os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DMORPHIO_VERSION_STRING=' + self.distribution.get_version(),
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DHIGHFIVE_EXAMPLES=OFF',
'-DHIGHFIVE_UNIT_TESTS=OFF',
]
if self.cmake_defs:
cmake_args += ["-D" + opt for opt in self.cmake_defs.split(",")]
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
if platform.system() == "Windows":
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(
cfg.upper(),
extdir)]
cmake_args += ['-G', os.getenv('MORPHIO_CMAKE_GENERATOR',
"Visual Studio 15 2017 Win64")]
else:
cmake_args += ['-DCMAKE_BUILD_TYPE={}'.format(cfg),
'-DMorphIO_CXX_WARNINGS=OFF',
]
build_args += ["--", "-j{}".format(max(MIN_CPU_CORES, get_cpu_count())),
]
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call([cmake, ext.sourcedir] + cmake_args, cwd=self.build_temp)
subprocess.check_call([cmake, '--build', '.', '--target', '_morphio'] + build_args, cwd=self.build_temp)
with open('README.rst') as f:
long_description = f.read()
setup(
name='MorphIO',
author='Blue Brain Project, EPFL',
description='A neuron morphology IO library',
long_description=long_description,
long_description_content_type='text/x-rst',
install_requires=['numpy>=1.14.1'],
extras_require={
'docs': ['sphinx-bluebrain-theme'],
},
url='https://github.com/BlueBrain/MorphIO/',
ext_modules=[CMakeExtension('morphio._morphio')],
cmdclass=dict(build_ext=CMakeBuild),
packages=['morphio', 'morphio.mut', 'morphio.vasculature'],
license="LGPLv3",
keywords=('computational neuroscience',
'morphology',
'neuron'
'neurolucida'
'neuromorphology'),
zip_safe=False,
classifiers=[
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
],
use_scm_version=True,
setup_requires=['setuptools_scm'],
)