use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class RunEditorBasedOnNatureTypeAction method run.
@Override
public void run(IAction action) {
PyEdit pyEdit = getPyEdit();
final Tuple<String, IInterpreterManager> launchConfigurationTypeAndInterpreterManager = this.getLaunchConfigurationTypeAndInterpreterManager(pyEdit, false);
AbstractLaunchShortcut shortcut = new AbstractLaunchShortcut() {
@Override
protected String getLaunchConfigurationType() {
return launchConfigurationTypeAndInterpreterManager.o1;
}
@Override
protected IInterpreterManager getInterpreterManager(IProject project) {
return launchConfigurationTypeAndInterpreterManager.o2;
}
};
shortcut.launch(pyEdit, "run");
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class PythonPathBlock method initializeFrom.
/*
* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
String id = configuration.getType().getIdentifier();
IInterpreterManager manager = null;
if (Constants.ID_JYTHON_LAUNCH_CONFIGURATION_TYPE.equals(id) || Constants.ID_JYTHON_UNITTEST_LAUNCH_CONFIGURATION_TYPE.equals(id)) {
manager = InterpreterManagersAPI.getJythonInterpreterManager();
} else if (Constants.ID_IRONPYTHON_LAUNCH_CONFIGURATION_TYPE.equals(id) || Constants.ID_IRONPYTHON_UNITTEST_LAUNCH_CONFIGURATION_TYPE.equals(id)) {
manager = InterpreterManagersAPI.getIronpythonInterpreterManager();
} else if (Constants.ID_PYTHON_REGULAR_LAUNCH_CONFIGURATION_TYPE.equals(id) || Constants.ID_PYTHON_COVERAGE_LAUNCH_CONFIGURATION_TYPE.equals(id) || Constants.ID_PYTHON_UNITTEST_LAUNCH_CONFIGURATION_TYPE.equals(id)) {
manager = InterpreterManagersAPI.getPythonInterpreterManager();
} else {
// Get from the project
try {
// could throw core exception if project does not exist.
IProject project = PythonRunnerConfig.getProjectFromConfiguration(configuration);
PythonNature nature = PythonNature.getPythonNature(project);
if (nature != null) {
manager = InterpreterManagersAPI.getInterpreterManager(nature);
}
} catch (Exception e) {
Log.log(e);
}
if (manager == null) {
Log.log("Could not recognize: '" + id + "' using default python interpreter manager.");
manager = InterpreterManagersAPI.getPythonInterpreterManager();
}
}
String pythonPath = PythonRunnerConfig.getPythonpathFromConfiguration(configuration, manager);
fPythonPathList.removeAll();
java.util.List<String> paths = SimpleRunner.splitPythonpath(pythonPath);
for (String p : paths) {
fPythonPathList.add(p);
}
setErrorMessage(null);
} catch (Exception e) {
// Exceptions here may have several reasons
// - The interpreter is incorrectly configured
// - The arguments use an unresolved variable.
// In each case, the exception contains a meaningful message, that is displayed
Log.log(e);
String message = e.getMessage();
if (message == null) {
message = "null (see error log for the traceback).";
}
String errorMsg = StringUtils.replaceNewLines(message, " ");
fPythonPathList.removeAll();
fPythonPathList.add(errorMsg);
setErrorMessage(errorMsg);
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class AbstractRunEditorAction method getLaunchConfigurationTypeAndInterpreterManager.
protected Tuple<String, IInterpreterManager> getLaunchConfigurationTypeAndInterpreterManager(PyEdit pyEdit, boolean isUnitTest) {
String launchConfigurationType;
String defaultType = Constants.ID_PYTHON_REGULAR_LAUNCH_CONFIGURATION_TYPE;
IInterpreterManager interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
try {
IPythonNature nature = pyEdit.getPythonNature();
if (nature == null) {
launchConfigurationType = defaultType;
} else {
int interpreterType = nature.getInterpreterType();
interpreterManager = nature.getRelatedInterpreterManager();
switch(interpreterType) {
case IInterpreterManager.INTERPRETER_TYPE_PYTHON:
if (isUnitTest) {
launchConfigurationType = Constants.ID_PYTHON_UNITTEST_LAUNCH_CONFIGURATION_TYPE;
} else {
launchConfigurationType = Constants.ID_PYTHON_REGULAR_LAUNCH_CONFIGURATION_TYPE;
}
break;
case IInterpreterManager.INTERPRETER_TYPE_IRONPYTHON:
if (isUnitTest) {
launchConfigurationType = Constants.ID_IRONPYTHON_UNITTEST_LAUNCH_CONFIGURATION_TYPE;
} else {
launchConfigurationType = Constants.ID_IRONPYTHON_LAUNCH_CONFIGURATION_TYPE;
}
break;
case IInterpreterManager.INTERPRETER_TYPE_JYTHON:
if (isUnitTest) {
launchConfigurationType = Constants.ID_JYTHON_UNITTEST_LAUNCH_CONFIGURATION_TYPE;
} else {
launchConfigurationType = Constants.ID_JYTHON_LAUNCH_CONFIGURATION_TYPE;
}
break;
default:
throw new RuntimeException("Cannot recognize type: " + interpreterType);
}
}
} catch (Exception e) {
Log.log(IStatus.INFO, "Problem determining nature type. Using regular python launch.", e);
launchConfigurationType = defaultType;
}
return new Tuple<String, IInterpreterManager>(launchConfigurationType, interpreterManager);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class DebugEditorBasedOnNatureTypeAction method run.
@Override
public void run(IAction action) {
PyEdit pyEdit = getPyEdit();
final Tuple<String, IInterpreterManager> launchConfigurationTypeAndInterpreterManager = this.getLaunchConfigurationTypeAndInterpreterManager(pyEdit, false);
AbstractLaunchShortcut shortcut = new AbstractLaunchShortcut() {
@Override
protected String getLaunchConfigurationType() {
return launchConfigurationTypeAndInterpreterManager.o1;
}
@Override
protected IInterpreterManager getInterpreterManager(IProject project) {
return launchConfigurationTypeAndInterpreterManager.o2;
}
};
shortcut.launch(pyEdit, "debug");
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class AbstractLaunchShortcut method createDefaultLaunchConfigurationWithoutSaving.
public ILaunchConfigurationWorkingCopy createDefaultLaunchConfigurationWithoutSaving(FileOrResource[] resource) throws CoreException {
IProject project;
if (resource[0].resource != null) {
project = resource[0].resource.getProject();
} else {
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
List<IProject> projectsLst = ArrayUtils.filter(projects, new ICallback<Boolean, IProject>() {
@Override
public Boolean call(IProject arg) {
IProject project = arg;
try {
return project.isOpen() && project.hasNature(PythonNature.PYTHON_NATURE_ID);
} catch (CoreException e) {
return false;
}
}
});
final Object[] found = new Object[1];
if (projectsLst.size() == 0) {
found[0] = new CoreException(new StatusInfo(IStatus.ERROR, "Found no projects with the Python nature in the workspace."));
} else if (projectsLst.size() == 1) {
found[0] = projectsLst.get(0);
} else {
RunInUiThread.sync(new Runnable() {
@Override
public void run() {
ProjectSelectionDialog dialog = new ProjectSelectionDialog(EditorUtils.getShell(), PythonNature.PYTHON_NATURE_ID);
dialog.setMessage("Choose the project that'll provide the interpreter and\n" + "PYTHONPATH to be used in the launch of the file.");
if (dialog.open() == Window.OK) {
Object firstResult = dialog.getFirstResult();
if (firstResult instanceof IProject) {
found[0] = firstResult;
} else {
found[0] = new CoreException(new StatusInfo(IStatus.ERROR, "Expected project to be selected."));
}
}
}
});
}
if (found[0] == null) {
return null;
}
if (found[0] instanceof IProject) {
project = (IProject) found[0];
} else {
if (found[0] instanceof CoreException) {
throw (CoreException) found[0];
} else {
throw new CoreException(new StatusInfo(IStatus.ERROR, "Expected project, found: " + found[0]));
}
}
}
IInterpreterManager pythonInterpreterManager = getInterpreterManager(project);
String projName = project.getName();
ILaunchConfigurationWorkingCopy createdConfiguration = LaunchConfigurationCreator.createDefaultLaunchConfiguration(resource, getLaunchConfigurationType(), // it'll be made relative later on
LaunchConfigurationCreator.getDefaultLocation(resource, false), pythonInterpreterManager, projName);
// Common Tab Arguments
CommonTab tab = new CommonTab();
tab.setDefaults(createdConfiguration);
tab.dispose();
return createdConfiguration;
}
Aggregations