Unverified Commit ed94e762 authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Generates vscode settings with python paths for extensions (#32)

* adds utility to generate vscode settings with extra python paths
* adds flag to create vscode settings in orbit.sh
* updates docs with vscode flag
* updates comment in gitignore
parent b6781f3f
......@@ -24,6 +24,8 @@
# IDE
**/.idea/
**/.vscode/.**
# Include all but settings.json: auto-generated using the template in .vscode/tools/settings.template.json
.vscode/settings.json
# Outputs
**/output/*
......
......@@ -2,7 +2,7 @@
"files.associations": {
"*.tpp": "cpp",
"*.kit": "toml",
"*.rst": "restructuredtext",
"*.rst": "restructuredtext"
},
"editor.rulers": [120],
......@@ -25,7 +25,7 @@
"cpp",
"asciidoc",
"python",
"restructuredtext",
"restructuredtext"
],
"cSpell.words": [
"literalinclude",
......@@ -39,7 +39,7 @@
"robomimic",
"teleoperation",
"xform",
"numpy",
"numpy"
],
// This enables python language server. Seems to work slightly better than jedi:
"python.languageServer": "Pylance",
......@@ -66,5 +66,8 @@
},
"[restructuredtext]": {
"editor.tabSize": 2
}
},
// Python extra paths
// Note: this is filled up when "./orbit.sh -i" is run
"python.analysis.extraPaths": []
}
# Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES, ETH Zurich, and University of Toronto
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
"""
This script merges the python.analysis.extraPaths from the "_isaac_sim/.vscode/settings.json" file into
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
when the "setup_python_env.sh" is run as part of the vs-code launch configuration.
"""
import re
import os
ORBIT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
"""Path to the orbit directory."""
ISAACSIM_DIR = os.path.join(ORBIT_DIR, "_isaac_sim")
"""Path to the isaac-sim directory."""
def main():
# isaac-sim settings
isaacsim_vscode_filename = os.path.join(ISAACSIM_DIR, ".vscode/settings.json")
# read the path names from the isaac-sim settings file
with open(isaacsim_vscode_filename) as f:
vscode_settings = f.read()
# extract the path names
# search for the python.analysis.extraPaths section and extract the contents
settings = re.search(r"\"python.analysis.extraPaths\": \[.*?\]", vscode_settings, flags=re.MULTILINE | re.DOTALL)
settings = settings.group(0)
settings = settings.split('"python.analysis.extraPaths": [')[-1]
settings = settings.split("]")[0]
# change the path names to be relative to the orbit directory
path_names = settings.split(",")
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]
# combine them into a single string
path_names = ",\n\t\t".expandtabs(4).join(path_names)
# read the orbit template settings file
orbit_vscode_template_filename = os.path.join(ORBIT_DIR, ".vscode/tools/settings.template.json")
with open(orbit_vscode_template_filename) as f:
orbit_template_settings = f.read()
# replace the path names in the orbit settings file with the path names from the isaac-sim settings file
orbit_settings = re.sub(
r"\"python.analysis.extraPaths\": \[.*?\]",
'"python.analysis.extraPaths": [\n\t\t'.expandtabs(4) + path_names + "\n\t]".expandtabs(4),
orbit_template_settings,
flags=re.DOTALL,
)
# add template notice to the top of the file
header_message = (
"// This file is a template and is automatically generated by the setup_vscode.py script.\n"
"// Do not edit this file directly.\n"
"// \n"
f"// Generated from: {orbit_vscode_template_filename}\n"
)
orbit_settings = header_message + orbit_settings
# write the orbit settings file
orbit_vscode_filename = os.path.join(ORBIT_DIR, ".vscode/settings.json")
with open(orbit_vscode_filename, "w") as f:
f.write(orbit_settings)
if __name__ == "__main__":
main()
......@@ -140,7 +140,7 @@ utilities to manage extensions:
./orbit.sh --help
usage: orbit.sh [-h] [-i] [-e] [-f] [-p] [-s] -- Utility to manage extensions in Isaac Orbit.
usage: orbit.sh [-h] [-i] [-e] [-f] [-p] [-s] [-v] -- Utility to manage extensions in Isaac Orbit.
optional arguments:
-h, --help Display the help content.
......@@ -149,6 +149,7 @@ utilities to manage extensions:
-f, --format Run pre-commit to format the code and check lints.
-p, --python Run the python executable (python.sh) provided by Isaac Sim.
-s, --sim Run the simulator executable (isaac-sim.sh) provided by Isaac Sim.
-v, --vscode Generate the VSCode settings file from template.
The executable automatically fetches the python bundled with Isaac
Sim, using ``./orbit.sh -p`` command. To not restrict running commands
......
......@@ -75,9 +75,18 @@ install_orbit_extension() {
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_isaacsim_python)
# run the setup script
${python_exe} ${ORBIT_PATH}/.vscode/tools/setup_vscode.py
}
# print the usage description
print_help () {
echo -e "\nusage: $(basename "$0") [-h] [-i] [-e] [-f] [-p] [-s] -- Utility to manage extensions in Isaac Orbit."
echo -e "\nusage: $(basename "$0") [-h] [-i] [-e] [-f] [-p] [-s] [-v] -- Utility to manage extensions in Isaac Orbit."
echo -e "\noptional arguments:"
echo -e "\t-h, --help Display the help content."
echo -e "\t-i, --install Install the extensions inside Isaac Orbit."
......@@ -85,6 +94,7 @@ print_help () {
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-v, --vscode Generate the VSCode settings file from template."
echo -e "\n" >&2
}
......@@ -115,6 +125,8 @@ while [[ $# -gt 0 ]]; do
find -L "${ORBIT_PATH}/source/extensions" -mindepth 1 -maxdepth 1 -type d -exec bash -c 'install_orbit_extension "{}"' \;
# unset local variables
unset install_orbit_extension
# setup vscode settings
update_vscode_settings
shift # past argument
;;
-e|--extra)
......@@ -122,8 +134,24 @@ while [[ $# -gt 0 ]]; do
echo "[INFO] Installing extra requirements such as learning frameworks..."
python_exe=$(extract_isaacsim_python)
# install the rl-frameworks specified
${python_exe} -m pip install -e ${ORBIT_PATH}/source/extensions/omni.isaac.orbit_envs[all]
${python_exe} ${ORBIT_PATH}/source/extensions/omni.isaac.orbit_envs[all]
shift # past argument
;;
-f|--format)
# 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
echo "[INFO] Formatting the repository..."
# always execute inside the Orbit directory
cd "${ORBIT_PATH}"
pre-commit run --all-files
cd -
shift # past argument
# exit neatly
break
;;
-p|--python)
# run the python provided by isaacsim
......@@ -143,18 +171,9 @@ while [[ $# -gt 0 ]]; do
# exit neatly
break
;;
-f|--format)
# 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
echo "[INFO] Formatting the repository..."
# always execute inside the Orbit directory
cd "${ORBIT_PATH}"
pre-commit run --all-files
cd -
-v|--vscode)
# update the vscode settings
update_vscode_settings
shift # past argument
# exit neatly
break
......
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