use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class JythonShell method createServerProcess.
/**
* Will create the jython shell and return a string to be shown to the user with the jython shell command line.
* @throws MisconfigurationException
*/
@Override
protected synchronized ProcessCreationInfo createServerProcess(IInterpreterInfo jythonJar, int port) throws IOException, JDTNotAvailableException, MisconfigurationException {
String script = FileUtils.getFileAbsolutePath(serverFile);
String[] executableStr = SimpleJythonRunner.makeExecutableCommandStr(jythonJar.getExecutableOrJar(), script, "", String.valueOf(port));
IInterpreterManager manager = InterpreterManagersAPI.getJythonInterpreterManager();
String[] envp = null;
try {
envp = SimpleRunner.getEnvironment(null, jythonJar, manager);
} catch (CoreException e) {
Log.log(e);
}
File workingDir = serverFile.getParentFile();
return new ProcessCreationInfo(executableStr, envp, workingDir, SimpleRunner.createProcess(executableStr, envp, workingDir));
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class InterpreterTab method getConfig.
/**
* @param configuration the launch configuration to be used
* @param launchConfigurationDialog the dialog for the launch configuration
* @return a PythonRunnerConfig configured with the given launch configuration
* @throws CoreException
* @throws InvalidRunException
* @throws MisconfigurationException
*/
private PythonRunnerConfig getConfig(ILaunchConfiguration configuration, ILaunchConfigurationDialog launchConfigurationDialog) throws CoreException, InvalidRunException, MisconfigurationException {
String run;
IInterpreterManager interpreterManager = getInterpreterManager();
if (interpreterManager == null) {
return null;
}
switch(interpreterManager.getInterpreterType()) {
case IInterpreterManager.INTERPRETER_TYPE_JYTHON:
run = PythonRunnerConfig.RUN_JYTHON;
break;
case IInterpreterManager.INTERPRETER_TYPE_IRONPYTHON:
run = PythonRunnerConfig.RUN_IRONPYTHON;
break;
case IInterpreterManager.INTERPRETER_TYPE_PYTHON:
run = PythonRunnerConfig.RUN_REGULAR;
break;
default:
throw new RuntimeException("Should be python or jython interpreter (found unknown).");
}
boolean makeArgumentsVariableSubstitution = false;
// we don't want to make the arguments substitution (because it could end opening up a
// dialog for the user requesting something).
PythonRunnerConfig config = new PythonRunnerConfig(configuration, launchConfigurationDialog.getMode(), run, makeArgumentsVariableSubstitution);
return config;
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class InterpreterTab method initializeFrom.
/*
* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
fWorkingCopyForCommandLineGeneration = configuration.getWorkingCopy();
} catch (CoreException e1) {
throw new RuntimeException(e1);
}
IInterpreterManager interpreterManager = this.getInterpreterManager();
String[] interpreterNames = new String[0];
if (interpreterManager != null) {
IInterpreterInfo[] interpreterInfos = interpreterManager.getInterpreterInfos();
if (interpreterInfos.length > 0) {
// There is at least one interpreter defined, add the default interpreter option at the beginning.
interpreterNames = new String[interpreterInfos.length + 1];
interpreterNames[0] = InterpreterTab.DEFAULT_INTERPRETER_NAME;
for (int i = 0; i < interpreterInfos.length; i++) {
interpreterNames[i + 1] = interpreterInfos[i].getName();
}
}
}
fInterpreterComboField.setItems(interpreterNames);
String interpreter = "";
try {
interpreter = configuration.getAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT);
} catch (CoreException e) {
}
if (fInterpreterComboField.getItems().length == 0) {
setErrorMessage("No interpreter is configured, please, go to window > preferences > interpreters and add the interpreter you want to use.");
} else {
int selectThis = -1;
if (interpreter.equals(Constants.ATTR_INTERPRETER_DEFAULT)) {
selectThis = 0;
} else {
if (interpreterManager != null) {
IInterpreterInfo[] interpreterInfos = interpreterManager.getInterpreterInfos();
for (int i = 0; i < interpreterInfos.length; i++) {
if (interpreterInfos[i].matchNameBackwardCompatible(interpreter)) {
// Internally, it's the index+1 (because the one at 0 is the default)
selectThis = i + 1;
break;
}
}
}
}
if (selectThis == -1) {
if (interpreter.startsWith("${")) {
fInterpreterComboField.setText(interpreter);
} else {
setErrorMessage("Obsolete interpreter is selected. Choose a new one.");
}
} else {
fInterpreterComboField.select(selectThis);
}
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class ChooseProcessTypeDialog method okPressed.
/**
* Sets the internal pythonpath chosen.
*/
@Override
protected void okPressed() {
setSelectedFrame(null);
if (checkboxForCurrentEditor.isEnabled() && checkboxForCurrentEditor.getSelection()) {
IProject project = this.activeEditor.getProject();
PythonNature nature = PythonNature.getPythonNature(project);
natures.add(nature);
IInterpreterManager relatedInterpreterManager = nature.getRelatedInterpreterManager();
this.interpreterManager = relatedInterpreterManager;
interactiveConsoleInterpreterRep = PydevConsoleConstants.ACTIVE_EDITOR_INTERPRETER_REPRESENTATION;
} else if (checkboxPython.isEnabled() && checkboxPython.getSelection()) {
this.interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
interactiveConsoleInterpreterRep = PydevConsoleConstants.PYTHON_INTERPRETER_REPRESENTATION;
} else if (checkboxPythonDebug.isEnabled() && checkboxPythonDebug.getSelection()) {
setSelectedFrame(getSuspendedFrame());
this.interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
interactiveConsoleInterpreterRep = PydevConsoleConstants.PYDEV_DEBUG_INTERPRETER_REPRESENTATION;
} else if (checkboxJython.isEnabled() && checkboxJython.getSelection()) {
this.interpreterManager = InterpreterManagersAPI.getJythonInterpreterManager();
interactiveConsoleInterpreterRep = PydevConsoleConstants.JYTHON_INTERPRETER_REPRESENTATION;
} else if (checkboxIronpython.isEnabled() && checkboxIronpython.getSelection()) {
this.interpreterManager = InterpreterManagersAPI.getIronpythonInterpreterManager();
interactiveConsoleInterpreterRep = PydevConsoleConstants.IRONPYTHON_INTERPRETER_REPRESENTATION;
}
if (checkboxSaveSelection.isEnabled() && checkboxSaveSelection.getSelection()) {
InteractiveConsolePrefs.setDefaultInteractiveConsole(interactiveConsoleInterpreterRep);
}
super.okPressed();
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SelectTestTreeContentProvider method run.
@Override
public void run(IAction action) {
PyEdit pyEdit = getPyEdit();
final Tuple<String, IInterpreterManager> launchConfigurationTypeAndInterpreterManager = this.getLaunchConfigurationTypeAndInterpreterManager(pyEdit, true);
Shell shell = EditorUtils.getShell();
final DialogMemento memento = new DialogMemento(shell, "org.python.pydev.debug.ui.actions.RunEditorAsCustomUnitTestAction");
SimpleNode ast = pyEdit.getAST();
final ShiftListener shiftListener = new ShiftListener();
Display d = shell.getDisplay();
d.addFilter(SWT.KeyDown, shiftListener);
d.addFilter(SWT.KeyUp, shiftListener);
try {
final TreeSelectionDialog dialog = new TreeSelectionDialog(shell, new SelectTestLabelProvider(), new SelectTestTreeContentProvider(pyEdit)) {
private Label labelShiftToDebug;
@Override
public boolean close() {
memento.writeSettings(getShell());
return super.close();
}
@Override
public Control createDialogArea(Composite parent) {
memento.readSettings();
Control ret = super.createDialogArea(parent);
ret.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
okPressed();
}
}
});
return ret;
}
/* (non-Javadoc)
* @see org.python.pydev.ui.dialogs.TreeSelectionDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createButtonBar(Composite parent) {
Composite buttonBar = new Composite(parent, 0);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
buttonBar.setLayout(layout);
GridData data = new GridData();
data.horizontalAlignment = SWT.FILL;
data.grabExcessHorizontalSpace = true;
buttonBar.setLayoutData(data);
Link configTestRunner = new Link(buttonBar, SWT.PUSH);
configTestRunner.setText(" <a>Configure test runner</a>");
configTestRunner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
PyUnitPrefsPage2.showPage();
}
});
data = new GridData();
data.horizontalAlignment = GridData.BEGINNING;
data.grabExcessHorizontalSpace = true;
configTestRunner.setLayoutData(data);
labelShiftToDebug = new Label(buttonBar, 0);
labelShiftToDebug.setText("Run: Normal (Press Shift to Debug)");
data = new GridData();
data.horizontalAlignment = GridData.END;
data.grabExcessHorizontalSpace = true;
labelShiftToDebug.setLayoutData(data);
shiftListener.onChanged.registerListener(new ICallbackListener<Boolean>() {
@Override
public Object call(Boolean shiftPressed) {
if (shiftPressed) {
labelShiftToDebug.setText("Run: Debug (Release Shift for Normal)");
} else {
labelShiftToDebug.setText("Run: Normal (Press Shift to Debug)");
}
labelShiftToDebug.getParent().layout(true);
return null;
}
});
Tree tree = getTreeViewer().getTree();
Menu menu = new Menu(tree.getShell(), SWT.POP_UP);
MenuItem runItem = new MenuItem(menu, SWT.PUSH);
final TreeSelectionDialog outerDialog = this;
runItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ILaunchConfiguration conf = null;
IStructuredSelection selection = (IStructuredSelection) getTreeViewer().getSelection();
IEditorInput editorInput = pyEdit.getEditorInput();
IFile resource = editorInput != null ? editorInput.getAdapter(IFile.class) : null;
FileOrResource[] fileOrResource;
if (resource != null) {
fileOrResource = new FileOrResource[] { new FileOrResource(resource) };
} else {
fileOrResource = new FileOrResource[] { new FileOrResource(pyEdit.getEditorFile()) };
}
String testNames = getFullArgumentsRepresentation(selection.toArray());
UnittestLaunchShortcut shortcut = new UnittestLaunchShortcut(launchConfigurationTypeAndInterpreterManager, testNames);
List<ILaunchConfiguration> configurations = shortcut.findExistingLaunchConfigurations(fileOrResource);
boolean newConfiguration = false;
if (configurations.isEmpty()) {
conf = shortcut.createDefaultLaunchConfiguration(fileOrResource);
newConfiguration = true;
} else {
// assume that there's only one matching configuration
conf = configurations.get(0);
}
int retVal = DebugUITools.openLaunchConfigurationDialog(shell, conf, shiftListener.shiftPressed ? IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP : IDebugUIConstants.ID_RUN_LAUNCH_GROUP, null);
if (retVal == Window.CANCEL && newConfiguration) {
// user cancelled operation on newly created configuration
try {
conf.delete();
} catch (CoreException e1) {
// ignore
}
}
if (retVal == Window.OK) {
outerDialog.cancel();
}
}
});
runItem.setText("Customize run configuration...");
tree.setMenu(menu);
return buttonBar;
}
@Override
protected Point getInitialSize() {
return memento.getInitialSize(super.getInitialSize(), getShell());
}
@Override
protected Point getInitialLocation(Point initialSize) {
return memento.getInitialLocation(initialSize, super.getInitialLocation(initialSize), getShell());
}
/*
* @see SelectionStatusDialog#computeResult()
*/
@Override
@SuppressWarnings("unchecked")
protected void computeResult() {
doFinalUpdateBeforeComputeResult();
IStructuredSelection selection = (IStructuredSelection) getTreeViewer().getSelection();
List<Object> list = selection.toList();
if (list.size() > 0) {
setResult(list);
} else {
Tree tree = getTreeViewer().getTree();
TreeItem[] items = tree.getItems();
list = new ArrayList<Object>();
// Now, if he didn't select anything, let's create tests with all that is currently filtered
// in the interface
createListWithLeafs(items, list);
setResult(list);
}
}
private void createListWithLeafs(TreeItem[] items, List<Object> leafObjectsList) {
for (TreeItem item : items) {
TreeItem[] children = item.getItems();
if (children.length == 0) {
leafObjectsList.add(item.getData());
} else {
createListWithLeafs(children, leafObjectsList);
}
}
}
};
dialog.setTitle("PyDev: Select tests to run");
dialog.setMessage("Select the tests to run (press enter to run tests shown/selected)");
PySelection ps = pyEdit.createPySelection();
String selectedText;
try {
selectedText = ps.getSelectedText();
} catch (BadLocationException e) {
selectedText = "";
}
if (selectedText.length() > 0 && PyStringUtils.isValidIdentifier(selectedText, false)) {
// Space in the end == exact match
dialog.setInitialFilter(selectedText + " ");
} else {
dialog.setInitialFilter("test");
}
dialog.setAllowMultiple(true);
dialog.setInput(ast);
int open = dialog.open();
if (open != Window.OK) {
return;
}
Object[] result = dialog.getResult();
final String arguments = getFullArgumentsRepresentation(result);
AbstractLaunchShortcut shortcut = new UnittestLaunchShortcut(launchConfigurationTypeAndInterpreterManager, arguments);
if (shiftListener.shiftPressed) {
shortcut.launch(pyEdit, "debug");
} else {
shortcut.launch(pyEdit, "run");
}
} finally {
d.removeFilter(SWT.KeyDown, shiftListener);
d.removeFilter(SWT.KeyUp, shiftListener);
}
}
Aggregations