From 2c7638ac8bd284b79db469d5c708e39084a4e89d Mon Sep 17 00:00:00 2001 From: Alexander Koshevoy Date: Tue, 10 Oct 2023 14:36:24 +0200 Subject: [PATCH] Safe remove unused PyCondaManagementService class GitOrigin-RevId: 7f9c11ce5560ee457d4a6574cf4b5a9a9b9ac59e --- .../messages/PyBundle.properties | 2 - .../ui/PyCondaManagementService.java | 199 ------------------ 2 files changed, 201 deletions(-) delete mode 100644 python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java diff --git a/python/pluginResources/messages/PyBundle.properties b/python/pluginResources/messages/PyBundle.properties index 834c0b8694b1..6c48c8eae190 100644 --- a/python/pluginResources/messages/PyBundle.properties +++ b/python/pluginResources/messages/PyBundle.properties @@ -956,8 +956,6 @@ python.packaging.no.tasks.found=No tasks found python.packaging.command.line=Command Line python.packaging.install=Install python.packaging.choose.packages.to.install=Choose Packages to Install -python.packaging.removing.conda.channel=Removing Conda Channel -python.packaging.adding.conda.channel=Adding Conda Channel python.packaging.failed.to.install.packaging.tools.title=Failed to Install Python Packaging Tools python.packaging.install.packaging.tools=Install packaging tools python.packaging.create.setup.package.name=Package name diff --git a/python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java b/python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java deleted file mode 100644 index b7f38afecf5b..000000000000 --- a/python/src/com/jetbrains/python/packaging/ui/PyCondaManagementService.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jetbrains.python.packaging.ui; - -import com.google.common.collect.Multimap; -import com.intellij.execution.ExecutionException; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.util.CatchingConsumer; -import com.intellij.util.containers.ContainerUtil; -import com.intellij.webcore.packaging.InstalledPackage; -import com.intellij.webcore.packaging.RepoPackage; -import com.jetbrains.python.PyBundle; -import com.jetbrains.python.packaging.PyCondaPackageManagerImpl; -import com.jetbrains.python.packaging.PyCondaPackageService; -import com.jetbrains.python.packaging.PyPackageManager; -import com.jetbrains.python.sdk.flavors.PyCondaRunKt; -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class PyCondaManagementService extends PyPackageManagementService { - private static final Logger LOG = Logger.getInstance(PyCondaManagementService.class); - public PyCondaManagementService(@NotNull final Project project, @NotNull final Sdk sdk) { - super(project, sdk); - } - - private boolean useConda() { - return PyPackageManager.getInstance(mySdk) instanceof PyCondaPackageManagerImpl && - ((PyCondaPackageManagerImpl)PyPackageManager.getInstance(mySdk)).useConda(); - } - - @Override - @NotNull - public List getAllPackagesCached() { - if (useConda()) { - return Collections.emptyList(); - } - else { - return super.getAllPackagesCached(); - } - } - - @Override - @NotNull - public List getAllPackages() throws IOException { - if (useConda()) { - return reloadAllPackages(); - } - else { - return super.getAllPackages(); - } - } - - @Override - @NotNull - public List reloadAllPackages() throws IOException { - if (useConda()) { - final Multimap packages = PyCondaPackageService.listAllPackagesAndVersions(); - if (packages == null) return Collections.emptyList(); - final List results = new ArrayList<>(); - for (String pkg : packages.keySet()) { - results.add(new RepoPackage(pkg, null, ContainerUtil.getFirstItem(packages.get(pkg)))); - } - return results; - } - else { - return super.reloadAllPackages(); - } - } - - - @Override - public void fetchAllRepositories(@NotNull CatchingConsumer, ? super Exception> consumer) { - if (useConda()) { - myExecutorService.execute(() -> { - try { - final List channels = ContainerUtil.notNullize(PyCondaPackageService.listChannels()); - consumer.consume(channels); - } - catch (ExecutionException e) { - consumer.consume(e); - } - }); - } - else { - super.fetchAllRepositories(consumer); - } - } - - @Override - public void addRepository(String repositoryUrl) { - if (useConda()) { - ProgressManager.getInstance().run(new Task.Modal(getProject(), PyBundle.message("python.packaging.adding.conda.channel"), true) { - @Override - public void run(@NotNull ProgressIndicator indicator) { - indicator.setIndeterminate(true); - try { - PyCondaRunKt.runConda(mySdk, Arrays.asList("config", "--add", "channels", repositoryUrl, "--force")); - } - catch (ExecutionException e) { - LOG.warn("Failed to add repository. " + e); - } - } - }); - } - else { - super.addRepository(repositoryUrl); - } - } - - @Override - public void removeRepository(String repositoryUrl) { - if (useConda()) { - ProgressManager.getInstance().run(new Task.Modal(getProject(), PyBundle.message("python.packaging.removing.conda.channel"), true) { - @Override - public void run(@NotNull ProgressIndicator indicator) { - indicator.setIndeterminate(true); - try { - PyCondaRunKt.runConda(mySdk, Arrays.asList("config", "--remove", "channels", repositoryUrl, "--force")); - } - catch (ExecutionException e) { - LOG.warn("Failed to remove repository. " + e); - } - } - }); - } - else { - super.removeRepository(repositoryUrl); - } - } - - @Override - public boolean canInstallToUser() { - return !useConda() && super.canInstallToUser(); - } - - @Override - public void fetchPackageVersions(String packageName, CatchingConsumer, ? super Exception> consumer) { - if (useConda()) { - myExecutorService.execute(() -> { - try { - consumer.consume(PyCondaPackageService.listPackageVersions(packageName)); - } - catch (ExecutionException e) { - consumer.consume(e); - } - }); - } - else { - super.fetchPackageVersions(packageName, consumer); - } - } - - @Override - public void fetchLatestVersion(@NotNull InstalledPackage pkg, @NotNull CatchingConsumer consumer) { - final String packageName = pkg.getName(); - if (useConda()) { - myExecutorService.execute(() -> { - try { - final String latestVersion = ContainerUtil.getFirstItem(PyCondaPackageService.listPackageVersions(packageName)); - consumer.consume(latestVersion); - } - catch (ExecutionException e) { - consumer.consume(e); - } - }); - } - else { - super.fetchLatestVersion(pkg, consumer); - } - } - - @Override - public boolean shouldFetchLatestVersionsForOnlyInstalledPackages() { - return false; - } -}