use of org.python.pydev.core.IInterpreterManager in project ibex_gui by ISISComputingGroup.
the class GeniePythonConsoleFactory method createGeniePydevInterpreter.
/**
* Creates a Genie Python Interpreter.
*
* @return Interpreter
* @throws Exception
* can throw several different exceptions
*/
PydevConsoleInterpreter createGeniePydevInterpreter() throws Exception {
IInterpreterManager manager = InterpreterManagersAPI.getPythonInterpreterManager();
IInterpreterInfo interpreterInfo = manager.createInterpreterInfo(PreferenceSupplier.getPythonPath(), monitor, false);
PydevIProcessFactory iprocessFactory = new PydevIProcessFactory();
PydevConsoleLaunchInfo launchAndProcess = iprocessFactory.createLaunch(manager, interpreterInfo, interpreterInfo.getPythonPath(), null, null);
return createPydevInterpreter(launchAndProcess, null, null);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class InterpreterManagersAPI method getInfoForFile.
/**
* @param file the file we want to get info on.
* @return a tuple with the nature to be used and the name of the module represented by the file in that scenario.
*/
public static Tuple<IPythonNature, String> getInfoForFile(File file) {
IInterpreterManager pythonInterpreterManager2 = getPythonInterpreterManager(false);
IInterpreterManager jythonInterpreterManager2 = getJythonInterpreterManager(false);
IInterpreterManager ironpythonInterpreterManager2 = getIronpythonInterpreterManager(false);
if (file != null) {
// Check if we can resolve the manager for the passed file...
Tuple<IPythonNature, String> infoForManager = getInfoForManager(file, pythonInterpreterManager2);
if (infoForManager != null) {
return infoForManager;
}
infoForManager = getInfoForManager(file, jythonInterpreterManager2);
if (infoForManager != null) {
return infoForManager;
}
infoForManager = getInfoForManager(file, ironpythonInterpreterManager2);
if (infoForManager != null) {
return infoForManager;
}
// Ok, the file is not part of the interpreter configuration, but it's still possible that it's part of a
// project... (external projects), so, let's go on and see if there's some match there.
List<IPythonNature> allPythonNatures = PythonNature.getAllPythonNatures();
int size = allPythonNatures.size();
for (int i = 0; i < size; i++) {
IPythonNature nature = allPythonNatures.get(i);
try {
// Note: only resolve in the project sources, as we've already checked the system and we'll be
// checking all projects anyways.
String modName = nature.resolveModuleOnlyInProjectSources(FileUtils.getFileAbsolutePath(file), true);
if (modName != null) {
return new Tuple<IPythonNature, String>(nature, modName);
}
} catch (Exception e) {
Log.log(e);
}
}
}
if (pythonInterpreterManager2.isConfigured()) {
try {
return new Tuple<IPythonNature, String>(new SystemPythonNature(pythonInterpreterManager2), getModNameFromFile(file));
} catch (MisconfigurationException e) {
}
}
if (jythonInterpreterManager2.isConfigured()) {
try {
return new Tuple<IPythonNature, String>(new SystemPythonNature(jythonInterpreterManager2), getModNameFromFile(file));
} catch (MisconfigurationException e) {
}
}
if (ironpythonInterpreterManager2.isConfigured()) {
try {
return new Tuple<IPythonNature, String>(new SystemPythonNature(ironpythonInterpreterManager2), getModNameFromFile(file));
} catch (MisconfigurationException e) {
}
}
// Ok, nothing worked, let's just do a call which'll ask to configure python and return null!
try {
pythonInterpreterManager2.getDefaultInterpreterInfo(true);
} catch (MisconfigurationException e) {
// Ignore
}
return null;
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class InterpreterManagersAPI method getAllInterpreterInfos.
public static List<IInterpreterInfo> getAllInterpreterInfos() {
List<IInterpreterInfo> infos = new ArrayList<>();
IInterpreterManager[] allInterpreterManagers = getAllInterpreterManagers();
for (IInterpreterManager iInterpreterManager : allInterpreterManagers) {
if (iInterpreterManager != null) {
infos.addAll(Arrays.asList(iInterpreterManager.getInterpreterInfos()));
}
}
return infos;
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class Pep8Runner method runWithPep8BaseScript.
/**
* @param fileContents the contents to be passed in the stdin.
* @param parameters the parameters to pass. Note that a '-' is always added to the parameters to signal we'll pass the file as the input in stdin.
* @param script i.e.: pycodestyle.py, autopep8.py
* @return null if there was some error, otherwise returns the process stdout output.
*/
public static String runWithPep8BaseScript(IDocument doc, String parameters, String script) {
File autopep8File;
try {
autopep8File = CorePlugin.getScriptWithinPySrc(new Path("third_party").append("pep8").append(script).toString());
} catch (CoreException e) {
Log.log("Unable to get " + script + " location.");
return null;
}
if (!autopep8File.exists()) {
Log.log("Specified location for " + script + " does not exist (" + autopep8File + ").");
return null;
}
SimplePythonRunner simplePythonRunner = new SimplePythonRunner();
IInterpreterManager pythonInterpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
IInterpreterInfo defaultInterpreterInfo;
try {
defaultInterpreterInfo = pythonInterpreterManager.getDefaultInterpreterInfo(false);
} catch (MisconfigurationException e) {
Log.log("No default Python interpreter configured to run " + script);
return null;
}
String[] parseArguments = ProcessUtils.parseArguments(parameters);
List<String> lst = new ArrayList<>(Arrays.asList(parseArguments));
lst.add("-");
String[] cmdarray = SimplePythonRunner.preparePythonCallParameters(defaultInterpreterInfo.getExecutableOrJar(), autopep8File.toString(), lst.toArray(new String[0]));
// Try to find the file's encoding, but if none is given or the specified encoding is
// unsupported, then just default to utf-8
String pythonFileEncoding = null;
try {
pythonFileEncoding = FileUtils.getPythonFileEncoding(doc, null);
if (pythonFileEncoding == null) {
pythonFileEncoding = "utf-8";
}
} catch (UnsupportedEncodingException e) {
pythonFileEncoding = "utf-8";
}
final String encodingUsed = pythonFileEncoding;
SystemPythonNature nature = new SystemPythonNature(pythonInterpreterManager, defaultInterpreterInfo);
ICallback<String[], String[]> updateEnv = new ICallback<String[], String[]>() {
@Override
public String[] call(String[] arg) {
if (arg == null) {
arg = new String[] { "PYTHONIOENCODING=" + encodingUsed };
} else {
arg = ProcessUtils.addOrReplaceEnvVar(arg, "PYTHONIOENCODING", encodingUsed);
}
return arg;
}
};
Tuple<Process, String> r = simplePythonRunner.run(cmdarray, autopep8File.getParentFile(), nature, new NullProgressMonitor(), updateEnv);
try {
r.o1.getOutputStream().write(doc.get().getBytes(pythonFileEncoding));
r.o1.getOutputStream().close();
} catch (IOException e) {
Log.log("Error writing contents to " + script);
return null;
}
Tuple<String, String> processOutput = SimplePythonRunner.getProcessOutput(r.o1, r.o2, new NullProgressMonitor(), pythonFileEncoding);
if (processOutput.o2.length() > 0) {
Log.log(processOutput.o2);
}
if (processOutput.o1.length() > 0) {
return processOutput.o1;
}
return null;
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class DjangoNewProjectPage method getNextPage.
@Override
public IWizardPage getNextPage() {
String projectType = this.getProjectType();
IInterpreterManager interpreterManager;
if (IPythonNature.Versions.ALL_JYTHON_VERSIONS.contains(projectType)) {
interpreterManager = InterpreterManagersAPI.getJythonInterpreterManager();
} else if (IPythonNature.Versions.ALL_IRONPYTHON_VERSIONS.contains(projectType)) {
interpreterManager = InterpreterManagersAPI.getIronpythonInterpreterManager();
} else {
// if others fail, consider it python
interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
}
try {
String projectInterpreter = this.getProjectInterpreter();
IInterpreterInfo interpreterInfo;
if (projectInterpreter.toLowerCase().equals("default")) {
interpreterInfo = interpreterManager.getDefaultInterpreterInfo(false);
} else {
interpreterInfo = interpreterManager.getInterpreterInfo(projectInterpreter, new NullProgressMonitor());
}
IModule module = interpreterInfo.getModulesManager().getModuleWithoutBuiltins("django.core.__init__", null, false, new BaseModuleRequest(false));
if (module == null) {
DjangoNotAvailableWizardPage page = new DjangoNotAvailableWizardPage("Django not available", interpreterInfo);
page.setWizard(this.getWizard());
return page;
}
} catch (MisconfigurationException e) {
ErrorWizardPage page = new ErrorWizardPage("Unexpected error.", "An unexpected error happened:\n" + e.getMessage());
page.setWizard(this.getWizard());
return page;
}
return super.getNextPage();
}
Aggregations