Skip to content

Adds uninstall button on packages #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@
"title": "%python-envs.terminal.deactivate.title%",
"category": "Python Envs",
"icon": "$(circle-slash)"
},
{
"command": "python-envs.uninstallPackage",
"title": "%python-envs.uninstallPackage.title%",
"category": "Python Envs",
"icon": "$(trash)"
}
],
"menus": {
Expand Down Expand Up @@ -272,6 +278,10 @@
{
"command": "python-envs.terminal.deactivate",
"when": "pythonTerminalActivation"
},
{
"command": "python-envs.uninstallPackage",
"when": "false"
}
],
"view/item/context": [
Expand Down Expand Up @@ -309,6 +319,11 @@
"group": "inline",
"when": "view == env-managers && viewItem =~ /.*pythonEnvironment.*/"
},
{
"command": "python-envs.uninstallPackage",
"group": "inline",
"when": "view == env-managers && viewItem == python-package"
},
{
"command": "python-envs.packages",
"group": "inline",
Expand Down Expand Up @@ -336,6 +351,11 @@
"command": "python-envs.createTerminal",
"group": "inline",
"when": "view == python-projects && viewItem =~ /.*python-workspace.*/"
},
{
"command": "python-envs.uninstallPackage",
"group": "inline",
"when": "view == python-projects && viewItem == python-package"
}
],
"view/title": [
Expand Down
4 changes: 2 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"python-envs.pythonProjects.envManager.description": "The environment manager for creating and managing environments for this project.",
"python-envs.pythonProjects.packageManager.description": "The package manager for managing packages in environments for this project.",
"python-envs.terminal.showActivateButton.description": "Whether to show the 'Activate' button in the terminal menu",

"python-envs.setEnvManager.title": "Set Environment Manager",
"python-envs.setPkgManager.title": "Set Package Manager",
"python-envs.addPythonProject.title": "Add Python Project",
Expand All @@ -26,5 +25,6 @@
"python-envs.createTerminal.title": "Create Python Terminal",
"python-envs.runAsTask.title": "Run as Task",
"python-envs.terminal.activate.title": "Activate Environment in Current Terminal",
"python-envs.terminal.deactivate.title": "Deactivate Environment in Current Terminal"
"python-envs.terminal.deactivate.title": "Deactivate Environment in Current Terminal",
"python-envs.uninstallPackage.title": "Uninstall Package"
}
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
refreshPackagesCommand,
createAnyEnvironmentCommand,
runInDedicatedTerminalCommand,
handlePackageUninstall,
} from './features/envCommands';
import { registerCondaFeatures } from './managers/conda/main';
import { registerSystemPythonFeatures } from './managers/builtin/main';
Expand Down Expand Up @@ -133,6 +134,9 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
);
await handlePackagesCommand(packageManager, environment);
}),
commands.registerCommand('python-envs.uninstallPackage', async (context: unknown) => {
await handlePackageUninstall(context, envManagers);
}),
commands.registerCommand('python-envs.set', async (item) => {
await setEnvironmentCommand(item, envManagers, projectManager);
}),
Expand Down
13 changes: 13 additions & 0 deletions src/features/envCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
ProjectPackageRootTreeItem,
GlobalProjectItem,
EnvTreeItemKind,
PackageTreeItem,
ProjectPackage,
} from './views/treeViewItems';
import { Common } from '../common/localize';
import { pickEnvironment } from '../common/pickers/environments';
Expand Down Expand Up @@ -187,6 +189,17 @@ export async function handlePackagesCommand(
}
}

export async function handlePackageUninstall(context: unknown, em: EnvironmentManagers) {
if (context instanceof PackageTreeItem || context instanceof ProjectPackage) {
const moduleName = context.pkg.name;
const environment = context.parent.environment;
const packageManager = em.getPackageManager(environment);
await packageManager?.uninstall(environment, [moduleName]);
return;
}
traceError(`Invalid context for uninstall command: ${typeof context}`);
}

export async function setEnvironmentCommand(
context: unknown,
em: EnvironmentManagers,
Expand Down
Loading