use of org.python.pydev.ast.codecompletion.revisited.SystemModulesManager in project Pydev by fabioz.
the class InterpreterInfoBuilder method syncInfoToPythonPath.
public BuilderResult syncInfoToPythonPath(IProgressMonitor monitor, PythonPathHelper pythonPathHelper, AbstractAdditionalDependencyInfo additionalInfo, IModulesManager modulesManager, InterpreterInfo info) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
if (DebugSettings.DEBUG_INTERPRETER_AUTO_UPDATE) {
org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, "--- Start run");
}
BuilderResult ret = checkEarlyReturn(monitor, info);
if (ret != BuilderResult.OK) {
return ret;
}
ModulesFoundStructure modulesFound = pythonPathHelper.getModulesFoundStructure(null, monitor);
ret = checkEarlyReturn(monitor, info);
if (ret != BuilderResult.OK) {
return ret;
}
PyPublicTreeMap<ModulesKey, ModulesKey> keysFound = ModulesManager.buildKeysFromModulesFound(monitor, modulesFound);
if (DebugSettings.DEBUG_INTERPRETER_AUTO_UPDATE) {
org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, StringUtils.format("Found: %s modules", keysFound.size()));
}
ret = checkEarlyReturn(monitor, info);
if (ret != BuilderResult.OK) {
return ret;
}
try {
if (info != null) {
String[] builtins = info.getBuiltins();
// as we have to get the completions for all builtin modules from the shell.
if (builtins != null) {
for (int i = 0; i < builtins.length; i++) {
String name = builtins[i];
final ModulesKey k = new ModulesKey(name, null);
// Note that it'll override source modules!
keysFound.put(k, k);
}
}
}
synchronized (additionalInfo.updateKeysLock) {
// Use a lock (if we have more than one builder updating we could get into a racing condition here).
// Important: do the diff only after the builtins are added (otherwise the modules manager may become wrong)!
Tuple<List<ModulesKey>, List<ModulesKey>> diffModules = modulesManager.diffModules(keysFound);
if (diffModules.o1.size() > 0 || diffModules.o2.size() > 0) {
if (DebugSettings.DEBUG_INTERPRETER_AUTO_UPDATE) {
org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, StringUtils.format("Diff modules. Added: %s Removed: %s", diffModules.o1, diffModules.o2));
}
// Update the modules manager itself (just pass all the keys as that should be fast)
if (modulesManager instanceof SystemModulesManager) {
((SystemModulesManager) modulesManager).updateKeysAndSave(keysFound);
} else {
for (ModulesKey newEntry : diffModules.o1) {
modulesManager.addModule(newEntry);
}
modulesManager.removeModules(diffModules.o2);
}
}
additionalInfo.updateKeysIfNeededAndSave(keysFound, info, monitor);
}
} catch (Exception e) {
Log.log(e);
}
if (DebugSettings.DEBUG_INTERPRETER_AUTO_UPDATE) {
org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, "--- End Run");
}
return BuilderResult.OK;
}
use of org.python.pydev.ast.codecompletion.revisited.SystemModulesManager in project Pydev by fabioz.
the class ForcedLibGroup method calculateChildren.
@Override
protected void calculateChildren() throws MisconfigurationException {
SystemModulesManager m = (SystemModulesManager) this.interpreterInfo.getModulesManager();
AbstractModule builtinModule = m.getBuiltinModule(forcedLib, true, new BaseModuleRequest(true));
TokensList globalTokens = builtinModule.getGlobalTokens();
ArrayList<LeafElement> lst = new ArrayList<LeafElement>();
for (IterTokenEntry entry : globalTokens) {
IToken iToken = entry.getToken();
lst.add(new LeafElement(this, iToken.getRepresentation()));
}
Collections.sort(lst, new Comparator<LeafElement>() {
@Override
public int compare(LeafElement o1, LeafElement o2) {
return o1.toString().compareTo(o2.toString());
}
});
for (LeafElement leafElement : lst) {
addChild(leafElement);
}
}
use of org.python.pydev.ast.codecompletion.revisited.SystemModulesManager in project Pydev by fabioz.
the class AbstractIOTestCase method createModuleAdapterFromDataSource.
/**
* @param version IPythonNature.PYTHON_VERSION_XXX
*/
protected ModuleAdapter createModuleAdapterFromDataSource(String version) throws Throwable {
codeCompletionTestsBase.restorePythonPath(FileUtils.getFileAbsolutePath(data.file.getParentFile()), true);
PythonModuleManager pythonModuleManager = new PythonModuleManager(CodeCompletionTestsBase.nature);
if (version != null) {
// As the files will be found in the system, we need to set the system modules manager info.
IModulesManager modulesManager = pythonModuleManager.getIModuleManager();
SystemModulesManager systemModulesManager = (SystemModulesManager) modulesManager.getSystemModulesManager();
systemModulesManager.setInfo(new InterpreterInfo(version, "", new ArrayList<String>()));
CodeCompletionTestsBase.nature.setVersion(version, null);
}
ModuleAdapter module = VisitorFactory.createModuleAdapter(pythonModuleManager, data.file, new Document(data.source), CodeCompletionTestsBase.nature, CodeCompletionTestsBase.nature);
return module;
}
Aggregations