Skip to content

Commit 20246e9

Browse files
use added paths when checking ptvsd version / availabilty (#7220)
1 parent a70b4f5 commit 20246e9

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

news/2 Fixes/6907.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the debugger being installed even when available from the VSCode install

src/client/datascience/jupyter/jupyterDebugger.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
155155
return result;
156156
}
157157

158-
// Append our local ptvsd path and ptvsd settings path to sys.path
159-
private async appendPtvsdPaths(server: INotebookServer): Promise<void> {
158+
private calculatePtvsdPathList(server: INotebookServer): string | undefined {
160159
const extraPaths: string[] = [];
161160

162161
// Add the settings path first as it takes precedence over the ptvsd extension path
@@ -183,7 +182,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
183182
}
184183

185184
if (extraPaths && extraPaths.length > 0) {
186-
const pythonPathList = extraPaths.reduce((totalPath, currentPath) => {
185+
return extraPaths.reduce((totalPath, currentPath) => {
187186
if (totalPath.length === 0) {
188187
totalPath = `'${currentPath}'`;
189188
} else {
@@ -192,7 +191,17 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
192191

193192
return totalPath;
194193
}, '');
195-
await this.executeSilently(server, `import sys\r\nsys.path.extend([${pythonPathList}])\r\nsys.path`);
194+
}
195+
196+
return undefined;
197+
}
198+
199+
// Append our local ptvsd path and ptvsd settings path to sys.path
200+
private async appendPtvsdPaths(server: INotebookServer): Promise<void> {
201+
const ptvsdPathList = this.calculatePtvsdPathList(server);
202+
203+
if (ptvsdPathList && ptvsdPathList.length > 0) {
204+
await this.executeSilently(server, `import sys\r\nsys.path.extend([${ptvsdPathList}])\r\nsys.path`);
196205
}
197206
}
198207

@@ -216,9 +225,19 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
216225
}
217226

218227
private async ptvsdCheck(server: INotebookServer): Promise<IPtvsdVersion | undefined> {
219-
// We don't want to actually import ptvsd to check version so run !python instead.
228+
// We don't want to actually import ptvsd to check version so run !python instead. If we import an old version it's hard to get rid of on
229+
// an upgrade needed scenario
220230
// tslint:disable-next-line:no-multiline-string
221-
const ptvsdVersionResults = await this.executeSilently(server, `import sys\r\n!{sys.executable} -c "import ptvsd;print(ptvsd.__version__)"`);
231+
const ptvsdPathList = this.calculatePtvsdPathList(server);
232+
233+
let code;
234+
if (ptvsdPathList) {
235+
code = `import sys\r\n!{sys.executable} -c "import sys;sys.path.extend([${ptvsdPathList}]);sys.path;import ptvsd;print(ptvsd.__version__)"`;
236+
} else {
237+
code = `import sys\r\n!{sys.executable} -c "import ptvsd;print(ptvsd.__version__)"`;
238+
}
239+
240+
const ptvsdVersionResults = await this.executeSilently(server, code);
222241
return this.parsePtvsdVersionInfo(ptvsdVersionResults);
223242
}
224243

0 commit comments

Comments
 (0)