-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup.py
More file actions
182 lines (150 loc) · 5.5 KB
/
setup.py
File metadata and controls
182 lines (150 loc) · 5.5 KB
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
import os
import subprocess
import platform
import logging
import shutil
from setuptools import setup
from setuptools.command.install import install
from setuptools.command.develop import develop
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
SOFA_DOWNLOAD_URLS = {
"Linux": "https://github.com/sofa-framework/sofa/releases/download/v24.06.00/SOFA_v24.06.00_Linux.zip",
"Darwin": "https://github.com/sofa-framework/sofa/releases/download/v24.06.00/SOFA_v24.06.00_MacOS.zip",
"Windows": "https://github.com/sofa-framework/sofa/releases/download/v24.06.00/SOFA_v24.06.00_Win64.zip",
}
PYTHON_VERSION = "3.10"
INSTALL_COMMANDS = {
"wget": {
"Linux": "sudo apt install wget",
"Darwin": "brew install wget",
"Windows": "choco install wget",
},
"unzip": {
"Linux": "sudo apt install unzip",
"Darwin": "brew install unzip",
"Windows": "choco install unzip",
},
}
class SOFAInstallCommand(install):
"""Customized install command to optionally install SOFA."""
def run(self):
# Check if manual sofa install environment variable (SKIP_SOFA) is set
skip_sofa = os.environ.get("SKIP_SOFA", "0")
if skip_sofa == "1":
logger.warning("Skipping SOFA installation. Make sure to install SOFA manually.")
else:
download_and_install_sofa()
# Proceed with normal installation
install.run(self)
class SOFADevelopCommand(develop):
"""Customized develop command to optionally install SOFA."""
def run(self):
# Check if manual sofa install environment variable (SKIP_SOFA) is set
skip_sofa = os.environ.get("SKIP_SOFA", "0")
if skip_sofa == "1":
logger.warning("Skipping SOFA installation. Make sure to install SOFA manually.")
else:
download_and_install_sofa()
# Proceed with normal installation
develop.run(self)
def download_and_install_sofa():
# Check if the required Python version is installed
python_version = platform.python_version()
main_python_version = ".".join(python_version.split(".")[:2])
if main_python_version != PYTHON_VERSION:
raise Exception(
f"Python version {PYTHON_VERSION} is required. Found {python_version}."
)
# Check if the CPU architecture is x86_64
cpu_arch = platform.machine()
if cpu_arch != "x86_64":
raise Exception(
f"CPU architecture x86_64 is required. Found {cpu_arch}. Please install SOFA manually."
)
# Determine platform and get the corresponding download URL
download_url = SOFA_DOWNLOAD_URLS[platform.system()]
file_name = download_url.split("/")[-1]
org_dir_name = file_name.split(".zip")[0]
sofa_dir_name = "SOFA"
which_command = "which" if platform.system() != "Windows" else "where"
# Assert that wget, unzip, and rm are available
if subprocess.run([which_command, "wget"]).returncode != 0:
raise Exception(
f"wget is not installed. Please install it with {INSTALL_COMMANDS['wget'][platform.system()]}"
)
if subprocess.run([which_command, "unzip"]).returncode != 0:
raise Exception(
f"unzip is not installed. Please install it with {INSTALL_COMMANDS['unzip'][platform.system()]}"
)
# Download SOFA and extract it
logger.info(f"Downloading SOFA from {download_url}")
subprocess.run(["wget", download_url])
logger.info(f"Extracting SOFA")
subprocess.run(["unzip", file_name])
os.remove(file_name)
# Move extracted directory to "SOFA", overwrite if necessary
if os.path.exists(sofa_dir_name):
shutil.rmtree(sofa_dir_name)
os.rename(org_dir_name, sofa_dir_name)
# Set environment variables
sofa_root = os.path.abspath(sofa_dir_name)
sofa_python_root = os.path.join(sofa_root, "plugins", "SofaPython3")
sofa_python_libs = os.path.join(sofa_python_root, "lib", "python3", "site-packages")
python_pkg_path = (
subprocess.check_output(
[
"python3",
"-c",
'import sysconfig; print(sysconfig.get_paths()["purelib"])',
]
)
.strip()
.decode("utf-8")
)
# Check if the SOFA Python libraries are already installed, and remove them if necessary,
# then create symbolic links.
for lib in ["Sofa", "SofaRuntime", "SofaTypes", "splib"]:
if os.path.exists(os.path.join(python_pkg_path, lib)):
os.remove(os.path.join(python_pkg_path, lib))
os.symlink(
os.path.join(sofa_python_libs, lib), os.path.join(python_pkg_path, lib)
)
logger.info(f"SOFA installed successfully at {sofa_root}")
setup(
name="sofa_env",
version="1.0.0",
description="Gymnasium wrapper for SOFA simulations",
author="Paul Maria Scheikl",
author_email="pscheik1@jhu.edu",
packages=["sofa_env"],
install_requires=[
"numpy",
"gymnasium",
"pyglet==1.5.21",
"pygame",
"PyOpenGL==3.1.7",
"PyOpenGL-accelerate",
"Sphinx",
"sphinx-tabs",
"sphinx_rtd_theme",
"sphinx-autobuild",
"autodocsumm",
"opencv-python",
"matplotlib",
"tqdm",
"requests",
"numba",
"inputs",
"numpy-stl",
"open3d",
"pytest",
"filelock",
"scipy",
],
python_requires=">=3.9",
cmdclass={
"install": SOFAInstallCommand,
"develop": SOFADevelopCommand,
},
)