PY-78749 Packages: refactor uninstall(String) from PyPM

Signed-off-by: Nikita.Ashihmin <nikita.ashihmin@jetbrains.com>

GitOrigin-RevId: dbf373cca5c10091c12f4abce22d66fb76568c02
This commit is contained in:
Nikita.Ashihmin
2025-07-24 11:34:37 +00:00
committed by intellij-monorepo-bot
parent 50d6856ce5
commit 83c557f522
5 changed files with 0 additions and 79 deletions
@@ -61,8 +61,6 @@ public abstract class PyPackageManager implements Disposable {
public abstract void install(@Nullable List<PyRequirement> requirements, @NotNull List<String> extraArgs) throws ExecutionException;
public abstract void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException;
public abstract void refresh();
public abstract @NotNull String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws ExecutionException;
@@ -29,13 +29,6 @@ internal open class PyPackageManagerBridge(sdk: Sdk) : PyTargetEnvironmentPackag
}
}
@Throws(ExecutionException::class)
override fun uninstall(packages: MutableList<PyPackage>) {
runBlockingMaybeCancellable {
packageManagerUI.uninstallPackagesBackground(packages.map { it.name })
}
}
override fun refreshAndGetPackages(alwaysRefresh: Boolean): List<PyPackage?> {
val pythonPackages = if (alwaysRefresh) {
runBlockingMaybeCancellable {
@@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@@ -109,32 +108,6 @@ public abstract class PyPackageManagerImpl extends PyPackageManagerImplBase {
}
}
@Override
public void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException {
final List<String> args = new ArrayList<>();
try {
args.add(UNINSTALL);
boolean canModify = true;
for (PyPackage pkg : packages) {
if (canModify) {
final String location = pkg.getLocation();
if (location != null) {
canModify = Files.isWritable(Paths.get(location));
}
}
args.add(pkg.getName());
}
getHelperResult(args, !canModify, true);
}
catch (PyExecutionException e) {
throw PyExecutionExceptionExtKt.copyWith(e, "pip", args);
}
finally {
LOG.debug("Packages cache is about to be refreshed because these packages were uninstalled: " + packages);
refreshPackagesSynchronously();
}
}
@Override
public @Nullable List<PyPackage> getPackages() {
@@ -40,9 +40,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
/**
@@ -131,42 +129,6 @@ public abstract class PyTargetEnvironmentPackageManager extends PyPackageManager
}
}
@Override
public void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException {
List<String> args = new ArrayList<>();
HelpersAwareTargetEnvironmentRequest helpersAwareRequest = getPythonTargetInterpreter();
TargetEnvironmentRequest targetEnvironmentRequest = helpersAwareRequest.getTargetEnvironmentRequest();
PythonScriptExecution pythonExecution =
PythonScripts.prepareHelperScriptExecution(PythonHelper.PACKAGING_TOOL, helpersAwareRequest);
try {
pythonExecution.addParameter(UNINSTALL);
// TODO [targets] Remove temporary usage of String arguments
args.add(UNINSTALL);
boolean canModify = true;
for (PyPackage pkg : packages) {
if (canModify) {
final String location = pkg.getLocation();
if (location != null) {
// TODO [targets] Introspection is required here
canModify = Files.isWritable(Paths.get(location));
}
}
pythonExecution.addParameter(pkg.getName());
// TODO [targets] Remove temporary usage of String arguments
args.add(pkg.getName());
}
// TODO [targets] Pass `parentDir = null`
getPythonProcessResult(pythonExecution, !canModify, true, targetEnvironmentRequest);
}
catch (PyExecutionException e) {
throw PyExecutionExceptionExtKt.copyWith(e, "pip", args);
}
finally {
LOG.debug("Packages cache is about to be refreshed because these packages were uninstalled: " + packages);
refreshPackagesSynchronously();
}
}
@Override
public @Nullable List<PyPackage> getPackages() {
@@ -13,7 +13,6 @@ import com.jetbrains.env.PyTestTask;
import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyPackageManager;
import com.jetbrains.python.packaging.requirement.PyRequirementRelation;
import com.jetbrains.python.sdk.PythonSdkUtil;
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
import com.jetbrains.python.sdk.flavors.VirtualEnvSdkFlavor;
import com.jetbrains.python.tools.sdkTools.SdkCreationType;
@@ -121,10 +120,6 @@ public class PyPackagingTest extends PyEnvTestCase {
final PyPackage pip1 = findPackage("pip", packages1);
assertNotNull(pip1);
assertEquals("pip", pip1.getName());
manager.uninstall(Collections.singletonList(markdown2));
final List<PyPackage> packages3 = manager.refreshAndGetPackages(false);
final PyPackage markdown3 = findPackage("markdown", packages3);
assertNull(markdown3);
}
catch (ExecutionException e) {
throw new RuntimeException(String.format("Error for interpreter '%s': %s", sdk.getHomePath(), e.getMessage()), e);