-
Notifications
You must be signed in to change notification settings - Fork 20
/
setup.py
127 lines (102 loc) · 3.89 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
import distutils.sysconfig as sysconfig
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from shutil import copyfile, copy
from glob import glob
import shutil as sh
from subprocess import call, check_output
from platform import system
import os
import sys
import distutils
import platform
class get_pybind_include(object):
"""Helper class to determine the pybind11 include path
The purpose of this class is to postpone importing pybind11
until it is actually installed, so that the ``get_include()``
method can be invoked. """
def __init__(self, user=False):
try:
import pybind11
pybind11
except ImportError:
if call([sys.executable, '-m', 'pip', 'install', 'pybind11']):
raise RuntimeError('pybind11 install failed.')
self.user = user
def __str__(self):
import pybind11
return pybind11.get_include(self.user)
cmake_args = []
# What variables from the environment do we wish to pass on to cmake as variables?
cmake_env_vars = ('CMAKE_GENERATOR', 'CMAKE_GENERATOR_PLATFORM', 'CMAKE_OSX_ARCHITECTURES')
for cmake_env_var in cmake_env_vars:
cmake_var = os.environ.get(cmake_env_var)
if cmake_var:
cmake_args.extend([f'-D{cmake_env_var}={cmake_var}'])
# Add parameters to cmake_args and define_macros
cmake_args += ["-DQDLDL_UNITTESTS=OFF"]
cmake_build_flags = []
lib_subdir = []
# Check if windows linux or mac to pass flag
if system() == 'Windows':
cmake_build_flags += ['--config', 'Release']
lib_name = 'qdldlamd.lib'
lib_subdir = ['Release']
else: # Linux or Mac
lib_name = 'libqdldlamd.a'
# Set optimizer flag
if system() != 'Windows':
compile_args = ["-O3"]
else:
compile_args = []
# Compile QDLDL using CMake
current_dir = os.getcwd()
qdldl_dir = os.path.join(current_dir, 'c',)
qdldl_build_dir = os.path.join(qdldl_dir, 'build')
qdldl_lib = [qdldl_build_dir, 'out'] + lib_subdir + [lib_name]
qdldl_lib = os.path.join(*qdldl_lib)
class build_ext_qdldl(build_ext):
def build_extensions(self):
# Create build directory
if not os.path.exists(qdldl_build_dir):
os.makedirs(qdldl_build_dir)
os.chdir(qdldl_build_dir)
try:
check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build qdldl")
# Compile static library with CMake
call(['cmake'] + cmake_args + ['..'])
call(['cmake', '--build', '.', '--target', 'qdldlamd'] +
cmake_build_flags)
# Change directory back to the python interface
os.chdir(current_dir)
# Run extension
build_ext.build_extensions(self)
qdldl = Extension('qdldl',
sources=glob(os.path.join('cpp', '*.cpp')),
include_dirs=[os.path.join('c'),
os.path.join('c', 'qdldl', 'include'),
get_pybind_include(),
get_pybind_include(user=False)],
language='c++',
extra_compile_args=compile_args + ['-std=c++11'],
extra_objects=[qdldl_lib])
def readme():
with open('README.md') as f:
return f.read()
setup(name='qdldl',
version='0.1.7.post5',
author='Bartolomeo Stellato, Paul Goulart, Goran Banjac',
author_email='[email protected]',
description='QDLDL, a free LDL factorization routine.',
long_description=readme(),
long_description_content_type='text/markdown',
package_dir={'qdldl': 'module'},
include_package_data=True, # Include package data from MANIFEST.in
install_requires=["numpy >= 1.7", "scipy >= 0.13.2"],
license='Apache 2.0',
url="https://github.com/oxfordcontrol/qdldl-python/",
cmdclass={'build_ext': build_ext_qdldl},
ext_modules=[qdldl],
)