This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Venv fixes #228
Merged
Merged
Venv fixes #228
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1262a9b
progress on venv bug fix
andreamah c0c6409
fixes to virtual env workflow
andreamah 82d78bc
formatting
andreamah 76057db
removed console logs
andreamah dbeb7fe
Merge branch 'dev' into users/t-anmah/ext-venv-fix
andreamah 6ea6dec
formatting
andreamah 6ed2556
Merge branch 'dev' into users/t-anmah/ext-venv-fix
andreamah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,30 @@ 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 = ""; | ||
|
||
|
@@ -549,40 +546,22 @@ 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))) { | ||
pythonExecutableName = 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; | ||
} | ||
pythonExecutableName = await installDependenciesWrapper( | ||
context, | ||
pythonExecutableNameVenv, | ||
pythonExecutableName | ||
); | ||
} | ||
} else { | ||
pythonExecutableName = await promptInstallVenv( | ||
|
@@ -591,8 +570,14 @@ export const setupEnv = async ( | |
); | ||
} | ||
} | ||
|
||
if (pythonExecutableName === originalPythonExecutableName) { | ||
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)) { | ||
|
@@ -607,47 +592,38 @@ export const setupEnv = 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 | ||
); | ||
} | ||
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 | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't install the dependencies (perhaps you miss the prompts) and try running some micro:bit code, VS Code only shows a generic error:
It would be much more helpful if we could show the user a more helpful message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True! Perhaps that'd be good for another release, since we're rushing for the release in an hour :'''( |
||
} | ||
); | ||
return pythonExecutableName; | ||
} | ||
} | ||
); | ||
} | ||
} | ||
); | ||
} | ||
} else { | ||
vscode.window.showInformationMessage( | ||
CONSTANTS.INFO.UPDATED_TO_EXTENSION_VENV | ||
); | ||
vscode.workspace | ||
.getConfiguration() | ||
.update(CONFIG.PYTHON_PATH, pythonExecutableName); | ||
} | ||
} else if (needsResponse) { | ||
vscode.window.showInformationMessage( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be ok to remove this prompt, as it is the third prompt in a row asking about installing dependencies. Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should leave it in for now, since people who just close popups on instinct should be advised that the extension won't work without installing dependencies! Maybe we can incorporate this info into an earlier popup later on :0