forked from Farama-Foundation/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
239 lines (201 loc) · 8.28 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import os
import shutil
import subprocess
import sys
import warnings
from distutils import sysconfig
from distutils.command.build import build
from multiprocessing import cpu_count
from setuptools import setup
from wheel.bdist_wheel import bdist_wheel
platform = sys.platform
python_version = sysconfig.get_python_version()
build_output_path = "bin"
package_path = build_output_path + "/python" + python_version + "/pip_package"
supported_platforms = ["Linux", "Mac OS X", "Windows"]
package_data = [
"__init__.py",
"bots.cfg",
"freedoom2.wad",
"vizdoom.pk3",
"vizdoom",
"scenarios/*",
"gym_wrapper/*",
]
os.makedirs(package_path, exist_ok=True)
if platform.startswith("win"):
package_data.extend(["vizdoom.exe", "*.pyd", "*.dll"])
library_extension = "lib"
elif platform.startswith("darwin"):
package_data.extend(["vizdoom", "*.so"])
library_extension = "dylib"
elif platform.startswith("linux"):
package_data.extend(["vizdoom", "*.so"])
library_extension = "so"
else:
raise RuntimeError(f"Unsupported platform: {sys.platform}")
def get_vizdoom_version():
try:
import re
with open("CMakeLists.txt") as cmake_file:
lines = cmake_file.read()
version = re.search(r"VERSION\s+([0-9].[0-9].[0-9]+)", lines).group(1)
return version
except Exception:
raise RuntimeError(
"Package version retrieval failed. "
"Most probably something is wrong with this code and "
"you should create an issue at https://github.com/Farama-Foundation/ViZDoom"
)
def get_long_description():
try:
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, "README.md"), encoding="utf-8") as readme_file:
return readme_file.read()
except Exception:
raise RuntimeError(
"Package description retrieval failed. "
"Most probably something is wrong with this code and "
"you should create an issue at https://github.com/Farama-Foundation/ViZDoom"
)
def get_python_library(python_root_dir):
paths_to_check = [
"libs/python{}{}.{}", # Windows Python/Anaconda
"libpython{}.{}m.{}", # Unix
"libpython{}.{}.{}", # Unix
"lib/libpython{}.{}m.{}", # Unix Anaconda
"lib/libpython{}.{}.{}", # Unix Anaconda
]
for path_format in paths_to_check:
path = os.path.join(
python_root_dir,
path_format.format(*python_version.split("."), library_extension),
)
if os.path.exists(path):
return path
return None
class Wheel(bdist_wheel):
def finalize_options(self):
bdist_wheel.finalize_options(self)
# Mark us as not a pure python package
self.root_is_pure = False
def get_tag(self):
python, abi, plat = bdist_wheel.get_tag(self)
return python, abi, plat
class BuildCommand(build):
def run(self):
cpu_cores = max(1, cpu_count() - 1)
python_executable = os.path.realpath(sys.executable)
cmake_arg_list = [
"cmake",
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_PYTHON=ON",
f"-DPYTHON_EXECUTABLE={python_executable}",
]
env_cmake_args = os.getenv("VIZDOOM_CMAKE_ARGS")
if env_cmake_args:
cmake_arg_list += env_cmake_args.split()
warnings.warn(
f"VIZDOOM_CMAKE_ARGS is set, the following arguments will be added to cmake command: {env_cmake_args}"
)
if platform.startswith("win"):
generator = os.getenv("VIZDOOM_BUILD_GENERATOR_NAME")
if not generator:
raise RuntimeError(
"VIZDOOM_BUILD_GENERATOR_NAME is not set"
) # TODO: Improve
deps_root = os.getenv("VIZDOOM_WIN_DEPS_ROOT")
if deps_root is None:
raise RuntimeError("VIZDOOM_WIN_DEPS_ROOT is not set") # TODO: Improve
mpg123_include = os.path.join(deps_root, "libmpg123")
mpg123_lib = os.path.join(deps_root, "libmpg123/libmpg123-0.lib")
mpg123_dll = os.path.join(deps_root, "libmpg123/libmpg123-0.dll")
sndfile_include = os.path.join(deps_root, "libsndfile/include")
sndfile_lib = os.path.join(deps_root, "libsndfile/lib/libsndfile-1.lib")
sndfile_dll = os.path.join(deps_root, "libsndfile/bin/libsndfile-1.dll")
os.environ["OPENALDIR"] = str(os.path.join(deps_root, "openal-soft"))
openal_dll = os.path.join(deps_root, "openal-soft/bin/Win64/OpenAL32.dll")
cmake_arg_list.extend(
[
"-G",
generator,
f"-DMPG123_INCLUDE_DIR={mpg123_include}",
f"-DMPG123_LIBRARIES={mpg123_lib}",
f"-DSNDFILE_INCLUDE_DIR={sndfile_include}",
f"-DSNDFILE_LIBRARY={sndfile_lib}",
]
)
shutil.copy(mpg123_dll, build_output_path)
shutil.copy(sndfile_dll, build_output_path)
shutil.copy(openal_dll, build_output_path)
python_standard_lib = sysconfig.get_python_lib(standard_lib=True)
python_root_dir = os.path.dirname(python_standard_lib)
python_library = get_python_library(python_root_dir)
python_include_dir = sysconfig.get_python_inc()
if python_include_dir and os.path.exists(python_include_dir):
cmake_arg_list.append(f"-DPYTHON_INCLUDE_DIR={python_include_dir}")
if python_library and os.path.exists(python_library):
cmake_arg_list.append(f"-DPYTHON_LIBRARY={python_library}")
if os.path.exists("CMakeCache.txt"):
os.remove("CMakeCache.txt")
try:
if platform.startswith("win"):
if os.path.exists("./src/lib_python/libvizdoom_python.dir"):
shutil.rmtree(
"./src/lib_python/libvizdoom_python.dir"
) # TODO: This is not very elegant, improve
subprocess.check_call(cmake_arg_list)
subprocess.check_call(["cmake", "--build", ".", "--config", "Release"])
else:
subprocess.check_call(cmake_arg_list)
subprocess.check_call(["make", "-j", str(cpu_cores)])
except subprocess.CalledProcessError:
sys.stderr.write(
"\033[1m\nInstallation failed, you may be missing some dependencies. "
"\nPlease check https://github.com/mwydmuch/ViZDoom/blob/master/doc/Building.md "
"for details\n\n\033[0m"
)
raise
build.run(self)
setup(
name="vizdoom",
version=get_vizdoom_version(),
description="ViZDoom is Doom-based AI Research Platform for Reinforcement Learning from Raw Visual Information.",
long_description=get_long_description(),
long_description_content_type="text/markdown",
url="http://vizdoom.cs.put.edu.pl/",
author="Marek Wydmuch, Michał Kempka, Wojciech Jaśkowski, Grzegorz Runc, Jakub Toczek",
author_email="[email protected]",
extras_require={"gym": ["gym==0.26.0", "pygame==2.1.0"]},
install_requires=["numpy", "tqdm"],
tests_require=["psutil"],
packages=["vizdoom"],
package_dir={"vizdoom": package_path},
package_data={"vizdoom": package_data},
include_package_data=True,
cmdclass={"bdist_wheel": Wheel, "build": BuildCommand},
platforms=supported_platforms,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"License :: OSI Approved :: MIT License",
"Programming Language :: C++",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
],
keywords=[
"vizdoom",
"doom",
"ai",
"deep learning",
"reinforcement learning",
"research",
],
)