Search in sources :

Example 1 with NotConfiguredInterpreterException

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);
}
Also used : IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) NotConfiguredInterpreterException(org.python.pydev.core.NotConfiguredInterpreterException)

Example 2 with NotConfiguredInterpreterException

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);
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) IPythonNature(org.python.pydev.core.IPythonNature) NotConfiguredInterpreterException(org.python.pydev.core.NotConfiguredInterpreterException)

Example 3 with NotConfiguredInterpreterException

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);
        }
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) IPythonNature(org.python.pydev.core.IPythonNature) IPythonPathNature(org.python.pydev.core.IPythonPathNature) Properties(java.util.Properties) NotConfiguredInterpreterException(org.python.pydev.core.NotConfiguredInterpreterException) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo)

Example 4 with NotConfiguredInterpreterException

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;
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) NotConfiguredInterpreterException(org.python.pydev.core.NotConfiguredInterpreterException)

Example 5 with NotConfiguredInterpreterException

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;
}
Also used : InterpreterType(org.python.pydev.ast.interpreter_managers.IInterpreterProviderFactory.InterpreterType) AutoConfigMaker(org.python.pydev.ui.pythonpathconf.AutoConfigMaker) AbstractInterpreterManager(org.python.pydev.ast.interpreter_managers.AbstractInterpreterManager) NotConfiguredInterpreterException(org.python.pydev.core.NotConfiguredInterpreterException)

Aggregations

NotConfiguredInterpreterException (org.python.pydev.core.NotConfiguredInterpreterException)5 IPythonNature (org.python.pydev.core.IPythonNature)3 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)2 File (java.io.File)1 Properties (java.util.Properties)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 AbstractInterpreterManager (org.python.pydev.ast.interpreter_managers.AbstractInterpreterManager)1 InterpreterType (org.python.pydev.ast.interpreter_managers.IInterpreterProviderFactory.InterpreterType)1 IPythonPathNature (org.python.pydev.core.IPythonPathNature)1 MisconfigurationException (org.python.pydev.core.MisconfigurationException)1 PythonNature (org.python.pydev.plugin.nature.PythonNature)1 FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)1 AutoConfigMaker (org.python.pydev.ui.pythonpathconf.AutoConfigMaker)1