From 29ccbb5497fd7a64c8978242790a4c7489aae286 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Thu, 31 Oct 2019 15:10:49 -0700 Subject: [PATCH] Ensure cwd matches notebook path (#8137) * Ensure cwd matches notebook path * add error checking * silent, don't store history --- extensions/notebook/src/jupyter/jupyterSessionManager.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/notebook/src/jupyter/jupyterSessionManager.ts b/extensions/notebook/src/jupyter/jupyterSessionManager.ts index 88e01b4d22..160a1a58ec 100644 --- a/extensions/notebook/src/jupyter/jupyterSessionManager.ts +++ b/extensions/notebook/src/jupyter/jupyterSessionManager.ts @@ -334,6 +334,10 @@ export class JupyterSession implements nb.ISession { private async setEnvironmentVars(skip: boolean = false): Promise { if (!skip && this.sessionImpl) { let allCode: string = ''; + // Ensure cwd matches notebook path (this follows Jupyter behavior) + if (this.path && path.dirname(this.path)) { + allCode += `%cd ${path.dirname(this.path)}${EOL}`; + } for (let i = 0; i < Object.keys(process.env).length; i++) { let key = Object.keys(process.env)[i]; if (key.toLowerCase() === 'path' && this._pythonEnvVarPath) { @@ -344,7 +348,9 @@ export class JupyterSession implements nb.ISession { } } let future = this.sessionImpl.kernel.requestExecute({ - code: allCode + code: allCode, + silent: true, + store_history: false }, true); await future.done; }