Skip to content

Commit 9d5e533

Browse files
authored
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
1 parent cdbf1b6 commit 9d5e533

File tree

5 files changed

+44
-41
lines changed

5 files changed

+44
-41
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"label": "setup_python_env",
99
"type": "shell",
1010
"linux": {
11-
"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"
11+
"command": "${workspaceFolder}/isaaclab.sh -p ${workspaceFolder}/.vscode/tools/setup_vscode.py"
1212
}
1313
},
1414
{

.vscode/tools/launch.template.json

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
"type": "python",
1010
"request": "launch",
1111
"program": "${file}",
12-
"console": "integratedTerminal",
13-
"env": {
14-
"EXP_PATH": "${workspaceFolder}/_isaac_sim/apps",
15-
"RESOURCE_NAME": "IsaacSim"
16-
},
17-
"envFile": "${workspaceFolder}/.vscode/.python.env",
18-
"preLaunchTask": "setup_python_env"
12+
"console": "integratedTerminal"
1913
},
2014
{
2115
"name": "Python: Attach (windows-x86_64/linux-x86_64)",
@@ -30,27 +24,15 @@
3024
"request": "launch",
3125
"args" : ["--task", "Isaac-Reach-Franka-v0", "--headless"],
3226
"program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/train.py",
33-
"console": "integratedTerminal",
34-
"env": {
35-
"EXP_PATH": "${workspaceFolder}/_isaac_sim/apps",
36-
"RESOURCE_NAME": "IsaacSim"
37-
},
38-
"envFile": "${workspaceFolder}/.vscode/.python.env",
39-
"preLaunchTask": "setup_python_env"
27+
"console": "integratedTerminal"
4028
},
4129
{
4230
"name": "Python: Play Environment",
4331
"type": "python",
4432
"request": "launch",
4533
"args" : ["--task", "Isaac-Reach-Franka-v0", "--num_envs", "32"],
4634
"program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/play.py",
47-
"console": "integratedTerminal",
48-
"env": {
49-
"EXP_PATH": "${workspaceFolder}/_isaac_sim/apps",
50-
"RESOURCE_NAME": "IsaacSim"
51-
},
52-
"envFile": "${workspaceFolder}/.vscode/.python.env",
53-
"preLaunchTask": "setup_python_env"
54-
},
35+
"console": "integratedTerminal"
36+
}
5537
]
5638
}

.vscode/tools/settings.template.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@
6868
"autoDocstring.docstringFormat": "google",
6969
"autoDocstring.guessTypes": true,
7070
// Python environment path
71-
"python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/kit/python/bin/python3",
72-
"python.envFile": "${workspaceFolder}/.vscode/.python.env",
71+
// note: the default interpreter is overridden when user selects a workspace interpreter
72+
// in the status bar. For example, the virtual environment python interpreter
73+
"python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/python.sh",
7374
// ROS distribution
7475
"ros.distro": "noetic",
7576
// Language specific settings

.vscode/tools/setup_vscode.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
"""This script sets up the vs-code settings for the Isaac Lab project.
77
8-
This script merges the python.analysis.extraPaths from the "_isaac_sim/.vscode/settings.json" file into
8+
This script merges the python.analysis.extraPaths from the "{ISAACSIM_DIR}/.vscode/settings.json" file into
99
the ".vscode/settings.json" file.
1010
11-
This is necessary because Isaac Sim 2022.2.1 does not add the necessary python packages to the python path
11+
This is necessary because Isaac Sim 2022.2.1 onwards does not add the necessary python packages to the python path
1212
when the "setup_python_env.sh" is run as part of the vs-code launch configuration.
1313
"""
1414

@@ -20,18 +20,33 @@
2020

2121
ISAACLAB_DIR = pathlib.Path(__file__).parents[2]
2222
"""Path to the Isaac Lab directory."""
23-
ISAACSIM_DIR = os.path.join(ISAACLAB_DIR, "_isaac_sim")
23+
24+
try:
25+
import isaacsim # noqa: F401
26+
27+
isaacsim_dir = os.environ.get("ISAAC_PATH", "")
28+
except ModuleNotFoundError or ImportError:
29+
isaacsim_dir = os.path.join(ISAACLAB_DIR, "_isaac_sim")
30+
31+
# check if the isaac-sim directory exists
32+
if not os.path.exists(isaacsim_dir):
33+
raise FileNotFoundError(
34+
f"Could not find the isaac-sim directory: {isaacsim_dir}. There are two possible reasons for this:\n"
35+
"\t1. The Isaac Sim directory does not exist as a symlink in the Isaac Lab directory.\n"
36+
"\t2. The script could import the 'isaacsim' package. This could be due to the 'isaacsim' package not being "
37+
"installed in the Python environment.\n"
38+
"Please make sure that the Isaac Sim directory exists or that the 'isaacsim' package is installed."
39+
)
40+
41+
ISAACSIM_DIR = isaacsim_dir
2442
"""Path to the isaac-sim directory."""
25-
# check if ISAACSIM_DIR is valid:
26-
if not os.path.isdir(ISAACSIM_DIR):
27-
ISAACSIM_DIR = os.environ.get("ISAACSIM_PATH", "")
2843

2944

3045
def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str:
3146
"""Overwrite the python.analysis.extraPaths in the Isaac Lab settings file.
3247
3348
The extraPaths are replaced with the path names from the isaac-sim settings file that exists in the
34-
"_isaac_sim/.vscode/settings.json" file.
49+
"{ISAACSIM_DIR}/.vscode/settings.json" file.
3550
3651
Args:
3752
isaaclab_settings: The settings string to use as template.
@@ -57,17 +72,24 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str:
5772
settings = settings.group(0)
5873
settings = settings.split('"python.analysis.extraPaths": [')[-1]
5974
settings = settings.split("]")[0]
60-
# change the path names to be relative to the Isaac Lab directory
75+
76+
# read the path names from the isaac-sim settings file
6177
path_names = settings.split(",")
6278
path_names = [path_name.strip().strip('"') for path_name in path_names]
63-
path_names = ['"${workspaceFolder}/_isaac_sim/' + path_name + '"' for path_name in path_names if len(path_name) > 0]
79+
path_names = [path_name for path_name in path_names if len(path_name) > 0]
80+
81+
# change the path names to be relative to the Isaac Lab directory
82+
rel_path = os.path.relpath(ISAACSIM_DIR, ISAACLAB_DIR)
83+
path_names = ['"${workspaceFolder}/' + rel_path + "/" + path_name + '"' for path_name in path_names]
6484

6585
# add the path names that are in the Isaac Lab extensions directory
6686
isaaclab_extensions = os.listdir(os.path.join(ISAACLAB_DIR, "source", "extensions"))
6787
path_names.extend(['"${workspaceFolder}/source/extensions/' + ext + '"' for ext in isaaclab_extensions])
6888

6989
# combine them into a single string
7090
path_names = ",\n\t\t".expandtabs(4).join(path_names)
91+
# deal with the path separator being different on Windows and Unix
92+
path_names = path_names.replace("/", os.sep)
7193

7294
# replace the path names in the Isaac Lab settings file with the path names from the isaac-sim settings file
7395
isaaclab_settings = re.sub(

docs/source/setup/developer.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ To setup the IDE, please follow these instructions:
4141
:align: center
4242
:alt: VSCode Tasks
4343

44-
If everything executes correctly, it should create a file
45-
``.python.env`` in the ``.vscode`` directory. The file contains the python
46-
paths to all the extensions provided by Isaac Sim and Omniverse. This helps
47-
in indexing all the python modules for intelligent suggestions while writing
48-
code.
44+
If everything executes correctly, it should create the following files:
45+
46+
* ``.vscode/launch.json``: Contains the launch configurations for debugging python code.
47+
* ``.vscode/settings.json``: Contains the settings for the python interpreter and the python environment.
4948

5049
For more information on VSCode support for Omniverse, please refer to the
5150
following links:
@@ -64,8 +63,7 @@ python executable provided by Omniverse. This is specified in the
6463
.. code-block:: json
6564
6665
{
67-
"python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/kit/python/bin/python3",
68-
"python.envFile": "${workspaceFolder}/.vscode/.python.env",
66+
"python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/python.sh",
6967
}
7068
7169
If you want to use a different python interpreter (for instance, from your conda environment),

0 commit comments

Comments
 (0)