Beispiel #1
0
        internal AstPythonModule(string moduleName, IPythonInterpreter interpreter, PythonAst ast, string filePath, IEnumerable <string> parseErrors)
        {
            Name           = moduleName;
            _documentation = ast.Documentation;
            FilePath       = filePath;
            DocumentUri    = ProjectEntry.MakeDocumentUri(FilePath);
            Locations      = new[] { new LocationInfo(filePath, DocumentUri, 1, 1) };
            _interpreter   = interpreter;

            _properties   = new Dictionary <object, object>();
            _childModules = new List <string>();
            _members      = new Dictionary <string, IMember>();

            // Do not allow children of named modules
            if (!ModulePath.IsInitPyFile(FilePath))
            {
                _foundChildModules = true;
            }

            var walker = new AstAnalysisWalker(interpreter, ast, this, filePath, DocumentUri, _members, true, true);

            ast.Walk(walker);
            walker.Complete();

            ParseErrors = parseErrors?.ToArray();
        }
        protected override PythonWalker PrepareWalker(IPythonInterpreter interpreter, PythonAst ast)
        {
            var walker = new AstAnalysisWalker(interpreter, ast, this, null, _members, false, true);

            walker.CreateBuiltinTypes          = true;
            walker.Scope.SuppressBuiltinLookup = true;
            return(walker);
        }
Beispiel #3
0
        internal void Analyze(PythonAst ast, PathResolverSnapshot currentPathResolver)
        {
            var walker = new AstAnalysisWalker(_interpreter, currentPathResolver, ast, this, FilePath, DocumentUri, _members,
                                               includeLocationInfo: true,
                                               warnAboutUndefinedValues: true,
                                               suppressBuiltinLookup: false
                                               );

            ast.Walk(walker);
            walker.Complete();
        }
Beispiel #4
0
        internal AstPythonModule(IPythonInterpreter interpreter, PythonAst ast, string filePath) {
            Name = ast.Name;
            Documentation = ast.Documentation;
            FilePath = filePath;
            Locations = new[] { new LocationInfo(filePath, 1, 1) };

            _properties = new Dictionary<object, object>();
            _childModules = new List<string>();
            _members = new Dictionary<string, IMember>();

            var walker = new AstAnalysisWalker(interpreter, ast, this, filePath, _members);
            ast.Walk(walker);
        }
Beispiel #5
0
        internal AstPythonModule(IPythonInterpreter interpreter, PythonAst ast, string filePath)
        {
            Name          = ast.Name;
            Documentation = ast.Documentation;
            FilePath      = filePath;
            Locations     = new[] { new LocationInfo(filePath, 1, 1) };

            _properties   = new Dictionary <object, object>();
            _childModules = new List <string>();
            _members      = new Dictionary <string, IMember>();

            var walker = new AstAnalysisWalker(interpreter, ast, this, filePath, _members);

            ast.Walk(walker);
        }
Beispiel #6
0
        protected override PythonWalker PrepareWalker(IPythonInterpreter interpreter, PythonAst ast)
        {
#if DEBUG
            var        fact             = (interpreter as AstPythonInterpreter)?.Factory as AstPythonInterpreterFactory;
            var        filePath         = fact?.GetCacheFilePath(fact?.Configuration.InterpreterPath ?? "python.exe");
            const bool includeLocations = true;
#else
            string     filePath         = null;
            const bool includeLocations = false;
#endif

            var walker = new AstAnalysisWalker(interpreter, ast, this, filePath, null, _members, includeLocations, true);
            walker.CreateBuiltinTypes          = true;
            walker.Scope.SuppressBuiltinLookup = true;
            return(walker);
        }
Beispiel #7
0
        internal AstPythonModule(string moduleName, IPythonInterpreter interpreter, PythonAst ast, string filePath)
        {
            Name          = moduleName;
            Documentation = ast.Documentation;
            FilePath      = filePath;
            Locations     = new[] { new LocationInfo(filePath, 1, 1) };
            _interpreter  = interpreter;

            _properties   = new Dictionary <object, object>();
            _childModules = new List <string>();
            _members      = new Dictionary <string, IMember>();

            // Do not allow children of named modules
            if (!ModulePath.IsInitPyFile(FilePath))
            {
                _foundChildModules = true;
            }

            var walker = new AstAnalysisWalker(interpreter, ast, this, filePath, _members, true, true);

            ast.Walk(walker);
        }
        protected override PythonWalker PrepareWalker(AstPythonInterpreter interpreter, PythonAst ast)
        {
            string filePath = null;

#if DEBUG
            filePath = interpreter.ModuleCache.GetCacheFilePath(interpreter.InterpreterPath ?? "python.exe");
            const bool includeLocations = true;
#else
            const bool includeLocations = false;
#endif

            var walker = new AstAnalysisWalker(
                interpreter, interpreter.CurrentPathResolver, ast, this, filePath, null, _members,
                includeLocations,
                warnAboutUndefinedValues: true,
                suppressBuiltinLookup: true
                )
            {
                CreateBuiltinTypes = true
            };

            return(walker);
        }
Beispiel #9
0
        public void Imported(IModuleContext context)
        {
            if (_scraped)
            {
                return;
            }
            _scraped = true;

            var interp = context as AstPythonInterpreter;
            var fact   = interp?.Factory;

            if (fact == null || !File.Exists(fact.Configuration.InterpreterPath))
            {
                return;
            }

            ModulePath mp = AstPythonInterpreterFactory.FindModule(fact, _filePath);

            if (string.IsNullOrEmpty(mp.FullName))
            {
                return;
            }

            var sm = PythonToolsInstallPath.TryGetFile("scrape_module.py", GetType().Assembly);

            if (!File.Exists(sm))
            {
                return;
            }

            Stream code = null;

            using (var p = ProcessOutput.RunHiddenAndCapture(
                       fact.Configuration.InterpreterPath, "-E", sm, mp.LibraryPath, mp.ModuleName
                       )) {
                p.Wait();
                if (p.ExitCode == 0)
                {
                    var ms = new MemoryStream();
                    code = ms;
                    using (var sw = new StreamWriter(ms, Encoding.UTF8, 4096, true)) {
                        foreach (var line in p.StandardOutputLines)
                        {
                            sw.WriteLine(line);
                        }
                    }
                }
            }

            if (code == null)
            {
                return;
            }

            PythonAst ast;

            code.Seek(0, SeekOrigin.Begin);
            using (var sr = new StreamReader(code, Encoding.UTF8))
                using (var parser = Parser.CreateParser(sr, fact.GetLanguageVersion())) {
                    ast = parser.ParseFile();
                }

            lock (_members) {
                var walker = new AstAnalysisWalker(interp, ast, this, _filePath, _members, false);
                ast.Walk(walker);
            }
        }