Skip to content

Commit

Permalink
fix #1 Append a setting justMyCode to the list of Addon settings
Browse files Browse the repository at this point in the history
  • Loading branch information
satabol committed May 1, 2024
1 parent c49972f commit 642800f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
"default": false,
"description": "Reload addon in Blender when a document is saved."
},
"blender.addon.justMyCode": {
"type": "boolean",
"scope": "resource",
"default": true,
"description": "True - debug addon code only, False - allow debug external python library code."
},
"blender.addon.buildTaskName": {
"type": "string",
"scope": "resource",
Expand Down
4 changes: 2 additions & 2 deletions pythonFiles/include/blender_vscode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
import sys

def startup(editor_address, addons_to_load, allow_modify_external_python):
def startup(editor_address, addons_to_load, allow_modify_external_python, justMyCode):
if bpy.app.version < (2, 80, 34):
handle_fatal_error("Please use a newer version of Blender")

Expand All @@ -14,7 +14,7 @@ def startup(editor_address, addons_to_load, allow_modify_external_python):
path_mappings = load_addons.setup_addon_links(addons_to_load)

from . import communication
communication.setup(editor_address, path_mappings)
communication.setup(editor_address, path_mappings, justMyCode)

load_addons.load(addons_to_load)

Expand Down
10 changes: 6 additions & 4 deletions pythonFiles/include/blender_vscode/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
EDITOR_ADDRESS = None
OWN_SERVER_PORT = None
DEBUGPY_PORT = None
JUSTMYCODE = None

def setup(address, path_mappings):
global EDITOR_ADDRESS, OWN_SERVER_PORT, DEBUGPY_PORT
def setup(address, path_mappings, justMyCode):
global EDITOR_ADDRESS, OWN_SERVER_PORT, DEBUGPY_PORT, JUSTMYCODE
EDITOR_ADDRESS = address

OWN_SERVER_PORT = start_own_server()
DEBUGPY_PORT = start_debug_server()
JUSTMYCODE = justMyCode

send_connection_information(path_mappings)

Expand Down Expand Up @@ -56,7 +58,6 @@ def start_debug_server():
pass
return port


# Server
#########################################

Expand Down Expand Up @@ -103,9 +104,10 @@ def send_connection_information(path_mappings):
"type" : "setup",
"blenderPort" : OWN_SERVER_PORT,
"debugpyPort" : DEBUGPY_PORT,
"justMyCode": JUSTMYCODE,
"blenderPath" : str(blender_path),
"scriptsFolder" : str(scripts_folder),
"addonPathMappings" : path_mappings,
"addonPathMappings" : path_mappings
})

def send_dict_as_json(data):
Expand Down
1 change: 1 addition & 0 deletions pythonFiles/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
addons_to_load=tuple(map(lambda x: (Path(x["load_dir"]), x["module_name"]),
json.loads(os.environ['ADDONS_TO_LOAD']))),
allow_modify_external_python=os.environ['ALLOW_MODIFY_EXTERNAL_PYTHON'] == "yes",
justMyCode=os.environ['JUSTMYCODE'] == "True",
)
except Exception as e:
if type(e) is not SystemExit:
Expand Down
4 changes: 4 additions & 0 deletions src/addon_folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class AddonWorkspaceFolder {
return <boolean>this.getConfig().get('addon.reloadOnSave');
}

get justMyCode() {
return <boolean>this.getConfig().get('addon.justMyCode');
}

public async hasAddonEntryPoint() {
try {
let sourceDir = await this.getSourceDirectory();
Expand Down
1 change: 1 addition & 0 deletions src/blender_executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ async function getBlenderLaunchEnv() {
return {
ADDONS_TO_LOAD: JSON.stringify(loadDirsWithNames),
EDITOR_PORT: getServerPort().toString(),
JUSTMYCODE: <boolean>config.get('addon.justMyCode') ? 'True' : 'False',
ALLOW_MODIFY_EXTERNAL_PYTHON: <boolean>config.get('allowModifyExternalPython') ? 'yes' : 'no',
...<object>config.get("environmentVariables", {}),
};
Expand Down
8 changes: 5 additions & 3 deletions src/communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export type AddonPathMapping = { src: string, load: string };
export class BlenderInstance {
blenderPort: number;
debugpyPort: number;
justMyCode: boolean;
path: string;
scriptsFolder: string;
addonPathMappings: AddonPathMapping[];
connectionErrors: Error[];

constructor(blenderPort: number, debugpyPort: number, path: string,
constructor(blenderPort: number, debugpyPort: number, justMyCode: boolean, path: string,
scriptsFolder: string, addonPathMappings: AddonPathMapping[]) {
this.blenderPort = blenderPort;
this.debugpyPort = debugpyPort;
this.justMyCode = justMyCode;
this.path = path;
this.scriptsFolder = scriptsFolder;
this.addonPathMappings = addonPathMappings;
Expand All @@ -49,7 +51,7 @@ export class BlenderInstance {
}

attachDebugger() {
attachPythonDebuggerToBlender(this.debugpyPort, this.path, this.scriptsFolder, this.addonPathMappings);
attachPythonDebuggerToBlender(this.debugpyPort, this.path, this.justMyCode, this.scriptsFolder, this.addonPathMappings);
}

get address() {
Expand Down Expand Up @@ -130,7 +132,7 @@ function SERVER_handleRequest(request: any, response: any) {

switch (req.type) {
case 'setup': {
let instance = new BlenderInstance(req.blenderPort, req.debugpyPort, req.blenderPath, req.scriptsFolder, req.addonPathMappings);
let instance = new BlenderInstance(req.blenderPort, req.debugpyPort, req.justMyCode, req.blenderPath, req.scriptsFolder, req.addonPathMappings);
instance.attachDebugger();
RunningBlenders.register(instance);
response.end('OK');
Expand Down
7 changes: 4 additions & 3 deletions src/python_debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import { AddonPathMapping } from './communication';
type PathMapping = { localRoot: string, remoteRoot: string };

export async function attachPythonDebuggerToBlender(
port: number, blenderPath: string, scriptsFolder: string,
port: number, blenderPath: string, justMyCode:boolean, scriptsFolder: string,
addonPathMappings: AddonPathMapping[]) {

let mappings = await getPythonPathMappings(scriptsFolder, addonPathMappings);
attachPythonDebugger(port, mappings);
attachPythonDebugger(port, justMyCode, mappings);
}

function attachPythonDebugger(port: number, pathMappings: PathMapping[] = []) {
function attachPythonDebugger(port: number, justMyCode:boolean, pathMappings: PathMapping[] = []) {
let configuration = {
name: `Python at Port ${port}`,
request: "attach",
type: 'python',
port: port,
host: 'localhost',
pathMappings: pathMappings,
justMyCode: justMyCode
};
vscode.debug.startDebugging(undefined, configuration);
}
Expand Down

0 comments on commit 642800f

Please sign in to comment.