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);
}
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);
}
}
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);
}
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();
}
Aggregations