Exemple #1
0
        public async Task <List <string> > EnumerateAllModules(bool refresh = false)
        {
            AbortOnInvalidConfiguration();

            if (_modules == null || refresh)
            {
                var stdLibPaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                stdLibPaths.Add(_factory.Configuration.LibraryPath);
                stdLibPaths.Add(Path.Combine(_factory.Configuration.PrefixPath, "DLLs"));
                stdLibPaths.Add(Path.GetDirectoryName(_factory.Configuration.InterpreterPath));

                var results = await Task.Run(() => {
                    List <PythonLibraryPath> paths;
                    if (_factory.AssumeSimpleLibraryLayout)
                    {
                        paths = PythonTypeDatabase.GetDefaultDatabaseSearchPaths(_factory.Configuration.LibraryPath);
                    }
                    else
                    {
                        paths = PythonTypeDatabase.GetCachedDatabaseSearchPaths(_factory.DatabasePath);
                        if (paths == null)
                        {
                            paths = PythonTypeDatabase.GetUncachedDatabaseSearchPathsAsync(
                                _factory.Configuration.InterpreterPath
                                ).WaitAndUnwrapExceptions();
                            try {
                                PythonTypeDatabase.WriteDatabaseSearchPaths(_factory.DatabasePath, paths);
                            } catch (Exception ex) {
                                if (ex.IsCriticalException())
                                {
                                    throw;
                                }
                            }
                        }
                    }

                    var groups = PythonTypeDatabase.GetDatabaseExpectedModules(
                        _factory.Configuration.Version,
                        paths
                        ).ToList();

                    var stdLibModules = groups[0].Select(mp => mp.ModuleName).ToList();
                    var modules       = groups.SelectMany().Select(mp => mp.ModuleName).ToList();
                    stdLibModules.Sort();
                    modules.Sort();
                    for (int i = stdLibModules.Count - 1; i > 0; --i)
                    {
                        if (stdLibModules[i - 1] == stdLibModules[i])
                        {
                            stdLibModules.RemoveAt(i);
                        }
                    }
                    for (int i = modules.Count - 1; i > 0; --i)
                    {
                        if (modules[i - 1] == modules[i])
                        {
                            modules.RemoveAt(i);
                        }
                    }

                    return(Tuple.Create(modules, stdLibModules));
                });

                _modules       = results.Item1;
                _stdLibModules = results.Item2;
            }
            return(_modules);
        }