Search in sources :

Example 11 with IInterpreterManager

use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.

the class PySelectInterpreter method run.

@Override
public void run(IAction action) {
    try {
        PyEdit editor = getPyEdit();
        IPythonNature nature = editor.getPythonNature();
        if (nature != null) {
            IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager();
            final IInterpreterInfo[] interpreterInfos = interpreterManager.getInterpreterInfos();
            if (interpreterInfos == null || interpreterInfos.length == 0) {
                PyDialogHelpers.openWarning("No interpreters available", "Unable to change default interpreter because no interpreters are available (add more interpreters in the related preferences page).");
                return;
            }
            if (interpreterInfos.length == 1) {
                PyDialogHelpers.openWarning("Only 1 interpreters available", "Unable to change default interpreter because only 1 interpreter is configured (add more interpreters in the related preferences page).");
                return;
            }
            // Ok, more than 1 found.
            IWorkbenchWindow workbenchWindow = EditorUtils.getActiveWorkbenchWindow();
            Assert.isNotNull(workbenchWindow);
            SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(workbenchWindow, interpreterInfos, "Select interpreter to be made the default.", false);
            int open = listDialog.open();
            if (open != ListDialog.OK || listDialog.getResult().length != 1) {
                return;
            }
            Object[] result = listDialog.getResult();
            if (result == null || result.length == 0) {
                return;
            }
            final IInterpreterInfo selectedInterpreter = ((IInterpreterInfo) result[0]);
            if (selectedInterpreter != interpreterInfos[0]) {
                // Ok, some interpreter (which wasn't already the default) was selected.
                Arrays.sort(interpreterInfos, (a, b) -> {
                    if (a == selectedInterpreter) {
                        return -1;
                    }
                    if (b == selectedInterpreter) {
                        return 1;
                    }
                    // Don't change order for the others.
                    return 0;
                });
                Shell shell = EditorUtils.getShell();
                setInterpreterInfosWithProgressDialog(interpreterManager, interpreterInfos, shell);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) IPythonNature(org.python.pydev.core.IPythonNature) IInterpreterManager(org.python.pydev.core.IInterpreterManager) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) PyEdit(org.python.pydev.editor.PyEdit) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with IInterpreterManager

use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.

the class AbstractInterpreterPreferencesPage method performOk.

/**
 * Applies changes (if any)
 *
 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
 */
@Override
public boolean performOk() {
    // IMPORTANT: we must call the perform before restoring the modules because this
    // info is going to be used when restoring them.
    super.performOk();
    // we need to update the tree so that the environment variables stay correct.
    pathEditor.updateTree();
    IInterpreterManager interpreterManager = getInterpreterManager();
    String newStringToPersist = AbstractInterpreterManager.getStringToPersist(pathEditor.getExesList());
    String oldStringToPersist = AbstractInterpreterManager.getStringToPersist(interpreterManager.getInterpreterInfos());
    boolean changed;
    if (!newStringToPersist.equals(oldStringToPersist)) {
        changed = true;
    } else {
        changed = false;
    }
    if (changed || inApply) {
        // If the user just presses 'apply' and nothing changed, he'll be asked to restore information on one of
        // the current interpreters.
        restoreInterpreterInfos(changed);
    }
    if (!inApply) {
        // re-enable "configure interpreter" dialogs, but only upon exiting the wizard
        PyDialogHelpers.enableAskInterpreterStep(true);
    }
    return true;
}
Also used : IInterpreterManager(org.python.pydev.core.IInterpreterManager)

Example 13 with IInterpreterManager

use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.

the class SyncSystemModulesManager method synchronizeManagerToNameToInfoPythonpath.

public void synchronizeManagerToNameToInfoPythonpath(IProgressMonitor monitor, ManagerInfoToUpdate localManagerToNameToInfo, IInterpreterInfoBuilder builder) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    if (builder == null) {
        builder = (IInterpreterInfoBuilder) ExtensionHelper.getParticipant(ExtensionHelper.PYDEV_INTERPRETER_INFO_BUILDER, false);
        if (builder == null) {
            Log.log("Expecting at least one " + ExtensionHelper.PYDEV_INTERPRETER_INFO_BUILDER + ".");
            return;
        }
    }
    // Ok, all is Ok in the PYTHONPATH, so, check if something changed inside the interpreter info
    // and not on the PYTHONPATH.
    Tuple<IInterpreterManager, IInterpreterInfo>[] managerAndInfos = localManagerToNameToInfo.getManagerAndInfos();
    for (Tuple<IInterpreterManager, IInterpreterInfo> tuple : managerAndInfos) {
        // If it was changed or not, we must check the internal structure too!
        InterpreterInfo info = (InterpreterInfo) tuple.o2;
        if (info == null) {
            Log.log("Info null when synchronizing info.");
            continue;
        }
        if (DEBUG) {
            System.out.println("Synchronizing PYTHONPATH info: " + info.getNameForUI());
        }
        long initial = System.currentTimeMillis();
        builder.syncInfoToPythonPath(monitor, info);
        if (DEBUG) {
            System.out.println("End Synchronizing PYTHONPATH info (" + (System.currentTimeMillis() - initial) / 1000.0 + " secs.)");
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DefaultPathsForInterpreterInfo(org.python.pydev.ast.interpreter_managers.DefaultPathsForInterpreterInfo) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) IInterpreterManager(org.python.pydev.core.IInterpreterManager) Tuple(org.python.pydev.shared_core.structure.Tuple)

Example 14 with IInterpreterManager

use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.

the class SyncSystemModulesManager method applySelectedChangesToInterpreterInfosPythonpath.

public void applySelectedChangesToInterpreterInfosPythonpath(final DataAndImageTreeNode root, List<TreeNode> selectElements, IProgressMonitor monitor) {
    List<IInterpreterInfo> changedInfos = computeChanges(root, selectElements);
    if (changedInfos.size() > 0) {
        IInterpreterManager[] allInterpreterManagers = InterpreterManagersAPI.getAllInterpreterManagers();
        for (IInterpreterManager manager : allInterpreterManagers) {
            if (manager == null) {
                continue;
            }
            Map<String, IInterpreterInfo> changedInterpreterNameToInterpreter = new HashMap<>();
            for (IInterpreterInfo info : changedInfos) {
                changedInterpreterNameToInterpreter.put(info.getName(), info);
            }
            IInterpreterInfo[] allInfos = manager.getInterpreterInfos();
            List<Object> newInfos = new ArrayList<>(allInfos.length);
            Set<String> changedNames = new HashSet<>();
            // Important: keep the order in which the user configured the interpreters.
            for (IInterpreterInfo info : allInfos) {
                IInterpreterInfo changedInfo = changedInterpreterNameToInterpreter.remove(info.getName());
                if (changedInfo != null) {
                    // Override with the ones that should be changed.
                    newInfos.add(changedInfo);
                    changedNames.add(changedInfo.getExecutableOrJar());
                } else {
                    newInfos.add(info);
                }
            }
            if (changedNames.size() > 0) {
                if (DEBUG) {
                    System.out.println("Updating interpreters: " + changedNames);
                }
                manager.setInfos(newInfos.toArray(new IInterpreterInfo[newInfos.size()]), changedNames, monitor);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IInterpreterManager(org.python.pydev.core.IInterpreterManager) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashSet(java.util.HashSet)

Example 15 with IInterpreterManager

use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.

the class SyncSystemModulesManagerScheduler method stop.

/**
 * Stops the synchronization.
 */
public void stop() {
    job.cancel();
    IInterpreterManager[] managers = InterpreterManagersAPI.getAllInterpreterManagers();
    synchronized (lockSetInfos) {
        for (IInterpreterManager iInterpreterManager : managers) {
            if (iInterpreterManager != null) {
                stopTrack(iInterpreterManager, pathWatch);
            }
        }
    }
    pathWatch.dispose();
}
Also used : IInterpreterManager(org.python.pydev.core.IInterpreterManager)

Aggregations

IInterpreterManager (org.python.pydev.core.IInterpreterManager)61 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)30 MisconfigurationException (org.python.pydev.core.MisconfigurationException)14 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)13 CoreException (org.eclipse.core.runtime.CoreException)12 File (java.io.File)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 IPythonNature (org.python.pydev.core.IPythonNature)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)8 IProject (org.eclipse.core.resources.IProject)7 SystemPythonNature (org.python.pydev.plugin.nature.SystemPythonNature)7 Map (java.util.Map)6 Tuple (org.python.pydev.shared_core.structure.Tuple)6 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)5 Collection (java.util.Collection)5 HashSet (java.util.HashSet)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 PyEdit (org.python.pydev.editor.PyEdit)4 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)4