Search in sources :

Example 56 with IInterpreterManager

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

the class SyncSystemModulesManagerTest method checkSynchronize.

private void checkSynchronize(SyncSystemModulesManager synchManager, final DataAndImageTreeNode root, ManagerInfoToUpdate managerToNameToInfo) {
    // Ok, all is Ok in the PYTHONPATH, so, check if something changed inside the interpreter info
    // and not on the PYTHONPATH.
    assertFalse(root.hasChildren());
    InterpreterInfoBuilder builder = new InterpreterInfoBuilder();
    synchManager.synchronizeManagerToNameToInfoPythonpath(null, managerToNameToInfo, builder);
    Tuple<IInterpreterManager, IInterpreterInfo>[] managerAndInfos = managerToNameToInfo.getManagerAndInfos();
    for (Tuple<IInterpreterManager, IInterpreterInfo> tuple : managerAndInfos) {
        InterpreterInfo interpreterInfo = (InterpreterInfo) tuple.o2;
        assertEquals(3, interpreterInfo.getModulesManager().getSize(false));
    }
}
Also used : IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) IInterpreterManager(org.python.pydev.core.IInterpreterManager) Tuple(org.python.pydev.shared_core.structure.Tuple)

Example 57 with IInterpreterManager

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

the class SyncSystemModulesManagerTest method testUpdateWhenEggIsAdded.

public void testUpdateWhenEggIsAdded() throws Exception {
    setupEnv(true);
    SyncSystemModulesManager synchManager = new SyncSystemModulesManager();
    final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
    Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfoMap = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
    ManagerInfoToUpdate managerToNameToInfo = new ManagerInfoToUpdate(managerToNameToInfoMap);
    checkUpdateStructures(synchManager, root, managerToNameToInfo);
    checkSynchronize(synchManager, root, managerToNameToInfo);
    root.clear();
    managerToNameToInfo = new ManagerInfoToUpdate(InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo());
    synchManager.updateStructures(null, root, managerToNameToInfo, new SyncSystemModulesManager.CreateInterpreterInfoCallback() {

        @Override
        public IInterpreterInfo createInterpreterInfo(IInterpreterManager manager, String executable, IProgressMonitor monitor) {
            Collection<String> pythonpath = new ArrayList<String>();
            pythonpath.add(libDir.toString());
            pythonpath.add(libZipFile.toString());
            final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
            return info;
        }
    });
    assertTrue(root.hasChildren());
    List<TreeNode> selectElements = new ArrayList<>();
    selectElements.addAll(root.flattenChildren());
    synchManager.applySelectedChangesToInterpreterInfosPythonpath(root, selectElements, null);
    List<IInterpreterInfo> allInterpreterInfos = InterpreterManagersAPI.getAllInterpreterInfos();
    for (IInterpreterInfo interpreterInfo : allInterpreterInfos) {
        assertEquals(4, interpreterInfo.getModulesManager().getSize(false));
        AdditionalSystemInterpreterInfo additionalInfo = (AdditionalSystemInterpreterInfo) AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterInfo.getModulesManager().getInterpreterManager(), interpreterInfo.getExecutableOrJar());
        Collection<IInfo> allTokens = additionalInfo.getAllTokens();
        assertEquals(4, additionalInfo.getAllTokens().size());
    }
}
Also used : ArrayList(java.util.ArrayList) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) SyncSystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) Collection(java.util.Collection) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashMap(java.util.HashMap) Map(java.util.Map) ManagerInfoToUpdate(org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate)

Example 58 with IInterpreterManager

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

the class AbstractWorkbenchTestCase method createPythonInterpreterManager.

/**
 * Creates the python interpreter manager with the default jython jar location.
 */
protected static void createPythonInterpreterManager(NullProgressMonitor monitor) {
    IInterpreterManager iMan = InterpreterManagersAPI.getPythonInterpreterManager(true);
    IInterpreterInfo interpreterInfo = iMan.createInterpreterInfo(TestDependent.PYTHON2_EXE, monitor, false);
    iMan.setInfos(new IInterpreterInfo[] { interpreterInfo }, null, null);
}
Also used : IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) IInterpreterManager(org.python.pydev.core.IInterpreterManager)

Example 59 with IInterpreterManager

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

the class AbstractWorkbenchTestCase method createJythonInterpreterManager.

/**
 * Creates the jython interpreter manager with the default jython jar location.
 */
protected static void createJythonInterpreterManager(NullProgressMonitor monitor) {
    IInterpreterManager iMan = InterpreterManagersAPI.getJythonInterpreterManager(true);
    IInterpreterInfo interpreterInfo = iMan.createInterpreterInfo(TestDependent.JYTHON_JAR_LOCATION, monitor, false);
    iMan.setInfos(new IInterpreterInfo[] { interpreterInfo }, null, null);
}
Also used : IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) IInterpreterManager(org.python.pydev.core.IInterpreterManager)

Example 60 with IInterpreterManager

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

the class AdditionalInterpreterInfoTest method testForcedBuiltinsInAdditionalInfo.

// Not working with lucene searches (test must be fixed).
// 
// public void testCompleteIndex() throws Exception {
// String doc = "class Test:\n" +
// "    class Test2:\n" +
// "        def mmm(self):\n" +
// "            a = mmm1\n"
// +
// "            print mmm1";
// File tempFileAt = FileUtils.getTempFileAt(baseDir, "data_temporary_file_on_additional_interpreter_info_test",
// ".py");
// FileUtils.writeStrToFile(doc, tempFileAt);
// try {
// SourceModule module = AbstractModule.createModuleFromDoc("test", tempFileAt, new Document(
// doc), nature, true);
// info.addAstInfo(module.getAst(), new ModulesKey("test", tempFileAt), false);
// 
// List<ModulesKey> modulesWithTokensStartingWith = null;
// 
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm", null);
// assertEquals(1, modulesWithTokensStartingWith.size());
// 
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm1", null);
// assertEquals(1, modulesWithTokensStartingWith.size());
// 
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm4", null);
// assertEquals(0, modulesWithTokensStartingWith.size());
// 
// synchronized (this) {
// wait(1000);
// }
// 
// doc = "new contents";
// FileUtils.writeStrToFile(doc, tempFileAt);
// 
// info.removeInfoFromModule("test", true);
// info.addAstInfo(new ModulesKey("test", tempFileAt), true);
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm", null);
// assertEquals(0, modulesWithTokensStartingWith.size());
// 
// modulesWithTokensStartingWith = info.getModulesWithToken("contents", null);
// assertEquals(1, modulesWithTokensStartingWith.size());
// } finally {
// tempFileAt.delete();
// }
// }
@SuppressWarnings("unchecked")
public void testForcedBuiltinsInAdditionalInfo() throws Exception {
    IInterpreterManager interpreterManager = getInterpreterManager();
    String defaultInterpreter = interpreterManager.getDefaultInterpreterInfo(false).getExecutableOrJar();
    AbstractAdditionalDependencyInfo additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterManager, defaultInterpreter);
    checkItertoolsToken(additionalSystemInfo, false);
    InterpreterInfo defaultInterpreterInfo = (InterpreterInfo) interpreterManager.getDefaultInterpreterInfo(false);
    HashSet<String> set = new HashSet<>(Arrays.asList(defaultInterpreterInfo.getBuiltins()));
    assertTrue(set.contains("itertools"));
    // Now, update the information to contain the builtin tokens!
    new InterpreterInfoBuilder().syncInfoToPythonPath(new NullProgressMonitor(), defaultInterpreterInfo);
    checkItertoolsToken(additionalSystemInfo, true);
    // Remove and re-update to check if it's fixed.
    additionalSystemInfo.removeInfoFromModule("itertools", false);
    checkItertoolsToken(additionalSystemInfo, false);
    new InterpreterInfoBuilder().syncInfoToPythonPath(new NullProgressMonitor(), defaultInterpreterInfo);
    checkItertoolsToken(additionalSystemInfo, true);
    int indexSize = additionalSystemInfo.completeIndex.keys().size();
    AdditionalSystemInterpreterInfo newAdditionalInfo = new AdditionalSystemInterpreterInfo(interpreterManager, defaultInterpreter);
    AdditionalSystemInterpreterInfo.setAdditionalSystemInfo(interpreterManager, defaultInterpreter, newAdditionalInfo);
    newAdditionalInfo.load();
    assertEquals(indexSize, newAdditionalInfo.completeIndex.keys().size());
    final List<ModulesKey> added = new ArrayList<>();
    final List<ModulesKey> removed = new ArrayList<>();
    ICallbackListener listener = new ICallbackListener() {

        @Override
        public Object call(Object obj) {
            Tuple t = (Tuple) obj;
            added.addAll((List<ModulesKey>) t.o1);
            removed.addAll((List<ModulesKey>) t.o2);
            return null;
        }
    };
    AbstractAdditionalDependencyInfo.modulesAddedAndRemoved.registerListener(listener);
    try {
        new InterpreterInfoBuilder().syncInfoToPythonPath(new NullProgressMonitor(), defaultInterpreterInfo, newAdditionalInfo);
    } finally {
        AbstractAdditionalDependencyInfo.modulesAddedAndRemoved.unregisterListener(listener);
    }
    if (added.size() > 0) {
        throw new AssertionError("Expected no modules to be added as we just loaded from a clean save. Found:\n" + StringUtils.join("\n", added));
    }
    if (removed.size() > 0) {
        throw new AssertionError("Expected no modules to be removed as we just loaded from a clean save. Found:\n" + StringUtils.join("\n", removed));
    }
    checkItertoolsToken(newAdditionalInfo, true);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArrayList(java.util.ArrayList) IInterpreterManager(org.python.pydev.core.IInterpreterManager) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) ModulesKey(org.python.pydev.core.ModulesKey) ICallbackListener(org.python.pydev.shared_core.callbacks.ICallbackListener) Tuple(org.python.pydev.shared_core.structure.Tuple) HashSet(java.util.HashSet) InterpreterInfoBuilder(com.python.pydev.analysis.system_info_builder.InterpreterInfoBuilder)

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