forked from robotology-legacy/gym-ignition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
167 lines (145 loc) · 5.83 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
# Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.
import os
import platform
import subprocess
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
"""
Custom setuptool extension to define parameters for configuring CMake.
"""
def __init__(self,
name: str,
cmake_configuration: str,
source_dir: str = ''):
Extension.__init__(self, name, sources=[])
self.source_dir = os.path.abspath(source_dir)
self.cmake_configuration = cmake_configuration
class BuildExtension(build_ext):
"""
Setuptool build extension handler.
It processes all the extensions listed in the 'ext_modules' entry.
"""
def run(self):
try:
_ = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError(
"CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
if len(self.extensions) != 1 or not \
isinstance(self.extensions[0], CMakeExtension):
raise RuntimeError("This class can only build one CMakeExtension object")
if platform.system() != "Linux":
raise RuntimeError("Only Linux is currently supported")
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
# In editable mode, do not compile C++.
# Developers should install the project through regular CMake.
# Note that here we use the 'inplace' variable that it switched on by the
# pip '--editable' option.
if self.inplace:
print("Editable install recognized. The CMake project will not be installed.")
return
# Get the temporary external build directory.
# On Ubuntu it will be '/tmp/pip-req-build-<randomseq>/build/linux-x86_64-3.6'.
ext_dir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
# Shared CMake arguments
cmake_args = [
f"-DCMAKE_INSTALL_PREFIX:PATH={ext_dir}",
]
# Apply the selected CMake build type
cfg = ext.cmake_configuration
build_args = ['--config', cfg]
# Handle differences in OS and CMake generators
if platform.system() == "Windows":
# Refer to https://github.com/pybind/cmake_example/blob/master/setup.py
raise NotImplementedError
elif platform.system() == "Darwin":
raise NotImplementedError
elif platform.system() == "Linux":
cmake_args += [
f"-GNinja",
f"-DCMAKE_BUILD_TYPE={cfg}",
]
install_target = "install"
else:
raise RuntimeError(f"Unsupported '{platform.system()}' platform")
# Commands to be executed
configure_command = ['cmake', ext.source_dir] + cmake_args
build_command = ['cmake', '--build', '.'] + build_args
install_command = ['cmake', '--build', '.', '--target', install_target]
print("")
print(f"Build folder: {self.build_temp}")
print("")
print(f"1) Configuring: {configure_command}")
print(f"2) Building : {build_command}")
print(f"3) Installing : {install_command}")
print("")
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
# Call CMake
subprocess.check_call(configure_command, cwd=self.build_temp)
subprocess.check_call(build_command, cwd=self.build_temp)
subprocess.check_call(install_command, cwd=self.build_temp)
# Read the contents of your README file
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='gym-ignition',
author="Diego Ferigo",
author_email="[email protected]",
description="Gym-Ignition: A toolkit for developing OpenAI Gym environments "
"simulated with Ignition Gazebo.",
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/robotology/gym-ignition',
keywords="openai gym reinforcement learning environment gazebo robotics ignition",
license="LGPL",
platforms='any',
classifiers=[
"Development Status :: 4 - Beta",
"Operating System :: POSIX :: Linux",
"Topic :: Games/Entertainment :: Simulation",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Framework :: Robot Framework",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: C++",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3 :: Only",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
],
use_scm_version={
'local_scheme': 'dirty-tag',
},
setup_requires=['setuptools_scm'],
python_requires='>=3.6',
install_requires=[
'gym >= 0.13.1',
'numpy',
'gym_ignition_models',
'lxml',
],
extras_require=dict(
website=[
"sphinx",
"sphinx-rtd-theme",
"sphinx-autodoc-typehints",
"sphinx_fontawesome",
"sphinx-multiversion",
"breathe",
],
),
packages=find_packages("python"),
package_dir={'': "python"},
ext_modules=[CMakeExtension(name='InstallAllTargets', cmake_configuration='PyPI')],
cmdclass={
'build_ext': BuildExtension,
},
zip_safe=False,
)