Unverified Commit 455a1748 authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Fixes VSCode settings to work with pip installation of Isaac Sim (#628)

Earlier, the VSCode settings were only made for installation with
binaries. This expected the path to be "_isaac_sim". As many users
reported, this doesn't work if we have PIP installation of Isaac Sim.

This MR fixes the above issue to ensure a smooth setup of vscode.

Fixes #620, #629

## Type of change

- Bug fix (non-breaking change which fixes an issue)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] 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
parent 4264e4f5
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"label": "setup_python_env", "label": "setup_python_env",
"type": "shell", "type": "shell",
"linux": { "linux": {
"command": "export CARB_APP_PATH=${workspaceFolder}/_isaac_sim/kit && export ISAAC_PATH=${workspaceFolder}/_isaac_sim && export EXP_PATH=${workspaceFolder}/_isaac_sim/apps && source ${workspaceFolder}/_isaac_sim/setup_python_env.sh && printenv >${workspaceFolder}/.vscode/.python.env && ${workspaceFolder}/_isaac_sim/python.sh ${workspaceFolder}/.vscode/tools/setup_vscode.py" "command": "${workspaceFolder}/isaaclab.sh -p ${workspaceFolder}/.vscode/tools/setup_vscode.py"
} }
}, },
{ {
......
...@@ -9,13 +9,7 @@ ...@@ -9,13 +9,7 @@
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"program": "${file}", "program": "${file}",
"console": "integratedTerminal", "console": "integratedTerminal"
"env": {
"EXP_PATH": "${workspaceFolder}/_isaac_sim/apps",
"RESOURCE_NAME": "IsaacSim"
},
"envFile": "${workspaceFolder}/.vscode/.python.env",
"preLaunchTask": "setup_python_env"
}, },
{ {
"name": "Python: Attach (windows-x86_64/linux-x86_64)", "name": "Python: Attach (windows-x86_64/linux-x86_64)",
...@@ -30,13 +24,7 @@ ...@@ -30,13 +24,7 @@
"request": "launch", "request": "launch",
"args" : ["--task", "Isaac-Reach-Franka-v0", "--headless"], "args" : ["--task", "Isaac-Reach-Franka-v0", "--headless"],
"program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/train.py", "program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/train.py",
"console": "integratedTerminal", "console": "integratedTerminal"
"env": {
"EXP_PATH": "${workspaceFolder}/_isaac_sim/apps",
"RESOURCE_NAME": "IsaacSim"
},
"envFile": "${workspaceFolder}/.vscode/.python.env",
"preLaunchTask": "setup_python_env"
}, },
{ {
"name": "Python: Play Environment", "name": "Python: Play Environment",
...@@ -44,13 +32,7 @@ ...@@ -44,13 +32,7 @@
"request": "launch", "request": "launch",
"args" : ["--task", "Isaac-Reach-Franka-v0", "--num_envs", "32"], "args" : ["--task", "Isaac-Reach-Franka-v0", "--num_envs", "32"],
"program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/play.py", "program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/play.py",
"console": "integratedTerminal", "console": "integratedTerminal"
"env": { }
"EXP_PATH": "${workspaceFolder}/_isaac_sim/apps",
"RESOURCE_NAME": "IsaacSim"
},
"envFile": "${workspaceFolder}/.vscode/.python.env",
"preLaunchTask": "setup_python_env"
},
] ]
} }
...@@ -68,8 +68,9 @@ ...@@ -68,8 +68,9 @@
"autoDocstring.docstringFormat": "google", "autoDocstring.docstringFormat": "google",
"autoDocstring.guessTypes": true, "autoDocstring.guessTypes": true,
// Python environment path // Python environment path
"python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/kit/python/bin/python3", // note: the default interpreter is overridden when user selects a workspace interpreter
"python.envFile": "${workspaceFolder}/.vscode/.python.env", // in the status bar. For example, the virtual environment python interpreter
"python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/python.sh",
// ROS distribution // ROS distribution
"ros.distro": "noetic", "ros.distro": "noetic",
// Language specific settings // Language specific settings
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
"""This script sets up the vs-code settings for the Isaac Lab project. """This script sets up the vs-code settings for the Isaac Lab project.
This script merges the python.analysis.extraPaths from the "_isaac_sim/.vscode/settings.json" file into This script merges the python.analysis.extraPaths from the "{ISAACSIM_DIR}/.vscode/settings.json" file into
the ".vscode/settings.json" file. the ".vscode/settings.json" file.
This is necessary because Isaac Sim 2022.2.1 does not add the necessary python packages to the python path This is necessary because Isaac Sim 2022.2.1 onwards does not add the necessary python packages to the python path
when the "setup_python_env.sh" is run as part of the vs-code launch configuration. when the "setup_python_env.sh" is run as part of the vs-code launch configuration.
""" """
...@@ -20,18 +20,33 @@ import pathlib ...@@ -20,18 +20,33 @@ import pathlib
ISAACLAB_DIR = pathlib.Path(__file__).parents[2] ISAACLAB_DIR = pathlib.Path(__file__).parents[2]
"""Path to the Isaac Lab directory.""" """Path to the Isaac Lab directory."""
ISAACSIM_DIR = os.path.join(ISAACLAB_DIR, "_isaac_sim")
try:
import isaacsim # noqa: F401
isaacsim_dir = os.environ.get("ISAAC_PATH", "")
except ModuleNotFoundError or ImportError:
isaacsim_dir = os.path.join(ISAACLAB_DIR, "_isaac_sim")
# check if the isaac-sim directory exists
if not os.path.exists(isaacsim_dir):
raise FileNotFoundError(
f"Could not find the isaac-sim directory: {isaacsim_dir}. There are two possible reasons for this:\n"
"\t1. The Isaac Sim directory does not exist as a symlink in the Isaac Lab directory.\n"
"\t2. The script could import the 'isaacsim' package. This could be due to the 'isaacsim' package not being "
"installed in the Python environment.\n"
"Please make sure that the Isaac Sim directory exists or that the 'isaacsim' package is installed."
)
ISAACSIM_DIR = isaacsim_dir
"""Path to the isaac-sim directory.""" """Path to the isaac-sim directory."""
# check if ISAACSIM_DIR is valid:
if not os.path.isdir(ISAACSIM_DIR):
ISAACSIM_DIR = os.environ.get("ISAACSIM_PATH", "")
def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str:
"""Overwrite the python.analysis.extraPaths in the Isaac Lab settings file. """Overwrite the python.analysis.extraPaths in the Isaac Lab settings file.
The extraPaths are replaced with the path names from the isaac-sim settings file that exists in the The extraPaths are replaced with the path names from the isaac-sim settings file that exists in the
"_isaac_sim/.vscode/settings.json" file. "{ISAACSIM_DIR}/.vscode/settings.json" file.
Args: Args:
isaaclab_settings: The settings string to use as template. isaaclab_settings: The settings string to use as template.
...@@ -57,10 +72,15 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: ...@@ -57,10 +72,15 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str:
settings = settings.group(0) settings = settings.group(0)
settings = settings.split('"python.analysis.extraPaths": [')[-1] settings = settings.split('"python.analysis.extraPaths": [')[-1]
settings = settings.split("]")[0] settings = settings.split("]")[0]
# change the path names to be relative to the Isaac Lab directory
# read the path names from the isaac-sim settings file
path_names = settings.split(",") path_names = settings.split(",")
path_names = [path_name.strip().strip('"') for path_name in path_names] path_names = [path_name.strip().strip('"') for path_name in path_names]
path_names = ['"${workspaceFolder}/_isaac_sim/' + path_name + '"' for path_name in path_names if len(path_name) > 0] path_names = [path_name for path_name in path_names if len(path_name) > 0]
# change the path names to be relative to the Isaac Lab directory
rel_path = os.path.relpath(ISAACSIM_DIR, ISAACLAB_DIR)
path_names = ['"${workspaceFolder}/' + rel_path + "/" + path_name + '"' for path_name in path_names]
# add the path names that are in the Isaac Lab extensions directory # add the path names that are in the Isaac Lab extensions directory
isaaclab_extensions = os.listdir(os.path.join(ISAACLAB_DIR, "source", "extensions")) isaaclab_extensions = os.listdir(os.path.join(ISAACLAB_DIR, "source", "extensions"))
...@@ -68,6 +88,8 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: ...@@ -68,6 +88,8 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str:
# combine them into a single string # combine them into a single string
path_names = ",\n\t\t".expandtabs(4).join(path_names) path_names = ",\n\t\t".expandtabs(4).join(path_names)
# deal with the path separator being different on Windows and Unix
path_names = path_names.replace("/", os.sep)
# replace the path names in the Isaac Lab settings file with the path names from the isaac-sim settings file # replace the path names in the Isaac Lab settings file with the path names from the isaac-sim settings file
isaaclab_settings = re.sub( isaaclab_settings = re.sub(
......
...@@ -41,11 +41,10 @@ To setup the IDE, please follow these instructions: ...@@ -41,11 +41,10 @@ To setup the IDE, please follow these instructions:
:align: center :align: center
:alt: VSCode Tasks :alt: VSCode Tasks
If everything executes correctly, it should create a file If everything executes correctly, it should create the following files:
``.python.env`` in the ``.vscode`` directory. The file contains the python
paths to all the extensions provided by Isaac Sim and Omniverse. This helps * ``.vscode/launch.json``: Contains the launch configurations for debugging python code.
in indexing all the python modules for intelligent suggestions while writing * ``.vscode/settings.json``: Contains the settings for the python interpreter and the python environment.
code.
For more information on VSCode support for Omniverse, please refer to the For more information on VSCode support for Omniverse, please refer to the
following links: following links:
...@@ -64,8 +63,7 @@ python executable provided by Omniverse. This is specified in the ...@@ -64,8 +63,7 @@ python executable provided by Omniverse. This is specified in the
.. code-block:: json .. code-block:: json
{ {
"python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/kit/python/bin/python3", "python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/python.sh",
"python.envFile": "${workspaceFolder}/.vscode/.python.env",
} }
If you want to use a different python interpreter (for instance, from your conda environment), If you want to use a different python interpreter (for instance, from your conda environment),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment