forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to delete and re-create .conda environments
- Loading branch information
1 parent
e32657f
commit 68e9ef1
Showing
8 changed files
with
354 additions
and
29 deletions.
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
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
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
37 changes: 37 additions & 0 deletions
37
src/client/pythonEnvironments/creation/provider/condaDeleteUtils.ts
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { WorkspaceFolder } from 'vscode'; | ||
import { plainExec } from '../../../common/process/rawProcessApis'; | ||
import { CreateEnv } from '../../../common/utils/localize'; | ||
import { traceError, traceInfo } from '../../../logging'; | ||
import { getPrefixCondaEnvPath, hasPrefixCondaEnv, showErrorMessageWithLogs } from '../common/commonUtils'; | ||
|
||
export async function deleteCondaEnvironment( | ||
workspace: WorkspaceFolder, | ||
interpreter: string, | ||
pathEnvVar: string, | ||
): Promise<boolean> { | ||
const condaEnvPath = getPrefixCondaEnvPath(workspace); | ||
const command = interpreter; | ||
const args = ['-m', 'conda', 'env', 'remove', '--prefix', condaEnvPath, '--yes']; | ||
try { | ||
traceInfo(`Deleting conda environment: ${condaEnvPath}`); | ||
traceInfo(`Running command: ${command} ${args.join(' ')}`); | ||
const result = await plainExec(command, args, { mergeStdOutErr: true }, { ...process.env, PATH: pathEnvVar }); | ||
traceInfo(result.stdout); | ||
if (await hasPrefixCondaEnv(workspace)) { | ||
// If conda cannot delete files it will name the files as .conda_trash. | ||
// These need to be deleted manually. | ||
traceError(`Conda environment ${condaEnvPath} could not be deleted.`); | ||
traceError(`Please delete the environment manually: ${condaEnvPath}`); | ||
showErrorMessageWithLogs(CreateEnv.Conda.errorDeletingEnvironment); | ||
return false; | ||
} | ||
} catch (err) { | ||
showErrorMessageWithLogs(CreateEnv.Conda.errorDeletingEnvironment); | ||
traceError(`Deleting conda environment ${condaEnvPath} Failed with error: `, err); | ||
return false; | ||
} | ||
return true; | ||
} |
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
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
Oops, something went wrong.