-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py.in
executable file
·142 lines (115 loc) · 4.16 KB
/
setup.py.in
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
130
131
132
133
134
135
136
137
138
139
140
141
142
#!python
from distutils.sysconfig import get_python_lib
from distutils.command.build import build as _build
import glob
import os
import sys
import shutil
import subprocess
from distutils.command.build_py import build_py
# use setuptools by default as per the official advice at:
# packaging.python.org/en/latest/current.html#packaging-tool-recommendations
use_setuptools = True
if use_setuptools:
try:
from setuptools import setup
from setuptools.command.install import install as _install
except ImportError:
use_setuptools = False
else:
from distutils.core import setup
from distutils.command.install import install as _install
def configuration(parent_package='', top_path=None):
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
config.set_options(
ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)
config.add_subpackage(os.path.join("${CMAKE_CURRENT_SOURCE_DIR}/python/gloc"))
return config
def copy_libraries():
'''
Just a hack but necessary for the installation
'''
target_path = "${LIBRARY_OUTPUT_PATH}"
lib_files = [fi for fi in os.listdir(target_path) if ".so" in fi]
print("move library files: {}".format(lib_files))
for fi in lib_files:
shutil.copy(os.path.join(target_path, fi),
os.path.join("${CMAKE_CURRENT_SOURCE_DIR}/python/gloc", fi))
class BuildWithbuild(_build):
_build_opts = _build.user_options
user_options = [
('define=', 'D',
'build <var>:<type>=<value>'),
]
user_options.extend(_build_opts)
def initialize_options(self):
_build.initialize_options(self)
self.define = None
def finalize_options(self):
_build.finalize_options(self)
# The argument parsing will result in self.define being a string, but
# it has to be a list of 2-tuples.
# Multiple symbols can be separated with semi-colons.
if self.define:
defines = self.define.split(';')
self.define = [(s.strip(), None) if '=' not in s else
tuple(ss.strip() for ss in s.split('='))
for s in defines]
build_opts.extend(self.define)
def run(self):
make_build()
# can't use super() here because _build is an old style class in 2.7
_build.run(self)
class InstallWithbuild(_install):
_install_opts = _install.user_options
user_options = [
('define=', 'D',
'build <var>:<type>=<value>'),
]
user_options.extend(_install_opts)
def initialize_options(self):
_install.initialize_options(self)
self.define = None
def finalize_options(self):
_install.finalize_options(self)
# The argument parsing will result in self.define being a string, but
# it has to be a list of 2-tuples.
# Multiple symbols can be separated with semi-colons.
if self.define:
defines = self.define.split(';')
self.define = [(s.strip(), None) if '=' not in s else
tuple(ss.strip() for ss in s.split('='))
for s in defines]
build_opts.extend(self.define)
def run(self):
# can't use super() here because _install is an old style class in 2.7
_install.run(self)
def make_build():
make_cmd = ["make"]
if subprocess.call(make_cmd) != 0:
raise EnvironmentError("error calling build")
copy_libraries()
setup(
name="gloc",
version="0.1.0",
packages=['gloc'],
package_dir={'gloc': "${CMAKE_CURRENT_SOURCE_DIR}/python/gloc"},
package_data={'': ['*.so']},
author='Thomas Latzko',
author_email="[email protected]",
description='Use the CMake build system to make Python modules.',
license='Apache',
keywords='cmake cython build',
url='http://github.com/tlatzko/gloc',
zip_safe=False,
cmdclass={
'build' : BuildWithbuild,
'install' : InstallWithbuild,
}
)