-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
150 lines (135 loc) · 3.96 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import multiprocessing
import os
import pathlib
from distutils.file_util import copy_file
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext as build_ext_orig
# REQUIREMENTS = [
# line
# for line in pathlib.Path("requirements.txt")
# .read_text()
# .strip()
# .split("\n")
# ]
CPU_COUNT = multiprocessing.cpu_count()
TARGETS = [
{
"name": "thread_pool",
"target": "thread_pool",
"extension_file_name": "thread_pool.so",
"module_directory": "thread_pool",
},
{
"name": "search",
"target": "search",
"extension_file_name": "search.so",
"module_directory": "search",
},
{
"name": "selection",
"target": "selection",
"extension_file_name": "selection.so",
"module_directory": "selection",
},
{
"name": "nn_evaluator",
"target": "nn_evaluator",
"extension_file_name": "nn_evaluator.so",
"module_directory": "evaluator/nn_evaluator",
},
{
"name": "evaluator",
"target": "evaluator",
"extension_file_name": "evaluator.so",
"module_directory": "evaluator",
},
{
"name": "simulation_evaluator",
"target": "simulation_evaluator",
"extension_file_name": "simulation_evaluator.so",
"module_directory": "evaluator/simulation_evaluator",
},
{
"name": "cache",
"target": "cache",
"extension_file_name": "cache.so",
"module_directory": "cache",
},
{
"name": "simple_cache",
"target": "simple_cache",
"extension_file_name": "simple_cache.so",
"module_directory": "cache/simple_cache",
},
{
"name": "game",
"target": "game",
"extension_file_name": "game.so",
"module_directory": "games",
},
{
"name": "connect_four",
"target": "connect_four",
"extension_file_name": "connect_four.so",
"module_directory": "games/connect_four",
},
{
"name": "tic_tac_toe",
"target": "tic_tac_toe",
"extension_file_name": "tic_tac_toe.so",
"module_directory": "games/tic_tac_toe",
},
{
"name": "bandits",
"target": "bandits",
"extension_file_name": "bandits.so",
"module_directory": "games/bandits",
},
]
class CMakeExtension(Extension):
def __init__(self, name):
super().__init__(name, sources=[])
class build_ext(build_ext_orig):
def run(self):
for ext in self.extensions:
self.build_cmake(ext)
super().run()
def build_cmake(self, ext):
cwd = pathlib.Path(__file__).parent.absolute()
build_temp = cwd / self.build_temp
build_lib = cwd / self.build_lib
build_temp.mkdir(parents=True, exist_ok=True)
extdir = cwd / self.get_ext_fullpath(ext.name)
extdir.mkdir(parents=True, exist_ok=True)
config = "Debug" if self.debug else "Release"
os.chdir(str(build_temp))
self.spawn(["cmake", str(cwd)])
if not self.dry_run:
self.spawn(
["cmake"]
+ ["--build", "."]
+ ["--config", config]
+ ["--parallel", str(CPU_COUNT)]
+ ["--target", "all_python"]
)
for target in TARGETS:
copy_file(
src=target["extension_file_name"],
dst=cwd
/ build_lib
/ "pyoaz"
/ target["module_directory"]
/ target["extension_file_name"],
)
os.chdir(str(cwd))
setup(
name="pyoaz",
version="0.1",
packages=find_packages(),
ext_modules=[CMakeExtension("pyoaz")],
# install_requires=REQUIREMENTS,
dependency_links=[
"git+https://www.github.com/keras-team/keras-contrib.git"
],
cmdclass={"build_ext": build_ext},
)