-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
75 lines (60 loc) · 2.39 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
import os
import subprocess
import sys
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name):
Extension.__init__(self, name, sources=[])
class CMakeBuild(build_ext):
def run(self):
try:
subprocess.check_call(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed")
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
extdir = os.path.abspath(
os.path.dirname(self.get_ext_fullpath(ext.name)))
cfg = 'Debug' if self.debug else 'Release'
target_version = str(sys.version_info.major) + "." + str(
sys.version_info.minor)
executable_path = sys.executable
cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
"-DCMAKE_BUILD_TYPE=" + cfg,
"-DSEQUENTIAL_LINE_SEARCH_BUILD_COMMAND_DEMOS=OFF",
"-DSEQUENTIAL_LINE_SEARCH_BUILD_VISUAL_DEMOS=OFF",
"-DSEQUENTIAL_LINE_SEARCH_BUILD_PHOTO_DEMOS=OFF",
"-DSEQUENTIAL_LINE_SEARCH_BUILD_PYTHON_BINDING=ON",
"-DPYBIND11_PYTHON_VERSION=" + target_version,
"-DPYTHON_EXECUTABLE=" + executable_path,
]
cmake_list_dir = os.path.abspath(os.path.dirname(__file__))
configure_command = ['cmake', cmake_list_dir] + cmake_args
build_command = ['cmake', '--build', '.']
subprocess.check_call(configure_command, cwd=self.build_temp)
subprocess.check_call(build_command, cwd=self.build_temp)
setup(
name="pySequentialLineSearch",
version="0.4",
author="Yuki Koyama",
author_email="[email protected]",
description="Python bindings of sequential line search",
long_description="",
long_description_content_type="text/markdown",
ext_modules=[CMakeExtension("pySequentialLineSearch")],
url="https://github.com/yuki-koyama/sequential-line-search",
packages=find_packages(),
install_requires=["numpy"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
],
python_requires=">=3.6",
cmdclass=dict(build_ext=CMakeBuild),
zip_safe=False,
)