From 26a81a6accf67cf8da6d1efdf75bfe00d65271fd Mon Sep 17 00:00:00 2001 From: Mayank Mittal <12863862+Mayankm96@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:19:01 +0200 Subject: [PATCH] Fixes isaaclab.sh script to deal with local system python (#649) # 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 --- .vscode/tools/setup_vscode.py | 5 +++ docker/Dockerfile.pip | 4 +-- isaaclab.sh | 61 +++++++++++++---------------------- 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index 7750be6f9f..0543766e9d 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -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): diff --git a/docker/Dockerfile.pip b/docker/Dockerfile.pip index 5053638c11..21d9bb3e90 100644 --- a/docker/Dockerfile.pip +++ b/docker/Dockerfile.pip @@ -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 diff --git a/isaaclab.sh b/isaaclab.sh index f3f27c90ee..d3166b4f48 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -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 @@ -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 @@ -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} } @@ -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