use of org.python.pydev.core.IInterpreterInfo.UnableToFindExecutableException in project Pydev by fabioz.
the class CondaPackageManager method manage.
public void manage(String[] initialCommands, boolean autoRun, File workingDir) {
final File condaExecutable;
try {
condaExecutable = PyDevCondaPreferences.findCondaExecutable(interpreterInfo);
} catch (UnableToFindExecutableException e) {
Log.log(e);
PyDialogHelpers.openException("Unable to find conda", e);
return;
}
ProcessWindow processWindow = new ProcessWindow(UIUtils.getActiveShell()) {
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Manage conda");
}
@Override
protected String[] getAvailableCommands() {
List<String> lst = new ArrayList<>(Arrays.asList(initialCommands));
final String prefixDir = new File(interpreterInfo.getExecutableOrJar()).getParent();
String prefixInfo = " -p " + prefixDir;
for (int i = 0; i < lst.size(); i++) {
String existing = lst.get(i);
if (!existing.contains("-p")) {
existing = existing.trim();
if (existing.startsWith("install") || existing.startsWith("uninstall") || existing.startsWith("upgrade") || existing.startsWith("update") || existing.startsWith("clean") || existing.startsWith("list") || existing.startsWith("package") || existing.startsWith("remove") || existing.startsWith("search")) {
existing += prefixInfo;
}
lst.set(i, existing);
}
}
return ArrayUtils.concatArrays(lst.toArray(new String[0]), new String[] { "install -p " + prefixDir + " <package>", "uninstall -p " + prefixDir + " <package>" });
}
@Override
protected String getSeeURL() {
return "https://conda.io/docs/commands.html";
}
@Override
public Tuple<Process, String> createProcess(String[] arguments) {
clearOutput();
AbstractShell.restartAllShells();
String[] cmdLine = ArrayUtils.concatArrays(new String[] { condaExecutable.toString() }, arguments);
return new SimpleRunner().run(cmdLine, workingDir, null, null);
}
};
if (workingDir == null) {
workingDir = condaExecutable.getParentFile();
}
processWindow.setParameters(null, null, condaExecutable, workingDir);
processWindow.setAutoRun(autoRun);
processWindow.open();
}
use of org.python.pydev.core.IInterpreterInfo.UnableToFindExecutableException in project Pydev by fabioz.
the class PipPackageManager method list.
/**
* To be called from any thread
*/
@Override
public List<String[]> list() {
List<String[]> listed = new ArrayList<String[]>();
File pipExecutable;
Tuple<String, String> output;
try {
pipExecutable = interpreterInfo.searchExecutableForInterpreter("pip", false);
// use system encoding
String encoding = null;
output = new SimpleRunner().runAndGetOutput(new String[] { pipExecutable.toString(), "list", "--format=columns" }, null, null, null, encoding);
} catch (UnableToFindExecutableException e) {
IPythonNature nature = new SystemPythonNature(interpreterInfo.getModulesManager().getInterpreterManager(), interpreterInfo);
String[] parameters = SimplePythonRunner.preparePythonCallParameters(interpreterInfo.getExecutableOrJar(), "-m", new String[] { getPipModuleName(interpreterInfo), "list", "--format=columns" });
output = new SimplePythonRunner().runAndGetOutput(parameters, null, nature, null, "utf-8");
}
List<String> splitInLines = StringUtils.splitInLines(output.o1, false);
for (String line : splitInLines) {
line = line.trim();
List<String> split = StringUtils.split(line, ' ');
if (split.size() == 2) {
String p0 = split.get(0).trim();
String p1 = split.get(1).trim();
if (p0.toLowerCase().equals("package") && p1.toLowerCase().equals("version")) {
continue;
}
if (p0.toLowerCase().startsWith("--") && p1.toLowerCase().startsWith("--")) {
continue;
}
listed.add(new String[] { p0.trim(), p1.trim(), "<pip>" });
}
}
if (output.o2.toLowerCase().contains("no module named pip")) {
listed.add(new String[] { "pip not installed (or not found) in interpreter", "", "" });
} else {
for (String s : StringUtils.iterLines(output.o2)) {
listed.add(new String[] { s, "", "" });
}
}
return listed;
}
use of org.python.pydev.core.IInterpreterInfo.UnableToFindExecutableException in project Pydev by fabioz.
the class CondaPackageManager method list.
@Override
public List<String[]> list() {
List<String[]> listed = new ArrayList<String[]>();
File condaExecutable;
try {
condaExecutable = PyDevCondaPreferences.findCondaExecutable(interpreterInfo);
} catch (UnableToFindExecutableException e) {
return errorToList(listed, e);
}
// use system encoding
String encoding = null;
Tuple<String, String> output = new SimpleRunner().runAndGetOutput(new String[] { condaExecutable.toString(), "list", "-p", prefix.toString(), "--json" }, null, null, null, encoding);
try {
JsonValue readFrom = JsonValue.readFrom(output.o1);
JsonArray asArray = readFrom.asArray();
for (JsonValue value : asArray) {
JsonObject asObject = value.asObject();
JsonValue name = asObject.get("name");
JsonValue version = asObject.get("version");
JsonValue channel = asObject.get("channel");
JsonValue buildString = asObject.get("build_string");
listed.add(new String[] { name.asString(), version.asString(), StringUtils.join("", buildString.asString(), " (", channel.asString(), ")") });
}
} catch (Exception e) {
// Older version of Conda had a different json format and "list --json" wouldn't show pip info, so,
// fallback to an implementation which just did a conda list without --json and parse its output
output = new SimpleRunner().runAndGetOutput(new String[] { condaExecutable.toString(), "list", "-p", prefix.toString() }, null, null, null, encoding);
List<String> splitInLines = StringUtils.splitInLines(output.o1, false);
for (String line : splitInLines) {
line = line.trim();
if (line.startsWith("#")) {
continue;
}
List<String> split = StringUtils.split(line, ' ');
if (split.size() >= 3) {
listed.add(new String[] { split.get(0), split.get(1), StringUtils.join(" - ", split.subList(2, split.size() - 1)) });
} else if (split.size() == 2) {
listed.add(new String[] { split.get(0), split.get(1), "" });
}
}
}
return listed;
}
use of org.python.pydev.core.IInterpreterInfo.UnableToFindExecutableException in project Pydev by fabioz.
the class PipPackageManager method manage.
public void manage(final String[] initialCommand, final boolean autoRun) {
File pipExecutable;
String[] availableCommands = new String[] { "install <package>", "uninstall <package>" };
try {
pipExecutable = interpreterInfo.searchExecutableForInterpreter("pip", false);
} catch (UnableToFindExecutableException e) {
availableCommands = new String[] { "-m " + getPipModuleName(interpreterInfo) + " install <package>", "-m " + getPipModuleName(interpreterInfo) + " uninstall <package>" };
pipExecutable = new File(interpreterInfo.getExecutableOrJar());
}
final String[] availableCommandsFinal = ArrayUtils.concatArrays(initialCommand, availableCommands);
final File pipExecutableFinal = pipExecutable;
ProcessWindow processWindow = new ProcessWindow(UIUtils.getActiveShell()) {
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Manage pip");
}
@Override
protected String[] getAvailableCommands() {
return availableCommandsFinal;
}
@Override
protected String getSeeURL() {
return "https://pip.pypa.io/en/stable";
}
@Override
public Tuple<Process, String> createProcess(String[] arguments) {
clearOutput();
AbstractShell.restartAllShells();
String[] cmdLine = ArrayUtils.concatArrays(new String[] { pipExecutableFinal.toString() }, arguments);
return new SimpleRunner().run(cmdLine, workingDir, pythonPathNature.getNature(), null);
}
};
IPythonPathNature pythonPathNature = null;
try {
pythonPathNature = interpreterInfo.getModulesManager().getNature().getPythonPathNature();
} catch (Exception e) {
Log.log(e);
}
processWindow.setParameters(null, pythonPathNature, pipExecutableFinal, pipExecutableFinal.getParentFile());
processWindow.setAutoRun(autoRun);
processWindow.open();
}
Aggregations