use of org.python.pydev.core.NotConfiguredInterpreterException in project Pydev by fabioz.
the class AbstractInterpreterManager method getDefaultInterpreterInfo.
/**
* @throws NotConfiguredInterpreterException
* @see org.python.pydev.core.IInterpreterManager#getDefaultInterpreterInfo()
*/
@Override
public IInterpreterInfo getDefaultInterpreterInfo(boolean autoConfigureIfNotConfigured) throws NotConfiguredInterpreterException {
IInterpreterInfo[] interpreters = getInterpreterInfos();
String errorMsg = null;
if (interpreters.length > 0) {
IInterpreterInfo defaultInfo = interpreters[0];
String interpreter = defaultInfo.getExecutableOrJar();
if (interpreter == null) {
errorMsg = "The configured interpreter for " + getInterpreterUIName() + " is null, some error happened getting it.";
}
return defaultInfo;
} else {
errorMsg = getInterpreterUIName() + " not configured.";
}
if (autoConfigureIfNotConfigured && configWhenInterpreterNotAvailable != null) {
configWhenInterpreterNotAvailable.call(this);
}
throw new NotConfiguredInterpreterException(errorMsg);
}
use of org.python.pydev.core.NotConfiguredInterpreterException in project Pydev by fabioz.
the class ChooseProcessTypeDialog method configureEditorButton.
/**
* Configures a button related to an editor.
* @throws MisconfigurationException
*/
private void configureEditorButton() {
boolean enabled = false;
String text;
try {
if (this.activeEditor != null) {
IPythonNature nature = this.activeEditor.getPythonNature();
if (nature != null) {
if (nature.getRelatedInterpreterManager().getDefaultInterpreterInfo(false) != null) {
text = "Console for currently active editor";
enabled = true;
} else {
throw new NotConfiguredInterpreterException();
}
} else {
text = "No python nature configured for the current editor";
}
} else {
text = "Unable to create console for current editor (no active editor)";
}
} catch (MisconfigurationException e) {
// expected
text = "Unable to create console for current editor (interpreter not configured for the editor)";
}
checkboxForCurrentEditor.setText(text);
checkboxForCurrentEditor.setEnabled(enabled);
}
use of org.python.pydev.core.NotConfiguredInterpreterException in project Pydev by fabioz.
the class AbstractInterpreterManager method restorePythopathForNatures.
private void restorePythopathForNatures(IProgressMonitor monitor) {
IInterpreterInfo defaultInterpreterInfo;
try {
defaultInterpreterInfo = getDefaultInterpreterInfo(false);
} catch (NotConfiguredInterpreterException e1) {
// go on as usual... (the natures must know that they're not bound to an interpreter anymore).
defaultInterpreterInfo = null;
}
FastStringBuffer buf = new FastStringBuffer();
// Also notify that all the natures had the pythonpath changed (it's the system pythonpath, but still,
// clients need to know about it)
List<IPythonNature> pythonNatures;
try {
pythonNatures = PythonNature.getAllPythonNatures();
} catch (IllegalStateException e1) {
// at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:367)
return;
}
for (IPythonNature nature : pythonNatures) {
try {
// If they have the same type of the interpreter manager, notify.
if (this.getInterpreterType() == nature.getInterpreterType()) {
IPythonPathNature pythonPathNature = nature.getPythonPathNature();
// There's a catch here: if the nature uses some variable defined in the string substitution
// from the interpreter info, we need to do a full build instead of only making a notification.
String complete = pythonPathNature.getProjectExternalSourcePath(false) + pythonPathNature.getProjectSourcePath(false);
PythonNature n = (PythonNature) nature;
String projectInterpreterName = n.getProjectInterpreterName();
IInterpreterInfo info;
if (IPythonNature.DEFAULT_INTERPRETER.equals(projectInterpreterName)) {
// if it's the default, let's translate it to the outside world
info = defaultInterpreterInfo;
} else {
synchronized (lock) {
info = exeToInfo.get(projectInterpreterName);
}
}
boolean makeCompleteRebuild = false;
if (info != null) {
Properties stringSubstitutionVariables = info.getStringSubstitutionVariables(false);
if (stringSubstitutionVariables != null) {
Enumeration<Object> keys = stringSubstitutionVariables.keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
buf.clear();
buf.append("${");
buf.append(key.toString());
buf.append("}");
if (complete.indexOf(buf.toString()) != -1) {
makeCompleteRebuild = true;
break;
}
}
}
}
if (!makeCompleteRebuild) {
// just notify that it changed
if (nature instanceof PythonNature) {
((PythonNature) nature).clearCaches(true);
}
PythonNatureListenersManager.notifyPythonPathRebuilt(nature.getProject(), nature);
} else {
// Rebuild the whole info.
nature.rebuildPath();
}
}
} catch (Throwable e) {
Log.log(e);
}
}
}
use of org.python.pydev.core.NotConfiguredInterpreterException in project Pydev by fabioz.
the class PyEdit method getPythonNature.
/**
* @return the python nature associated with this editor.
* @throws NotConfiguredInterpreterException
*/
@Override
public IPythonNature getPythonNature() throws MisconfigurationException {
IProject project = getProject();
if (project == null || !project.isOpen()) {
return null;
}
IPythonNature pythonNature = PythonNature.getPythonNature(project);
if (pythonNature != null) {
return pythonNature;
}
// if it's an external file, there's the possibility that it won't be added even here.
pythonNature = addNature(this.getEditorInput());
if (pythonNature != null) {
return pythonNature;
}
File editorFile = getEditorFile();
if (editorFile == null) {
return null;
}
Tuple<IPythonNature, String> infoForFile = InterpreterManagersAPI.getInfoForFile(editorFile);
if (infoForFile == null) {
NotConfiguredInterpreterException e = new NotConfiguredInterpreterException();
ErrorDialog.openError(EditorUtils.getShell(), "Error: no interpreter configured", "Interpreter not configured\n(Please, Configure it under window->preferences->PyDev)", SharedCorePlugin.makeStatus(IStatus.ERROR, e.getMessage(), e));
throw e;
}
pythonNature = infoForFile.o1;
return pythonNature;
}
use of org.python.pydev.core.NotConfiguredInterpreterException in project Pydev by fabioz.
the class ConfigureInterpreterJob method runInUIThread.
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Set<AbstractInterpreterManager> current = interpreters;
interpreters = new HashSet<AbstractInterpreterManager>();
for (AbstractInterpreterManager m : current) {
try {
m.getDefaultInterpreterInfo(false);
// Maybe it got configured at some other point...
continue;
} catch (NotConfiguredInterpreterException e) {
int ret = PyDialogHelpers.openQuestionConfigureInterpreter(m);
if (ret != PyDialogHelpers.INTERPRETER_CANCEL_CONFIG) {
if (ret == InterpreterConfigHelpers.CONFIG_MANUAL) {
PreferencesUtil.createPreferenceDialogOn(null, m.getPreferencesPageId(), null, null).open();
} else if (ret == InterpreterConfigHelpers.CONFIG_ADV_AUTO || ret == InterpreterConfigHelpers.CONFIG_AUTO) {
InterpreterType interpreterType;
switch(m.getInterpreterType()) {
case IPythonNature.INTERPRETER_TYPE_JYTHON:
interpreterType = InterpreterType.JYTHON;
break;
case IPythonNature.INTERPRETER_TYPE_IRONPYTHON:
interpreterType = InterpreterType.IRONPYTHON;
break;
default:
interpreterType = InterpreterType.PYTHON;
}
boolean advanced = ret == InterpreterConfigHelpers.CONFIG_ADV_AUTO;
AutoConfigMaker a = new AutoConfigMaker(interpreterType, advanced, null, null);
a.autoConfigSingleApply(null);
} else {
Log.log("Unexpected option: " + ret);
}
}
}
}
return Status.OK_STATUS;
}
Aggregations