-
Notifications
You must be signed in to change notification settings - Fork 3
/
fr3py.sh
executable file
·180 lines (166 loc) · 5.75 KB
/
fr3py.sh
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
#!/bin/bash
# Note: This shell script is inspired by the Orbit simulator: https://isaac-FR3Py.github.io/
#==
# Configurations
#==
# Exits if error occurs
set -e
# Set tab-spaces
tabs 4
# get source directory
export FR3PY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
#==
# Helper functions
#==
# extract the python from isaacsim
extract_python_exe() {
# Check if IsaacSim directory manually specified
# Note: for manually build isaacsim, this: _build/linux-x86_64/release
if [ ! -z ${ISAACSIM_PATH} ];
then
# Use local build
build_path=${ISAACSIM_PATH}
else
# Use TeamCity build
build_path=${FR3PY_PATH}/_isaac_sim
fi
# check if using conda
if ! [[ -z "${CONDA_PREFIX}" ]]; then
# use conda python
local python_exe=${CONDA_PREFIX}/bin/python
else
# use python from kit
local python_exe=${build_path}/python.sh
fi
# check if there is a python path available
if [ ! -f "${python_exe}" ]; then
echo "[ERROR] No python executable found at path: ${build_path}" >&2
exit 1
fi
# return the result
echo ${python_exe}
}
# check if input directory is a python extension and install the module
install_FR3Py_extension() {
# retrieve the python executable
python_exe=$(extract_python_exe)
# if the directory contains setup.py then install the python module
if [ -f "$1/setup.py" ];
then
echo -e "\t module: $1"
${python_exe} -m pip install --editable $1
fi
}
# update the vscode settings from template and isaac sim settings
update_vscode_settings() {
echo "[INFO] Setting up vscode settings..."
# retrieve the python executable
python_exe=$(extract_python_exe)
# run the setup script
${python_exe} ${FR3PY_PATH}/.vscode/tools/setup_vscode.py
}
# print the usage description
print_help () {
echo -e "\nusage: $(basename "$0") [-h] [-i] [-e] [-f] [-p] [-s] [-v] [-d] [-c] -- Utility to manage extensions in Orbit."
echo -e "\noptional arguments:"
echo -e "\t-h, --help Display the help content."
echo -e "\t-i, --install Install the extensions inside Isaac FR3Py."
echo -e "\t-f, --format Run pre-commit to format the code and check lints."
echo -e "\t-p, --python Run the python executable (python.sh) provided by Isaac Sim."
# echo -e "\t-s, --sim Run the simulator executable (isaac-sim.sh) provided by Isaac Sim."
echo -e "\t-s, --sim Run the FR3Py Isaac Sim simulation node."
echo -e "\t-v, --vscode Generate the VSCode settings file from template."
echo -e "\n" >&2
}
#==
# Main
#==
# check argument provided
if [ -z "$*" ]; then
echo "[Error] No arguments provided." >&2;
print_help
exit 1
fi
# pass the arguments
while [[ $# -gt 0 ]]; do
# read the key
case "$1" in
-i|--install)
# install the python packages for supported reinforcement learning frameworks
echo "[INFO] Installing extra requirements such as learning frameworks..."
python_exe=$(extract_python_exe)
# install the rl-frameworks specified
${python_exe} -m pip install -e ${FR3PY_PATH}
shift # past argument
;;
-f|--format)
# reset the python path to avoid conflicts with pre-commit
# this is needed because the pre-commit hooks are installed in a separate virtual environment
# and it uses the system python to run the hooks
if [ -n "${CONDA_DEFAULT_ENV}" ]; then
cache_pythonpath=${PYTHONPATH}
export PYTHONPATH=""
fi
# run the formatter over the repository
# check if pre-commit is installed
if ! command -v pre-commit &>/dev/null; then
echo "[INFO] Installing pre-commit..."
pip install pre-commit
fi
# always execute inside the Orbit directory
echo "[INFO] Formatting the repository..."
cd ${FR3PY_PATH}
pre-commit run --all-files
cd - > /dev/null
# set the python path back to the original value
if [ -n "${CONDA_DEFAULT_ENV}" ]; then
export PYTHONPATH=${cache_pythonpath}
fi
shift # past argument
# exit neatly
break
;;
-p|--python)
# run the python provided by isaacsim
python_exe=$(extract_python_exe)
echo "[INFO] Using python from: ${python_exe}"
shift # past argument
${python_exe} $@
# exit neatly
break
;;
# -s|--sim)
# # run the simulator exe provided by isaacsim
# isaacsim_exe=$(extract_isaacsim_exe)
# echo "[INFO] Running isaac-sim from: ${isaacsim_exe}"
# shift # past argument
# ${isaacsim_exe} --ext-folder ${FR3PY_PATH}/source/extensions $@
# # exit neatly
# break
# ;;
-s|--sim)
# run the simulator exe provided by isaacsim
python_exe=$(extract_python_exe)
# install the rl-frameworks specified
${python_exe} ${FR3PY_PATH}/FR3Py/sim/isaac/isaacsim_node.py
# exit neatly
break
;;
-v|--vscode)
# update the vscode settings
update_vscode_settings
shift # past argument
# exit neatly
break
;;
-h|--help)
print_help
exit 1
;;
*) # unknown option
echo "[Error] Invalid argument provided: $1"
print_help
exit 1
;;
esac
done