From 0c79cc2c5a176286ee6a9e9bb8b6c48243a7bf08 Mon Sep 17 00:00:00 2001 From: Ian Huff Date: Thu, 5 Sep 2019 13:19:19 -0700 Subject: [PATCH] use added paths when checking ptvsd version / availabilty --- news/2 Fixes/6907.md | 1 + .../datascience/jupyter/jupyterDebugger.ts | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 news/2 Fixes/6907.md diff --git a/news/2 Fixes/6907.md b/news/2 Fixes/6907.md new file mode 100644 index 000000000000..bdfb696eb0c8 --- /dev/null +++ b/news/2 Fixes/6907.md @@ -0,0 +1 @@ +Fix the debugger being installed even when available from the VSCode install \ No newline at end of file diff --git a/src/client/datascience/jupyter/jupyterDebugger.ts b/src/client/datascience/jupyter/jupyterDebugger.ts index f404175ec877..35af2bcceb3b 100644 --- a/src/client/datascience/jupyter/jupyterDebugger.ts +++ b/src/client/datascience/jupyter/jupyterDebugger.ts @@ -155,8 +155,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener { return result; } - // Append our local ptvsd path and ptvsd settings path to sys.path - private async appendPtvsdPaths(server: INotebookServer): Promise { + private calculatePtvsdPathList(server: INotebookServer): string | undefined { const extraPaths: string[] = []; // Add the settings path first as it takes precedence over the ptvsd extension path @@ -183,7 +182,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener { } if (extraPaths && extraPaths.length > 0) { - const pythonPathList = extraPaths.reduce((totalPath, currentPath) => { + return extraPaths.reduce((totalPath, currentPath) => { if (totalPath.length === 0) { totalPath = `'${currentPath}'`; } else { @@ -192,7 +191,17 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener { return totalPath; }, ''); - await this.executeSilently(server, `import sys\r\nsys.path.extend([${pythonPathList}])\r\nsys.path`); + } + + return undefined; + } + + // Append our local ptvsd path and ptvsd settings path to sys.path + private async appendPtvsdPaths(server: INotebookServer): Promise { + const ptvsdPathList = this.calculatePtvsdPathList(server); + + if (ptvsdPathList && ptvsdPathList.length > 0) { + await this.executeSilently(server, `import sys\r\nsys.path.extend([${ptvsdPathList}])\r\nsys.path`); } } @@ -216,9 +225,19 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener { } private async ptvsdCheck(server: INotebookServer): Promise { - // We don't want to actually import ptvsd to check version so run !python instead. + // 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 + // an upgrade needed scenario // tslint:disable-next-line:no-multiline-string - const ptvsdVersionResults = await this.executeSilently(server, `import sys\r\n!{sys.executable} -c "import ptvsd;print(ptvsd.__version__)"`); + const ptvsdPathList = this.calculatePtvsdPathList(server); + + let code; + if (ptvsdPathList) { + code = `import sys\r\n!{sys.executable} -c "import sys;sys.path.extend([${ptvsdPathList}]);sys.path;import ptvsd;print(ptvsd.__version__)"`; + } else { + code = `import sys\r\n!{sys.executable} -c "import ptvsd;print(ptvsd.__version__)"`; + } + + const ptvsdVersionResults = await this.executeSilently(server, code); return this.parsePtvsdVersionInfo(ptvsdVersionResults); }