Search in sources :

Example 1 with SystemModulesManager

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ModulesFoundStructure(org.python.pydev.ast.codecompletion.revisited.ModulesFoundStructure) ModulesKey(org.python.pydev.core.ModulesKey) List(java.util.List) SystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SystemModulesManager) ISystemModulesManager(org.python.pydev.core.ISystemModulesManager) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Example 2 with SystemModulesManager

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);
    }
}
Also used : IToken(org.python.pydev.core.IToken) BaseModuleRequest(org.python.pydev.core.BaseModuleRequest) ArrayList(java.util.ArrayList) IterTokenEntry(org.python.pydev.core.IterTokenEntry) SystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SystemModulesManager) TokensList(org.python.pydev.core.TokensList) AbstractModule(org.python.pydev.ast.codecompletion.revisited.modules.AbstractModule)

Example 3 with SystemModulesManager

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;
}
Also used : ModuleAdapter(org.python.pydev.refactoring.ast.adapters.ModuleAdapter) ArrayList(java.util.ArrayList) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IModulesManager(org.python.pydev.core.IModulesManager) SystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SystemModulesManager) Document(org.eclipse.jface.text.Document) PythonModuleManager(org.python.pydev.refactoring.ast.PythonModuleManager)

Aggregations

SystemModulesManager (org.python.pydev.ast.codecompletion.revisited.SystemModulesManager)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Document (org.eclipse.jface.text.Document)1 ModulesFoundStructure (org.python.pydev.ast.codecompletion.revisited.ModulesFoundStructure)1 AbstractModule (org.python.pydev.ast.codecompletion.revisited.modules.AbstractModule)1 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)1 BaseModuleRequest (org.python.pydev.core.BaseModuleRequest)1 IModulesManager (org.python.pydev.core.IModulesManager)1 ISystemModulesManager (org.python.pydev.core.ISystemModulesManager)1 IToken (org.python.pydev.core.IToken)1 IterTokenEntry (org.python.pydev.core.IterTokenEntry)1 MisconfigurationException (org.python.pydev.core.MisconfigurationException)1 ModulesKey (org.python.pydev.core.ModulesKey)1 TokensList (org.python.pydev.core.TokensList)1 PythonModuleManager (org.python.pydev.refactoring.ast.PythonModuleManager)1 ModuleAdapter (org.python.pydev.refactoring.ast.adapters.ModuleAdapter)1