Skip to content

Commit

Permalink
Fixes isaaclab.sh script to deal with local system python (#649)
Browse files Browse the repository at this point in the history
# Description

Realized that #631 did not deal properly with the case when not in a
conda or docker. This MR re-writes the logic to hopefully make the
operation safe.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
  • Loading branch information
Mayankm96 committed Jul 5, 2024
1 parent 97cf1f1 commit 26a81a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .vscode/tools/setup_vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
isaacsim_dir = os.environ.get("ISAAC_PATH", "")
except ModuleNotFoundError or ImportError:
isaacsim_dir = os.path.join(ISAACLAB_DIR, "_isaac_sim")
except EOFError:
print("Unable to trigger EULA acceptance. This is likely due to the script being run in a non-interactive shell.")
print("Please run the script in an interactive shell to accept the EULA.")
print("Skipping the setup of the VSCode settings...")
sys.exit(0)

# check if the isaac-sim directory exists
if not os.path.exists(isaacsim_dir):
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.pip
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# To build the Docker image and run the Docker container, follow the steps below:
#
# 1. Build the Docker image:
# docker build -t isaac-lab:latest -f docker/Dockerfile.pip .
# docker build -t isaac-lab-pip:latest -f docker/Dockerfile.pip .
# 2. Run the Docker container:
# docker run -it --gpus all --rm --network=host --name isaac-lab -v $(pwd):/root/isaaclab isaac-lab:latest
# docker run -it --gpus all --rm --network=host --name isaac-lab -v $(pwd):/root/isaaclab isaac-lab-pip:latest

# Base image: Ubuntu 22.04
FROM ubuntu:22.04 AS base
Expand Down
61 changes: 22 additions & 39 deletions isaaclab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,16 @@ export ISAACLAB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && p

# extract isaac sim path
extract_isaacsim_path() {
# Check if we have pip package installed inside conda environment
if ! [[ -z "${CONDA_PREFIX}" ]]; then
# Use the sym-link path to Isaac Sim directory
local isaac_path=${ISAACLAB_PATH}/_isaac_sim
# If above path is not available, try to find the path using python
if [ ! -d "${isaac_path}" ]; then
# Use the python executable to get the path
local python_exe=${CONDA_PREFIX}/bin/python
local python_exe=$(extract_python_exe)
# Retrieve the path importing isaac sim and getting the environment path
if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then
local isaac_path=$(${python_exe} -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])")
else
# If package not installed, try with the default path
local isaac_path=${ISAACLAB_PATH}/_isaac_sim
fi
elif command -v python &> /dev/null; then
# note: we need to deal with this case because of docker containers
# Retrieve the path importing isaac sim and getting the environment path
if [ $(python -m pip list | grep -c 'isaacsim-rl') ]; then
local isaac_path=$(python -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])")
else
# If package not installed, use an empty path for failure
local isaac_path=''
fi
else
# Use the sym-link path to Isaac Sim directory
local isaac_path=${ISAACLAB_PATH}/_isaac_sim
fi
# check if there is a path available
if [ ! -d "${isaac_path}" ]; then
Expand All @@ -65,21 +52,22 @@ extract_isaacsim_path() {

# extract the python from isaacsim
extract_python_exe() {
# check if using conda
if ! [[ -z "${CONDA_PREFIX}" ]]; then
# use conda python
local python_exe=${CONDA_PREFIX}/bin/python
elif command -v python &> /dev/null; then
# note: we need to deal with this case because of docker containers
if [ $(python -m pip list | grep -c 'isaacsim-rl') ]; then
local python_exe=$(which python)
# default to python in the kit
local python_exe=${ISAACLAB_PATH}/_isaac_sim/python.sh
# if default python is not available, check if conda is activated
if [ ! -f "${python_exe}" ]; then
# check if using conda
if ! [[ -z "${CONDA_PREFIX}" ]]; then
# use conda python
local python_exe=${CONDA_PREFIX}/bin/python
else
# leave a blank path for failure
local python_exe=''
# note: we need to check system python for cases such as docker
# inside docker, if user installed into system python, we need to use that
# otherwise, use the python from the kit
if [ $(python -m pip list | grep -c 'isaacsim-rl') ]; then
local python_exe=$(which python)
fi
fi
else
# use python from kit
local python_exe=${ISAACLAB_PATH}/_isaac_sim/python.sh
fi
# check if there is a python path available
if [ ! -f "${python_exe}" ]; then
Expand All @@ -90,12 +78,6 @@ extract_python_exe() {
echo -e "\t3. Python executable is not available at the default path: ${ISAACLAB_PATH}/_isaac_sim/python.sh" >&2
exit 1
fi
# kit dependencies are built with python 3.10 so any other version will not work
# this is needed in case users have multiple python versions installed and the wrong one is being used
if [ "$(${python_exe} --version | grep -c '3.10')" -eq 0 ]; then
echo "[ERROR] Found Python version: $(${python_exe} --version) while expecting 3.10. Please use the correct python version." >&2
exit 1
fi
# return the result
echo ${python_exe}
}
Expand Down Expand Up @@ -300,8 +282,9 @@ while [[ $# -gt 0 ]]; do
# install the rl-frameworks specified
${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/extensions/omni.isaac.lab_tasks["${framework_name}"]

# check if we are inside a docker container (in that case don't setup VSCode)
if [ -f "/.dockerenv" ]; then
# check if we are inside a docker container or are building a docker image
# in that case don't setup VSCode since it asks for EULA agreement which triggers user interaction
if [ -f /.dockerenv ]; then
echo "[INFO] Running inside a docker container. Skipping VSCode settings setup."
echo "[INFO] To setup VSCode settings, run 'isaaclab -v'."
else
Expand Down

0 comments on commit 26a81a6

Please sign in to comment.