-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
71 lines (61 loc) · 2.46 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
import os
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from distutils.util import convert_path
# hack to make it work in virtualenv
import sysconfig
cfg = sysconfig.get_config_vars()
pylib = os.path.join(cfg['LIBDIR'], cfg['LDLIBRARY'])
pyinc = cfg['INCLUDEPY']
pyver = cfg['VERSION']
# versioning
main_ns = {}
ver_path = convert_path('tomocam/_version.py')
with open(ver_path) as ver_file:
exec(ver_file.read(), main_ns)
class CMakeExtension(Extension):
"""
setuptools.Extension for cmake
"""
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuildExt(build_ext):
"""
setuptools build_exit which builds using cmake & make
You can add cmake args with the CMAKE_COMMON_VARIABLES environment variable
"""
def build_extension(self, ext):
if isinstance(ext, CMakeExtension):
output_dir = os.path.abspath(
os.path.dirname(
self.get_ext_fullpath(ext.name)))
build_type = 'Debug' if self.debug else 'Release'
cmake_args = ['cmake',
ext.sourcedir,
'-DUSING_SETUP_PY:BOOL=ON',
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + output_dir,
'-DCMAKE_BUILD_TYPE=' + build_type,
'-DPYBIND11_PYTHON_VERSION=' + pyver,
'-DPYTHON_LIBRARY=' + pylib,
'-DPYTHON_INCLUDE_DIR=' + pyinc
]
cmake_args.extend([x for x in os.environ.get('CMAKE_COMMON_VARIABLES', '').split(' ') if x])
env = os.environ.copy()
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call(cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(['make', '-j'], cwd=self.build_temp, env=env)
print()
else:
super().build_extension(ext)
setup(name='tomocam',
author ='Dinesh Kumar',
version = main_ns['__version__'],
description = "GPU based CT reconstruction parackge developed by CAMERA/LBL",
packages = [ 'tomocam' ],
license = "Tomocam Copyright (c) 2018",
ext_modules = [ CMakeExtension('tomocam.cTomocam', os.getcwd()) ],
cmdclass = {'build_ext' : CMakeBuildExt }
)