forked from Farama-Foundation/MAgent2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
160 lines (140 loc) · 5.46 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
import os
import platform
import subprocess
from subprocess import check_output
import setuptools
from setuptools import Extension
from setuptools.command.build_ext import build_ext
###
# Build process:
# cmake .
# make -j threads
# move libmagent -> build/
###
def get_description():
"""Gets the description from the readme."""
with open("README.md") as fh:
long_description = ""
header_count = 0
for line in fh:
if line.startswith("##"):
header_count += 1
if header_count < 2:
long_description += line
else:
break
return header_count, long_description
def get_version():
"""Gets the magent2 version."""
path = "magent2/__init__.py"
with open(path) as file:
lines = file.readlines()
for line in lines:
if line.startswith("__version__"):
return line.strip().split()[-1].strip().strip('"')
raise RuntimeError("bad version data in __init__.py")
class CMakeExtension(Extension):
def __init__(self, name, sourcedir, config=[]):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
self.config = config
class CMakeBuild(build_ext):
def build_extensions(self):
try:
subprocess.check_output(["cmake", "--version"])
except OSError:
raise RuntimeError(
"CMake must be installed to build the extensions: %s"
% ", ".join(ext.name for ext in self.extensions)
)
cfg = "Debug" if self.debug else "Release"
for ext in self.extensions:
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_config_args = [
f"-DCMAKE_BUILD_TYPE={cfg}",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}",
f"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}",
"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}".format(
cfg.upper(), self.build_temp
),
]
make_location = os.path.abspath(self.build_temp)
subprocess.check_call(
["cmake", ext.sourcedir] + cmake_config_args, cwd=make_location
)
print(ext.name)
if platform.system() == "Windows":
str(subprocess.check_output(["cd"], shell=True).decode()).strip()
# subprocess.check_call(["dir"], shell=True)
else:
subprocess.check_call(["pwd"])
print(extdir)
subprocess.check_call(["ls"])
# lib_ext = ""
# lib_name = ""
if platform.system() == "Darwin":
# lib_ext = ".dylib"
# lib_name = "libmagent"
thread_num = check_output(["sysctl", "-n", "hw.ncpu"], encoding="utf-8")
subprocess.check_call(
["make", "-C", make_location, "-j", str(thread_num).rstrip()],
cwd=extdir,
)
elif platform.system() == "Linux":
# lib_ext = ".so"
# lib_name = "libmagent"
thread_num = check_output(["nproc"], encoding="utf-8")
subprocess.check_call(
["make", "-C", make_location, "-j", str(thread_num).rstrip()],
cwd=extdir,
)
elif platform.system() == "Windows":
# lib_ext = ".dll"
# lib_name = "magent"
thread_num = 1
# cmake --build . --target ALL_BUILD --config Release
subprocess.check_call(
["cmake", "--build", ".", "--target", "ALL_BUILD", "--config", cfg],
cwd=make_location,
shell=True,
)
# build_res_dir = extdir + "/magent/build/"
# if not os.path.exists(build_res_dir):
# os.makedirs(build_res_dir)
# lib_name = extdir + "/libmagent" + lib_ext
# subprocess.check_call(
# ["mv", lib_name, build_res_dir]
# )
version = get_version()
header_count, long_description = get_description()
setuptools.setup(
name="magent2",
version=version,
author="Farama Foundation",
author_email="[email protected]",
description="Multi-Agent Reinforcement Learning environments with very large numbers of agents",
url="https://github.com/Farama-Foundation/MAgent",
license="MIT",
license_files=("LICENSE",),
long_description=long_description,
long_description_content_type="text/markdown",
keywords=["Reinforcement Learning", "game", "RL", "AI"],
python_requires=">=3.7",
packages=setuptools.find_packages(),
ext_modules=[CMakeExtension("magent2.libmagent", ".", [])],
install_requires=["numpy>=1.18.0", "pygame==2.1.0"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
include_package_data=True,
cmdclass={"build_ext": CMakeBuild},
)