forked from google-deepmind/spiral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
99 lines (79 loc) · 2.82 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
# Copyright 2019 DeepMind Technologies Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Install script for setuptools."""
import os
import subprocess
import sys
from setuptools import Extension
from setuptools import find_packages
from setuptools import setup
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name, cmake_lists_dir=".", **kwargs):
Extension.__init__(self, name, sources=[], **kwargs)
self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)
class CMakeBuildExt(build_ext):
"""Build extension handling building C/C++ files with CMake."""
def run(self):
try:
subprocess.check_output(["cmake", "--version"])
except OSError:
raise RuntimeError("Cannot find CMake executable")
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
self.configure_cmake(ext)
self.build_cmake(ext)
def configure_cmake(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cfg = "Debug" if self.debug else "Release"
configure_cmd = ["cmake", ext.cmake_lists_dir]
configure_cmd += [
"-DCMAKE_BUILD_TYPE={}".format(cfg),
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}/spiral/environments".format(
cfg.upper(), extdir),
"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}".format(
cfg.upper(), self.build_temp),
"-DPYTHON_EXECUTABLE:FILEPATH={}".format(sys.executable),
]
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call(configure_cmd, cwd=self.build_temp)
def build_cmake(self, ext):
cfg = "Debug" if self.debug else "Release"
subprocess.check_call(["cmake", "--build", ".", "--config", cfg],
cwd=self.build_temp)
spiral_extension = CMakeExtension("spiral")
setup(
name="spiral",
version="1.0",
author="DeepMind",
license="Apache License, Version 2.0",
packages=find_packages(include=["spiral*"]),
python_requires=">=3.6",
setup_requires=[],
install_requires=[
"tensorflow>=1.14,<2",
"tensorflow-hub",
"dm-sonnet>=1.35,<2",
"dm-env",
"six",
"scipy",
"numpy",
],
ext_modules=[spiral_extension],
cmdclass={
"build_ext": CMakeBuildExt,
},
)