示例#1
0
        internal async Task LoadBuiltinTypesAsync(CancellationToken cancellationToken = default)
        {
            await BuiltinsModule.LoadAndAnalyzeAsync(cancellationToken);

            Check.InvalidOperation(!(BuiltinsModule.Analysis is EmptyAnalysis), "After await");

            // Add built-in module names
            var builtinModuleNamesMember = BuiltinsModule.GetAnyMember("__builtin_module_names__");

            if (builtinModuleNamesMember.TryGetConstant <string>(out var s))
            {
                var builtinModuleNames = s.Split(',').Select(n => n.Trim());
                PathResolver.SetBuiltins(builtinModuleNames);
            }
        }
        internal async Task LoadBuiltinTypesAsync(CancellationToken cancellationToken = default)
        {
            var analyzer = _services.GetService <IPythonAnalyzer>();
            await analyzer.GetAnalysisAsync(BuiltinsModule, -1, cancellationToken);

            Check.InvalidOperation(!(BuiltinsModule.Analysis is EmptyAnalysis), "After await");

            // Add built-in module names
            var builtinModuleNamesMember = BuiltinsModule.GetAnyMember("__builtin_module_names__");
            var value = (builtinModuleNamesMember as IVariable)?.Value ?? builtinModuleNamesMember;

            if (value.TryGetConstant <string>(out var s))
            {
                var builtinModuleNames = s.Split(',').Select(n => n.Trim());
                PathResolver.SetBuiltins(builtinModuleNames);
            }
        }
        internal async Task LoadBuiltinTypesAsync(CancellationToken cancellationToken = default)
        {
            // Add names from search paths
            await ReloadAsync(cancellationToken);

            // Initialize built-in
            var moduleName = BuiltinTypeId.Unknown.GetModuleName(_interpreter.LanguageVersion);
            var modulePath = ModuleCache.GetCacheFilePath(_interpreter.Configuration.InterpreterPath ?? "python.exe");

            var b = new BuiltinsPythonModule(moduleName, modulePath, _services);

            _modules[BuiltinModuleName] = BuiltinsModule = b;
            await b.LoadAndAnalyzeAsync(cancellationToken);

            // Add built-in module names
            var builtinModuleNamesMember = BuiltinsModule.GetAnyMember("__builtin_module_names__");

            if (builtinModuleNamesMember.TryGetConstant <string>(out var s))
            {
                var builtinModuleNames = s.Split(',').Select(n => n.Trim());
                _pathResolver.SetBuiltins(builtinModuleNames);
            }
        }