mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
manage conda channels
This commit is contained in:
@@ -171,8 +171,7 @@ public class PyCondaPackageManagerImpl extends PyPackageManagerImpl {
|
||||
|
||||
@NotNull
|
||||
public static String createVirtualEnv(@NotNull String destinationDir, String version) throws ExecutionException {
|
||||
final String condaName = SystemInfo.isWindows ? "conda.exe" : "conda";
|
||||
final String condaExecutable = PyCondaPackageService.getCondaExecutable(condaName);
|
||||
final String condaExecutable = PyCondaPackageService.getCondaExecutable();
|
||||
if (condaExecutable == null) throw new PyExecutionException("Cannot find conda", "Conda", Collections.<String>emptyList(), new ProcessOutput());
|
||||
|
||||
final ArrayList<String> parameters = Lists.newArrayList(condaExecutable, "create", "-p", destinationDir,
|
||||
|
||||
@@ -79,12 +79,28 @@ public class PyCondaPackageService implements PersistentStateComponent<PyCondaPa
|
||||
return CONDA_CHANNELS;
|
||||
}
|
||||
|
||||
public void addChannel(@NotNull final String url) {
|
||||
CONDA_CHANNELS.add(url);
|
||||
}
|
||||
|
||||
public void removeChannel(@NotNull final String url) {
|
||||
if (CONDA_CHANNELS.contains(url)) {
|
||||
CONDA_CHANNELS.remove(url);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getCondaPython() {
|
||||
final String condaName = SystemInfo.isWindows ? "python.exe" : "python";
|
||||
return getCondaExecutable(condaName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getCondaExecutable() {
|
||||
final String condaName = SystemInfo.isWindows ? "conda.exe" : "conda";
|
||||
return getCondaExecutable(condaName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getCondaExecutable(@NotNull final String condaName) {
|
||||
final VirtualFile userHome = LocalFileSystem.getInstance().findFileByPath(SystemProperties.getUserHome().replace('\\', '/'));
|
||||
|
||||
@@ -15,8 +15,15 @@
|
||||
*/
|
||||
package com.jetbrains.python.packaging.ui;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.CapturingProcessHandler;
|
||||
import com.intellij.execution.process.ProcessOutput;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.CatchingConsumer;
|
||||
import com.intellij.webcore.packaging.PackageVersionComparator;
|
||||
import com.intellij.webcore.packaging.RepoPackage;
|
||||
@@ -28,7 +35,7 @@ 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);
|
||||
}
|
||||
@@ -58,6 +65,53 @@ public class PyCondaManagementService extends PyPackageManagementService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRepository(String repositoryUrl) {
|
||||
final String conda = PyCondaPackageService.getCondaExecutable();
|
||||
final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--add", "channels", repositoryUrl, "--force");
|
||||
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
|
||||
|
||||
try {
|
||||
final Process process = commandLine.createProcess();
|
||||
final CapturingProcessHandler handler = new CapturingProcessHandler(process);
|
||||
final ProcessOutput result = handler.runProcess();
|
||||
final int exitCode = result.getExitCode();
|
||||
if (exitCode != 0) {
|
||||
final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ?
|
||||
"Permission denied" : "Non-zero exit code";
|
||||
LOG.warn("Failed to add repository " + message);
|
||||
}
|
||||
PyCondaPackageService.getInstance().addChannel(repositoryUrl);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.warn("Failed to add repository");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRepository(String repositoryUrl) {
|
||||
final String conda = PyCondaPackageService.getCondaExecutable();
|
||||
final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--remove", "channels", repositoryUrl, "--force");
|
||||
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
|
||||
|
||||
try {
|
||||
final Process process = commandLine.createProcess();
|
||||
final CapturingProcessHandler handler = new CapturingProcessHandler(process);
|
||||
final ProcessOutput result = handler.runProcess();
|
||||
final int exitCode = result.getExitCode();
|
||||
if (exitCode != 0) {
|
||||
final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ?
|
||||
"Permission denied" : "Non-zero exit code";
|
||||
LOG.warn("Failed to remove repository " + message);
|
||||
}
|
||||
PyCondaPackageService.getInstance().removeChannel(repositoryUrl);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
LOG.warn("Failed to remove repository");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInstallToUser() {
|
||||
return false;
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.intellij.openapi.ui.popup.ListSeparator;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.util.NullableConsumer;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.packaging.PyCondaPackageService;
|
||||
@@ -110,8 +109,7 @@ public class PythonSdkDetailsStep extends BaseListPopupStep<String> {
|
||||
options.add(REMOTE);
|
||||
}
|
||||
options.add(VIRTUALENV);
|
||||
final String condaName = SystemInfo.isWindows ? "conda.exe" : "conda";
|
||||
if (PyCondaPackageService.getCondaExecutable(condaName) != null) {
|
||||
if (PyCondaPackageService.getCondaExecutable() != null) {
|
||||
options.add(CONDA);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user