From 1262a9b1d8adad6e13f83771248f2dfab2da5706 Mon Sep 17 00:00:00 2001 From: andreamah Date: Thu, 27 Feb 2020 11:10:51 -0800 Subject: [PATCH 1/5] progress on venv bug fix --- src/extension_utils/utils.ts | 226 ++++++++++++++++------------------- 1 file changed, 104 insertions(+), 122 deletions(-) diff --git a/src/extension_utils/utils.ts b/src/extension_utils/utils.ts index 4ee882a34..fd8df668e 100644 --- a/src/extension_utils/utils.ts +++ b/src/extension_utils/utils.ts @@ -85,7 +85,7 @@ export function tryParseJSON(jsonString: string): any | boolean { if (jsonObj && typeof jsonObj === "object") { return jsonObj; } - } catch (exception) {} + } catch (exception) { } return false; } @@ -345,23 +345,11 @@ export const promptInstallVenv = ( if (selection === DialogResponses.YES) { return installPythonVenv(context, pythonExecutable); } else { - return vscode.window - .showInformationMessage( - CONSTANTS.INFO.ARE_YOU_SURE, - DialogResponses.INSTALL_NOW, - DialogResponses.DONT_INSTALL - ) - .then((installChoice: vscode.MessageItem | undefined) => { - if (installChoice === DialogResponses.INSTALL_NOW) { - return installPythonVenv(context, pythonExecutable); - } else { - // return an empty string, notifying the caller - // that the user was unwilling to create venv - // and by default, this will trigger the extension to - // try using pythonExecutable - return ""; - } - }); + // return pythonExecutable, notifying the caller + // that the user was unwilling to create venv + // and by default, this will trigger the extension to + // try using pythonExecutable + return pythonExecutable; } }); }; @@ -410,22 +398,7 @@ export const installPythonVenv = async ( return pythonExecutable; } - if (!(await installDependencies(context, pythonPath))) { - vscode.window - .showErrorMessage( - `${CONSTANTS.ERROR.DEPENDENCY_DOWNLOAD_ERROR} Using original interpreter at: ${pythonExecutable}.`, - DialogResponses.READ_INSTALL_MD - ) - .then((selection: vscode.MessageItem | undefined) => { - if (selection === DialogResponses.READ_INSTALL_MD) { - open(CONSTANTS.LINKS.INSTALL); - } - }); - - return pythonExecutable; - } - - return pythonPath; + return installDependenciesWrapper(context, pythonPath, pythonExecutable); }; export const areDependenciesInstalled = async ( @@ -481,6 +454,49 @@ export const installDependencies = async ( } }; +export const installDependenciesWrapper = async ( + context: vscode.ExtensionContext, + pythonPath: string, + backupPythonPath: string = "" +) => { + + let errMessage = CONSTANTS.ERROR + .DEPENDENCY_DOWNLOAD_ERROR + if (backupPythonPath !== "") { + errMessage = `${errMessage} Using original interpreter at: ${backupPythonPath}.` + } + if ( + !(await installDependencies( + context, + pythonPath + )) + ) { + vscode.window + .showErrorMessage( + CONSTANTS.ERROR + .DEPENDENCY_DOWNLOAD_ERROR, + DialogResponses.READ_INSTALL_MD + ) + .then( + ( + selection: + | vscode.MessageItem + | undefined + ) => { + if ( + selection === + DialogResponses.READ_INSTALL_MD + ) { + open( + CONSTANTS.LINKS.INSTALL + ); + } + } + ); + return backupPythonPath; + } + return pythonPath; +}; export const getCurrentPythonExecutableName = async () => { let originalPythonExecutableName = ""; @@ -551,109 +567,75 @@ export const setupEnv = async ( if (!(await areDependenciesInstalled(context, pythonExecutableName))) { // environment needs to install dependencies if (!(await checkIfVenv(context, pythonExecutableName))) { - pythonExecutableName = await getPythonVenv(context); + const pythonExecutableNameVenv = await getPythonVenv(context); if (await hasVenv(context)) { // venv in extention exists with wrong dependencies if ( !(await areDependenciesInstalled( context, - pythonExecutableName + pythonExecutableNameVenv )) ) { - if ( - !(await installDependencies( - context, - pythonExecutableName - )) - ) { - vscode.window - .showErrorMessage( - `${CONSTANTS.ERROR.DEPENDENCY_DOWNLOAD_ERROR} Using original interpreter at: ${pythonExecutableName}.`, - DialogResponses.READ_INSTALL_MD - ) - .then( - (selection: vscode.MessageItem | undefined) => { - if ( - selection === - DialogResponses.READ_INSTALL_MD - ) { - open(CONSTANTS.LINKS.INSTALL); - } - } - ); - return pythonExecutableName; - } + await installDependenciesWrapper( + context, + pythonExecutableNameVenv, + pythonExecutableName); } - } else { - pythonExecutableName = await promptInstallVenv( - context, - originalPythonExecutableName - ); } + } else { + pythonExecutableName = await promptInstallVenv( + context, + originalPythonExecutableName + ); } + } - if (pythonExecutableName === originalPythonExecutableName) { - // going with original interpreter, either because - // already in venv or error in creating custom venv - if (checkConfig(CONFIG.SHOW_DEPENDENCY_INSTALL)) { - await vscode.window - .showInformationMessage( - CONSTANTS.INFO.INSTALL_PYTHON_DEPS, - DialogResponses.INSTALL_NOW, - DialogResponses.DONT_INSTALL - ) - .then( - async ( - installChoice: vscode.MessageItem | undefined - ) => { - if (installChoice === DialogResponses.INSTALL_NOW) { - if ( - !(await installDependencies( - context, - pythonExecutableName - )) - ) { - vscode.window - .showErrorMessage( - CONSTANTS.ERROR - .DEPENDENCY_DOWNLOAD_ERROR, - DialogResponses.READ_INSTALL_MD - ) - .then( - ( - selection: - | vscode.MessageItem - | undefined - ) => { - if ( - selection === - DialogResponses.READ_INSTALL_MD - ) { - open( - CONSTANTS.LINKS.INSTALL - ); - } - } - ); - return pythonExecutableName; - } - } + if (pythonExecutableName === originalPythonExecutableName) { + // going with original interpreter, either because + // already in venv or error in creating custom venv + if (checkConfig(CONFIG.SHOW_DEPENDENCY_INSTALL)) { + await vscode.window + .showInformationMessage( + CONSTANTS.INFO.INSTALL_PYTHON_DEPS, + DialogResponses.INSTALL_NOW, + DialogResponses.DONT_INSTALL + ) + .then( + async ( + installChoice: vscode.MessageItem | undefined + ) => { + if (installChoice === DialogResponses.INSTALL_NOW) { + await installDependenciesWrapper(context, pythonExecutableName) + } else { + vscode.window + .showInformationMessage( + CONSTANTS.INFO.ARE_YOU_SURE, + DialogResponses.INSTALL_NOW, + DialogResponses.DONT_INSTALL + ) + .then((installChoice2: vscode.MessageItem | undefined) => { + if (installChoice2 === DialogResponses.INSTALL_NOW) { + await installDependenciesWrapper(context, pythonExecutableName); + } + }); } - ); - } - } else { - vscode.window.showInformationMessage( - CONSTANTS.INFO.UPDATED_TO_EXTENSION_VENV - ); - vscode.workspace - .getConfiguration() - .update(CONFIG.PYTHON_PATH, pythonExecutableName); + } + ); } - } else if (needsResponse) { + } else { vscode.window.showInformationMessage( - CONSTANTS.INFO.ALREADY_SUCCESSFUL_INSTALL + CONSTANTS.INFO.UPDATED_TO_EXTENSION_VENV ); + vscode.workspace + .getConfiguration() + .update(CONFIG.PYTHON_PATH, pythonExecutableName); } +} else if (needsResponse) { + vscode.window.showInformationMessage( + CONSTANTS.INFO.ALREADY_SUCCESSFUL_INSTALL + ); +} - return pythonExecutableName; +return pythonExecutableName; }; + From c0c64091358ba1588ed0197f32285e2858bb0f6d Mon Sep 17 00:00:00 2001 From: andreamah Date: Thu, 27 Feb 2020 11:48:18 -0800 Subject: [PATCH 2/5] fixes to virtual env workflow --- src/extension_utils/utils.ts | 105 ++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/src/extension_utils/utils.ts b/src/extension_utils/utils.ts index fd8df668e..414291b1b 100644 --- a/src/extension_utils/utils.ts +++ b/src/extension_utils/utils.ts @@ -565,10 +565,12 @@ export const setupEnv = async ( let pythonExecutableName = originalPythonExecutableName; if (!(await areDependenciesInstalled(context, pythonExecutableName))) { + const pythonExecutableNameVenv = await getPythonVenv(context); // environment needs to install dependencies if (!(await checkIfVenv(context, pythonExecutableName))) { - const pythonExecutableNameVenv = await getPythonVenv(context); + console.log("uuuuwuuu 1") if (await hasVenv(context)) { + console.log("uuuuwuuu 2") // venv in extention exists with wrong dependencies if ( !(await areDependenciesInstalled( @@ -576,66 +578,67 @@ export const setupEnv = async ( pythonExecutableNameVenv )) ) { - await installDependenciesWrapper( + pythonExecutableName = await installDependenciesWrapper( context, pythonExecutableNameVenv, - pythonExecutableName); + pythonExecutableName) } + } else { + console.log("uuuuwuuu 2") + pythonExecutableName = await promptInstallVenv( + context, + originalPythonExecutableName + ); } - } else { - pythonExecutableName = await promptInstallVenv( - context, - originalPythonExecutableName - ); } - } - - if (pythonExecutableName === originalPythonExecutableName) { - // going with original interpreter, either because - // already in venv or error in creating custom venv - if (checkConfig(CONFIG.SHOW_DEPENDENCY_INSTALL)) { - await vscode.window - .showInformationMessage( - CONSTANTS.INFO.INSTALL_PYTHON_DEPS, - DialogResponses.INSTALL_NOW, - DialogResponses.DONT_INSTALL - ) - .then( - async ( - installChoice: vscode.MessageItem | undefined - ) => { - if (installChoice === DialogResponses.INSTALL_NOW) { - await installDependenciesWrapper(context, pythonExecutableName) - } else { - vscode.window - .showInformationMessage( - CONSTANTS.INFO.ARE_YOU_SURE, - DialogResponses.INSTALL_NOW, - DialogResponses.DONT_INSTALL - ) - .then((installChoice2: vscode.MessageItem | undefined) => { - if (installChoice2 === DialogResponses.INSTALL_NOW) { - await installDependenciesWrapper(context, pythonExecutableName); - } - }); + if (pythonExecutableName === pythonExecutableNameVenv) { + vscode.window.showInformationMessage( + CONSTANTS.INFO.UPDATED_TO_EXTENSION_VENV + ); + vscode.workspace + .getConfiguration() + .update(CONFIG.PYTHON_PATH, pythonExecutableName); + } else if (pythonExecutableName === originalPythonExecutableName) { + // going with original interpreter, either because + // already in venv or error in creating custom venv + if (checkConfig(CONFIG.SHOW_DEPENDENCY_INSTALL)) { + await vscode.window + .showInformationMessage( + CONSTANTS.INFO.INSTALL_PYTHON_DEPS, + DialogResponses.INSTALL_NOW, + DialogResponses.DONT_INSTALL + ) + .then( + async ( + installChoice: vscode.MessageItem | undefined + ) => { + if (installChoice === DialogResponses.INSTALL_NOW) { + await installDependenciesWrapper(context, pythonExecutableName) + } else { + await vscode.window + .showInformationMessage( + CONSTANTS.INFO.ARE_YOU_SURE, + DialogResponses.INSTALL_NOW, + DialogResponses.DONT_INSTALL + ) + .then( + async ( + installChoice2: vscode.MessageItem | undefined) => { + if (installChoice2 === DialogResponses.INSTALL_NOW) { + await installDependenciesWrapper(context, pythonExecutableName); + } + }); + } } - } - ); + ); + } } - } else { + } else if (needsResponse) { vscode.window.showInformationMessage( - CONSTANTS.INFO.UPDATED_TO_EXTENSION_VENV + CONSTANTS.INFO.ALREADY_SUCCESSFUL_INSTALL ); - vscode.workspace - .getConfiguration() - .update(CONFIG.PYTHON_PATH, pythonExecutableName); } -} else if (needsResponse) { - vscode.window.showInformationMessage( - CONSTANTS.INFO.ALREADY_SUCCESSFUL_INSTALL - ); -} -return pythonExecutableName; + return pythonExecutableName; }; From 82d78bc4a45c44d3ec7d2ae5d0f379c50b87a36f Mon Sep 17 00:00:00 2001 From: andreamah Date: Thu, 27 Feb 2020 11:50:57 -0800 Subject: [PATCH 3/5] formatting --- src/extension_utils/utils.ts | 70 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/src/extension_utils/utils.ts b/src/extension_utils/utils.ts index 414291b1b..603050a3c 100644 --- a/src/extension_utils/utils.ts +++ b/src/extension_utils/utils.ts @@ -85,7 +85,7 @@ export function tryParseJSON(jsonString: string): any | boolean { if (jsonObj && typeof jsonObj === "object") { return jsonObj; } - } catch (exception) { } + } catch (exception) {} return false; } @@ -459,40 +459,21 @@ export const installDependenciesWrapper = async ( pythonPath: string, backupPythonPath: string = "" ) => { - - let errMessage = CONSTANTS.ERROR - .DEPENDENCY_DOWNLOAD_ERROR + let errMessage = CONSTANTS.ERROR.DEPENDENCY_DOWNLOAD_ERROR; if (backupPythonPath !== "") { - errMessage = `${errMessage} Using original interpreter at: ${backupPythonPath}.` + errMessage = `${errMessage} Using original interpreter at: ${backupPythonPath}.`; } - if ( - !(await installDependencies( - context, - pythonPath - )) - ) { + if (!(await installDependencies(context, pythonPath))) { vscode.window .showErrorMessage( - CONSTANTS.ERROR - .DEPENDENCY_DOWNLOAD_ERROR, + CONSTANTS.ERROR.DEPENDENCY_DOWNLOAD_ERROR, DialogResponses.READ_INSTALL_MD ) - .then( - ( - selection: - | vscode.MessageItem - | undefined - ) => { - if ( - selection === - DialogResponses.READ_INSTALL_MD - ) { - open( - CONSTANTS.LINKS.INSTALL - ); - } + .then((selection: vscode.MessageItem | undefined) => { + if (selection === DialogResponses.READ_INSTALL_MD) { + open(CONSTANTS.LINKS.INSTALL); } - ); + }); return backupPythonPath; } return pythonPath; @@ -568,9 +549,9 @@ export const setupEnv = async ( const pythonExecutableNameVenv = await getPythonVenv(context); // environment needs to install dependencies if (!(await checkIfVenv(context, pythonExecutableName))) { - console.log("uuuuwuuu 1") + console.log("uuuuwuuu 1"); if (await hasVenv(context)) { - console.log("uuuuwuuu 2") + console.log("uuuuwuuu 2"); // venv in extention exists with wrong dependencies if ( !(await areDependenciesInstalled( @@ -581,10 +562,11 @@ export const setupEnv = async ( pythonExecutableName = await installDependenciesWrapper( context, pythonExecutableNameVenv, - pythonExecutableName) + pythonExecutableName + ); } } else { - console.log("uuuuwuuu 2") + console.log("uuuuwuuu 2"); pythonExecutableName = await promptInstallVenv( context, originalPythonExecutableName @@ -613,7 +595,10 @@ export const setupEnv = async ( installChoice: vscode.MessageItem | undefined ) => { if (installChoice === DialogResponses.INSTALL_NOW) { - await installDependenciesWrapper(context, pythonExecutableName) + await installDependenciesWrapper( + context, + pythonExecutableName + ); } else { await vscode.window .showInformationMessage( @@ -623,11 +608,21 @@ export const setupEnv = async ( ) .then( async ( - installChoice2: vscode.MessageItem | undefined) => { - if (installChoice2 === DialogResponses.INSTALL_NOW) { - await installDependenciesWrapper(context, pythonExecutableName); + installChoice2: + | vscode.MessageItem + | undefined + ) => { + if ( + installChoice2 === + DialogResponses.INSTALL_NOW + ) { + await installDependenciesWrapper( + context, + pythonExecutableName + ); } - }); + } + ); } } ); @@ -641,4 +636,3 @@ export const setupEnv = async ( return pythonExecutableName; }; - From 76057dbfae16a93c68b9f634647183efe7824850 Mon Sep 17 00:00:00 2001 From: andreamah Date: Thu, 27 Feb 2020 11:52:06 -0800 Subject: [PATCH 4/5] removed console logs --- src/extension_utils/utils.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/extension_utils/utils.ts b/src/extension_utils/utils.ts index 603050a3c..b3af4c270 100644 --- a/src/extension_utils/utils.ts +++ b/src/extension_utils/utils.ts @@ -85,7 +85,7 @@ export function tryParseJSON(jsonString: string): any | boolean { if (jsonObj && typeof jsonObj === "object") { return jsonObj; } - } catch (exception) {} + } catch (exception) { } return false; } @@ -549,9 +549,7 @@ export const setupEnv = async ( const pythonExecutableNameVenv = await getPythonVenv(context); // environment needs to install dependencies if (!(await checkIfVenv(context, pythonExecutableName))) { - console.log("uuuuwuuu 1"); if (await hasVenv(context)) { - console.log("uuuuwuuu 2"); // venv in extention exists with wrong dependencies if ( !(await areDependenciesInstalled( @@ -566,7 +564,6 @@ export const setupEnv = async ( ); } } else { - console.log("uuuuwuuu 2"); pythonExecutableName = await promptInstallVenv( context, originalPythonExecutableName From 6ea6decb4a0e5f3cdb651169f3c376c87ef26db6 Mon Sep 17 00:00:00 2001 From: andreamah Date: Thu, 27 Feb 2020 12:32:55 -0800 Subject: [PATCH 5/5] formatting --- src/extension_utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension_utils/utils.ts b/src/extension_utils/utils.ts index b3af4c270..599dfa88b 100644 --- a/src/extension_utils/utils.ts +++ b/src/extension_utils/utils.ts @@ -85,7 +85,7 @@ export function tryParseJSON(jsonString: string): any | boolean { if (jsonObj && typeof jsonObj === "object") { return jsonObj; } - } catch (exception) { } + } catch (exception) {} return false; }