Search in sources :

Example 31 with InterpreterInfo

use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.

the class JythonCodeCompletionTestsBase method setInterpreterManager.

@Override
protected void setInterpreterManager(String path) {
    AbstractInterpreterManager interpreterManager = new JythonInterpreterManager(this.getPreferences());
    InterpreterInfo info;
    info = (InterpreterInfo) interpreterManager.createInterpreterInfo(TestDependent.JYTHON_JAR_LOCATION, new NullProgressMonitor(), false);
    if (!info.executableOrJar.equals(TestDependent.JYTHON_JAR_LOCATION)) {
        throw new RuntimeException("expected same");
    }
    if (path != null) {
        info = new InterpreterInfo(info.getVersion(), TestDependent.JYTHON_JAR_LOCATION, PythonPathHelper.parsePythonPathFromStr(path, new ArrayList<String>()));
    }
    interpreterManager.setInfos(new IInterpreterInfo[] { info }, null, null);
    InterpreterManagersAPI.setJythonInterpreterManager(interpreterManager);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AbstractInterpreterManager(org.python.pydev.ast.interpreter_managers.AbstractInterpreterManager) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) JythonInterpreterManager(org.python.pydev.ast.interpreter_managers.JythonInterpreterManager)

Example 32 with InterpreterInfo

use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.

the class InterpreterInfoBuilderTest method testInterpreterInfoBuilder.

public void testInterpreterInfoBuilder() throws Exception {
    Collection<String> pythonpath = new ArrayList<String>();
    pythonpath.add(libDir.toString());
    final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
    IEclipsePreferences preferences = new InMemoryEclipsePreferences();
    final PythonInterpreterManager manager = new PythonInterpreterManager(preferences);
    InterpreterManagersAPI.setPythonInterpreterManager(manager);
    manager.setInfos(new IInterpreterInfo[] { info }, null, null);
    final AdditionalSystemInterpreterInfo additionalInfo = new AdditionalSystemInterpreterInfo(manager, info.getExecutableOrJar());
    AdditionalSystemInterpreterInfo.setAdditionalSystemInfo(manager, info.getExecutableOrJar(), additionalInfo);
    // Don't load it (otherwise it'll get the 'proper' info).
    // AdditionalSystemInterpreterInfo.loadAdditionalSystemInfo(manager, info.getExecutableOrJar());
    final ISystemModulesManager modulesManager = info.getModulesManager();
    assertEquals(0, modulesManager.getSize(false));
    assertEquals(0, additionalInfo.getAllTokens().size());
    InterpreterInfoBuilder builder = new InterpreterInfoBuilder();
    builder.syncInfoToPythonPath(null, info);
    int size = modulesManager.getSize(false);
    if (size != 3) {
        fail("Expected size = 3, found: " + size);
    }
    try {
        AbstractAdditionalDependencyInfo additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(manager, manager.getInterpreterInfos()[0].getExecutableOrJar(), true);
        if (additionalInfo != additionalSystemInfo) {
            throw new RuntimeException("Expecting it to be the same instance.");
        }
    } catch (MisconfigurationException e) {
        throw new RuntimeException(e);
    }
    Collection<IInfo> allTokens = additionalInfo.getAllTokens();
    size = allTokens.size();
    if (size != 3) {
        FastStringBuffer buf = new FastStringBuffer();
        for (IInfo i : allTokens) {
            buf.append(i.toString());
        }
        fail("Expected size = 3, found: " + size + "\nTokens: " + buf);
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) MisconfigurationException(org.python.pydev.core.MisconfigurationException) PythonInterpreterManager(org.python.pydev.ast.interpreter_managers.PythonInterpreterManager) ArrayList(java.util.ArrayList) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) ISystemModulesManager(org.python.pydev.core.ISystemModulesManager) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) InMemoryEclipsePreferences(org.python.pydev.shared_core.preferences.InMemoryEclipsePreferences)

Example 33 with InterpreterInfo

use of org.python.pydev.ast.interpreter_managers.InterpreterInfo 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)

Example 34 with InterpreterInfo

use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.

the class ObtainInterpreterInfoOperation method run.

/**
 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
 */
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    monitor = new OperationMonitor(monitor, logger);
    monitor.beginTask("Getting libs", 100);
    try {
        InterpreterInfo interpreterInfo = (InterpreterInfo) interpreterManager.createInterpreterInfo(file, monitor, !autoSelect);
        if (interpreterInfo != null) {
            result = interpreterInfo;
        }
    } catch (Exception e) {
        logger.println("Exception detected: " + e.getMessage());
        this.e = e;
    }
    monitor.done();
}
Also used : InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)34 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)27 IInterpreterManager (org.python.pydev.core.IInterpreterManager)13 ArrayList (java.util.ArrayList)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)7 HashMap (java.util.HashMap)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 File (java.io.File)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)4 PythonInterpreterManager (org.python.pydev.ast.interpreter_managers.PythonInterpreterManager)4 MisconfigurationException (org.python.pydev.core.MisconfigurationException)4 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)4 TreeNode (org.python.pydev.shared_core.structure.TreeNode)4 Tuple (org.python.pydev.shared_core.structure.Tuple)4 Map (java.util.Map)3 SyncSystemModulesManager (org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager)3 IInfo (org.python.pydev.core.IInfo)3