From d7ad0a352e1697ae2617485b723295f2f0fb0665 Mon Sep 17 00:00:00 2001 From: Pierre LeMoine Date: Mon, 12 Jan 2026 07:30:02 +0100 Subject: [PATCH] vscode config for Bonsai debugging --- .gitignore | 2 + .vscode/launch.json | 24 +++++++++ .vscode/tasks.json | 53 +++++++++++++++++++ .../scripts/dev_environment_vscode_config.py | 24 +++++++++ 4 files changed, 103 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 src/bonsai/scripts/dev_environment_vscode_config.py diff --git a/.gitignore b/.gitignore index 504685d332..5625af298a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,8 @@ venv # Visual Studio Code files .vscode +!.vscode/launch.json +!.vscode/tasks.json .vs # PyCharm files diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..63fa0f352d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Python Debugger: Remote Attach", + "type": "debugpy", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${config:bonsai.localRoot}", + "remoteRoot": "${config:bonsai.remoteRoot}" + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..883373e476 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,53 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Configure bonsai/vscode development environment", + "type": "shell", + "command": "${input:blenderPath}", + "args": [ + "--background", + "--python", "${workspaceFolder}/src/bonsai/scripts/dev_environment_vscode_config.py" + ], + "problemMatcher": [] + }, + { + "label": "Launch blender with debugpy", + "type": "shell", + "command": "blender", + "options": { + "cwd": "${config:bonsai.blenderPath}" + }, + "args": [ + "--python-expr", + "import debugpy; debugpy.listen(5678)" + ], + "problemMatcher": [] + }, + { + "label": "Install debugpy in Blender", + "type": "shell", + "command": "blender", + "options": { + "cwd": "${config:bonsai.blenderPath}" + }, + "args": [ + "--background", + "--python-expr", + "import os, sys, subprocess; path=os.path.abspath(sys.executable); subprocess.call([path, '-m', 'ensurepip']); subprocess.call([path, '-m', 'pip', 'install', '--upgrade', 'debugpy'])" + ], + "problemMatcher": [] + } + + ], + "inputs": [ + { + "id": "blenderPath", + "type": "promptString", + "description": "Enter the path to the blender executable", + "default": "blender" + } + ] +} \ No newline at end of file diff --git a/src/bonsai/scripts/dev_environment_vscode_config.py b/src/bonsai/scripts/dev_environment_vscode_config.py new file mode 100644 index 0000000000..e1643b0aea --- /dev/null +++ b/src/bonsai/scripts/dev_environment_vscode_config.py @@ -0,0 +1,24 @@ + +import bonsai, json, bpy +from pathlib import Path + +repo_path = Path(bonsai.__file__).resolve().parent +install_path = Path(bonsai.__file__).absolute().parent +assert repo_path != install_path, "Run `dev_environment.py` to setup the development environment symlinks first." + +repo_root = repo_path.parent.parent.parent +settings_path = repo_root / ".vscode" / "settings.json" +settings_path.parent.mkdir(parents=True, exist_ok=True) + +settings = json.loads(settings_path.read_text()) if settings_path.exists() else {} +settings.update({ + "bonsai.localRoot": repo_path.as_posix(), + "bonsai.remoteRoot": install_path.as_posix(), + "bonsai.blenderPath": Path(bpy.app.binary_path).parent.as_posix(), +}) +json_data = json.dumps(settings, indent=2) + +settings_path.write_text(json_data) + +print("\n\nBonsai/VSCode development environment configured successfully!\n\n") +