コード例 #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(Path.Combine(_factory.Configuration.PrefixPath, "DLLs"));
                stdLibPaths.Add(Path.GetDirectoryName(_factory.Configuration.InterpreterPath));

                var results = await Task.Run(() => {
                    var 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);
        }
コード例 #2
0
ファイル: DatabaseTest.cs プロジェクト: xNUTs/PTVS
        public async Task GetExpectedDatabaseModules() {
            Python.AssertInstalled();

            var db = PythonTypeDatabase.GetDatabaseExpectedModules(
                Python.Version.ToVersion(),
                await PythonTypeDatabase.GetUncachedDatabaseSearchPathsAsync(Python.InterpreterPath)
            ).ToList();

            var stdlib = db[0];
            AssertUtil.ContainsAtLeast(stdlib.Select(mp => mp.FullName),
                "os", "ctypes.__init__", "encodings.utf_8", "ntpath"
            );

        }