public GeneratorInfo(PythonAnalyzer projectState, IPythonProjectEntry entry)
     : base(projectState.ClassInfos[BuiltinTypeId.Generator]) {
     
     _declaringModule = entry;
     _declaringVersion = entry.AnalysisVersion;
     Yields = new VariableDef();
     Sends = new VariableDef();
     Returns = new VariableDef();
 }
Beispiel #2
0
        public CoroutineInfo(PythonAnalyzer projectState, IPythonProjectEntry entry)
            : base(projectState.ClassInfos[BuiltinTypeId.Generator]) {
            // Internally, coroutines are represented by generators with a CO_*
            // flag on the code object. Here we represent it as a separate info,
            // but reuse the underlying class info.

            _declaringModule = entry;
            _declaringVersion = entry.AnalysisVersion;
            Returns = new VariableDef();
        }
        public DropDownBarClient(IWpfTextView textView, IPythonProjectEntry pythonProjectEntry) {
            Utilities.ArgumentNotNull("textView", textView);
            Utilities.ArgumentNotNull("pythonProjectEntry", pythonProjectEntry);

            _projectEntry = pythonProjectEntry;
            _projectEntry.OnNewParseTree += ParserOnNewParseTree;
            _textView = textView;
            _topLevelEntries = _nestedEntries = EmptyEntries;
            _dispatcher = Dispatcher.CurrentDispatcher;
            _textView.Caret.PositionChanged += CaretPositionChanged;
        }
Beispiel #4
0
        private ReadOnlyCollection<DropDownEntryInfo> _topLevelEntries; // entries for top-level members of the file

        #endregion Fields

        #region Constructors

        public DropDownBarClient(IWpfTextView textView, IPythonProjectEntry classifier)
        {
            Debug.Assert(textView != null);
            Debug.Assert(classifier != null);

            _classifier = classifier;
            _classifier.OnNewParseTree += ParserOnNewParseTree;
            _textView = textView;
            _topLevelEntries = _nestedEntries = EmptyEntries;
            _dispatcher = Dispatcher.CurrentDispatcher;
            _textView.Caret.PositionChanged += CaretPositionChanged;
        }
Beispiel #5
0
 public FunctionScope(
     FunctionInfo function,
     Node node,
     InterpreterScope declScope,
     IPythonProjectEntry declModule
 )
     : base(function, node, declScope) {
     ReturnValue = new VariableDef();
     if (Function.FunctionDefinition.IsCoroutine) {
         Coroutine = new CoroutineInfo(function.ProjectState, declModule);
         ReturnValue.AddTypes(function.ProjectEntry, Coroutine.SelfSet, false);
     } else if (Function.FunctionDefinition.IsGenerator) {
         Generator = new GeneratorInfo(function.ProjectState, declModule);
         ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
     }
 }
Beispiel #6
0
        internal FunctionAnalysisUnit(
            FunctionInfo function,
            AnalysisUnit declUnit,
            InterpreterScope declScope,
            IPythonProjectEntry declEntry
        )
            : base(function.FunctionDefinition, null) {
            _declUnit = declUnit;
            Function = function;
            _decoratorCalls = new Dictionary<Node, Expression>();

            var scope = new FunctionScope(Function, Function.FunctionDefinition, declScope, declEntry);
            scope.EnsureParameters(this);
            _scope = scope;

            AnalysisLog.NewUnit(this);
        }
Beispiel #7
0
        public T GetValue <T>(IPythonProjectEntry module, string variable, int index = 0) where T : AnalysisValue
        {
            var rs = module.Analysis.GetValuesByIndex(variable, index).ToArray();

            if (rs.Length == 0)
            {
                Assert.Fail("'{0}.{1}' had no variables".FormatInvariant(module.ModuleName, variable));
            }
            else if (rs.Length > 1)
            {
                foreach (var r in rs)
                {
                    Trace.TraceInformation(r.ToString());
                }
                Assert.Fail("'{0}.{1}' had multiple values: {2}".FormatInvariant(module.ModuleName, variable, AnalysisSet.Create(rs)));
            }
            else
            {
                Assert.IsInstanceOfType(rs[0], typeof(T), "'{0}.{1}' was not expected type".FormatInvariant(module.ModuleName, variable));
                return((T)rs[0]);
            }
            return(default(T));
        }
Beispiel #8
0
        internal FunctionAnalysisUnit(
            FunctionInfo function,
            AnalysisUnit declUnit,
            InterpreterScope declScope,
            IPythonProjectEntry declEntry,
            bool concreteParameters
            )
            : base(function.FunctionDefinition, null)
        {
            _declUnit           = declUnit;
            Function            = function;
            _concreteParameters = concreteParameters;
            _decoratorCalls     = new Dictionary <Node, Expression>();

            var scope = new FunctionScope(Function, Function.FunctionDefinition, declScope, declEntry);

            _scope = scope;

            if (GetType() == typeof(FunctionAnalysisUnit))
            {
                AnalysisLog.NewUnit(this);
            }
        }
        internal AggregateProjectEntry AggregateWith(IPythonProjectEntry with)
        {
            if (_aggregating.Contains(with))
            {
                // we're not adding any new types
                return(this);
            }

            if (_next == null)
            {
                _next = new Dictionary <IProjectEntry, AggregateProjectEntry>();
            }

            AggregateProjectEntry entry;

            if (!_next.TryGetValue(with, out entry))
            {
                // We don't yet have the next transition, create it now.
                _next[with] = entry = with.ProjectState.GetAggregate(_aggregating, with);
            }

            return(entry);
        }
Beispiel #10
0
        private SaveLoadResult SaveLoad(PythonLanguageVersion version, params AnalysisModule[] modules)
        {
            IPythonProjectEntry[] entries = new IPythonProjectEntry[modules.Length];

            var fact   = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
            var interp = fact.CreateInterpreter();

            var dbFolder = TestData.GetTempPath(randomSubPath: true);

            Directory.CreateDirectory(dbFolder);

            var state = new PythonAnalysis(fact, interp, SharedDatabaseState.BuiltinName2x);

            state.CreateProjectOnDisk = true;
            for (int i = 0; i < modules.Length; i++)
            {
                state.AddModule(modules[i].ModuleName, modules[i].Code, modules[i].Filename);
            }

            state.WaitForAnalysis();

            new SaveAnalysis().Save(state.Analyzer, dbFolder);

            File.Copy(
                Path.Combine(PythonTypeDatabase.BaselineDatabasePath, "__builtin__.idb"),
                Path.Combine(dbFolder, "__builtin__.idb"),
                true
                );

            var loadFactory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(
                version.ToVersion(),
                null,
                dbFolder
                );

            return(new SaveLoadResult(CreateAnalyzer(loadFactory), state.CodeFolder));
        }
        private static IEnumerable <MemberResult> GetModuleVariables(
            IPythonProjectEntry entry,
            GetMemberOptions opts,
            string prefix
            )
        {
            var analysis = entry?.Analysis;

            if (analysis == null)
            {
                yield break;
            }

            foreach (var m in analysis.GetAllAvailableMembers(SourceLocation.None, opts))
            {
                if (m.Values.Any(v => v.DeclaringModule == entry))
                {
                    if (string.IsNullOrEmpty(prefix) || m.Name.StartsWithOrdinal(prefix, ignoreCase: true))
                    {
                        yield return(m);
                    }
                }
            }
        }
Beispiel #12
0
 public void AssertAttrIsType(IPythonProjectEntry module, string variable, string memberName, params PythonMemberType[] types)
 {
     AssertAttrIsType(module, variable, memberName, 0, types);
 }
Beispiel #13
0
 public void AssertIsInstance(IPythonProjectEntry module, string expr, params BuiltinTypeId[] types)
 {
     AssertIsInstance(module, expr, 0, types);
 }
Beispiel #14
0
 public void AssertIsInstance(IPythonProjectEntry module, string expr)
 {
     AssertIsInstance(module, expr, 0);
 }
Beispiel #15
0
 public void AssertHasAttrExact(IPythonProjectEntry module, string expr, int index, params string[] attrs)
 {
     AssertUtil.ContainsExactly(GetMemberNames(module, expr, index), attrs);
 }
Beispiel #16
0
 public IOverloadResult[] GetOverrideable(IPythonProjectEntry module, int index = 0)
 {
     return(module.Analysis.GetOverrideableByIndex(index).ToArray());
 }
Beispiel #17
0
 public AnalysisValue[] GetValues(IPythonProjectEntry module, string variable, int index = 0)
 {
     return(module.Analysis.GetValuesByIndex(variable, index).ToArray());
 }
Beispiel #18
0
        public void AssertConstantEquals(IPythonProjectEntry module, string expr, int index, string value)
        {
            var val = GetValue <AnalysisValue>(module, expr, index);

            Assert.AreEqual(val?.GetConstantValueAsString(), value, "{0}.{1}".FormatInvariant(module.ModuleName, expr));
        }
Beispiel #19
0
        private SaveLoadResult SaveLoad(PythonLanguageVersion version, params AnalysisModule[] modules)
        {
            IPythonProjectEntry[] entries = new IPythonProjectEntry[modules.Length];

            var fact = InterpreterFactory;
            var interp = Interpreter;
            if (version != fact.GetLanguageVersion()) {
                fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
                interp = fact.CreateInterpreter();
            }

            var codeFolder = TestData.GetTempPath(randomSubPath: true);
            var dbFolder = Path.Combine(codeFolder, "DB");
            Directory.CreateDirectory(codeFolder);
            Directory.CreateDirectory(dbFolder);

            var state = PythonAnalyzer.CreateSynchronously(fact, interp, SharedDatabaseState.BuiltinName2x);
            for (int i = 0; i < modules.Length; i++) {
                var fullname = Path.Combine(codeFolder, modules[i].Filename);
                File.WriteAllText(fullname, modules[i].Code);
                entries[i] = state.AddModule(modules[i].ModuleName, fullname);
                Prepare(entries[i], new StringReader(modules[i].Code), version);
            }

            for (int i = 0; i < modules.Length; i++) {
                entries[i].Analyze(CancellationToken.None, false);
            }

            new SaveAnalysis().Save(state, dbFolder);

            File.Copy(
                Path.Combine(PythonTypeDatabase.BaselineDatabasePath, "__builtin__.idb"),
                Path.Combine(dbFolder, "__builtin__.idb"),
                true
            );

            var loadFactory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(
                version.ToVersion(),
                null,
                dbFolder
            );
            return new SaveLoadResult(PythonAnalyzer.CreateSynchronously(loadFactory), codeFolder);
        }
Beispiel #20
0
 internal static bool TryGetPythonAnalysis(this ITextBuffer buffer, out IPythonProjectEntry analysis)
 {
     IProjectEntry entry;
     if (buffer.TryGetAnalysis(out entry) && (analysis = entry as IPythonProjectEntry) != null) {
         return true;
     }
     analysis = null;
     return false;
 }
Beispiel #21
0
 public AstScopeNode(PythonAst pythonAst, IPythonProjectEntry projectEntry) {
     _ast = pythonAst;
     _projectEntry = projectEntry;
 }
Beispiel #22
0
 public static void Prepare(IPythonProjectEntry entry, TextReader sourceUnit, PythonLanguageVersion version = PythonLanguageVersion.V27) {
     using (var parser = Parser.CreateParser(sourceUnit, version, new ParserOptions() { BindReferences = true })) {
         entry.UpdateTree(parser.ParseFile(), null);
     }
 }
Beispiel #23
0
        /// <summary>
        /// Get Test Case Members for a class.  If the class has 'test*' tests 
        /// return those.  If there aren't any 'test*' tests return (if one at 
        /// all) the runTest overridden method
        /// </summary>
        private static IEnumerable<KeyValuePair<string, IAnalysisSet>> GetTestCaseMembers(
            IPythonProjectEntry entry,
            AnalysisValue classValue
            )
        {
            var methodFunctions = classValue.GetAllMembers(entry.Analysis.InterpreterContext)
                .Where(v => v.Value.Any(m => m.MemberType == PythonMemberType.Function || m.MemberType == PythonMemberType.Method));

            var tests = methodFunctions.Where(v => v.Key.StartsWith("test"));
            var runTest = methodFunctions.Where(v => v.Key.Equals("runTest"));

            if (tests.Any()) {
                return tests;
            } else {
                return runTest;
            }
        }
Beispiel #24
0
 private static IEnumerable<AnalysisValue> GetTestCaseClasses(IPythonProjectEntry entry)
 {
     if (entry.IsAnalyzed) {
         return entry.Analysis.GetAllAvailableMembersByIndex(0)
             .SelectMany(m => entry.Analysis.GetValuesByIndex(m.Name, 0))
             .Where(v => v.MemberType == PythonMemberType.Class)
             .Where(v => v.Mro.SelectMany(v2 => v2).Any(IsTestCaseClass));
     } else {
         return Enumerable.Empty<AnalysisValue>();
     }
 }
Beispiel #25
0
 public void AssertDescription(IPythonProjectEntry module, string expr, string description)
 {
     AssertDescription(module, expr, 0, description);
 }
Beispiel #26
0
        public void AssertDescriptionContains(IPythonProjectEntry module, string expr, int index, params string[] description)
        {
            var val = GetValue <AnalysisValue>(module, expr, index);

            AssertUtil.Contains(val?.Description, description);
        }
Beispiel #27
0
 public TagInfo(string doc, IPythonProjectEntry entry) {
     Documentation = doc;
     Entry = entry;
 }
        private static void AnalyzeCode(
            out PythonAnalyzer analyzer,
            out IPythonProjectEntry entry,
            string code,
            Version preferredVersion = null,
            InterpreterArchitecture preferredArch = null,
            string module = "test-module"
        ) {
            var provider = InterpFactory;
            var factory = provider.GetInterpreterFactories().OrderByDescending(f => f.Configuration.Version)
                .Where(f => preferredVersion == null || f.Configuration.Version == preferredVersion)
                .Where(f => preferredArch == null || f.Configuration.Architecture == preferredArch)
                .FirstOrDefault();
            Assert.IsNotNull(factory, "no factory found");

            analyzer = PythonAnalyzer.CreateSynchronously(factory);
            var path = Path.Combine(TestData.GetTempPath(randomSubPath: true), module.Replace('.', '\\'));
            Directory.CreateDirectory(PathUtils.GetParent(path));
            File.WriteAllText(path, code);

            entry = analyzer.AddModule(module, path);
            PythonAst ast;
            using (var p = Parser.CreateParser(new StringReader(code), factory.GetLanguageVersion())) {
                ast = p.ParseFile();
                entry.UpdateTree(ast, null);
            }

            entry.Analyze(CancellationToken.None, true);
        }
 private void BufferContentTypeChanged(object sender, ContentTypeChangedEventArgs e) {
     _spanCache = null;
     _buffer.Changed -= BufferChanged;
     _buffer.ContentTypeChanged -= BufferContentTypeChanged;
     if (_entry != null) {
         _entry.OnNewAnalysis -= OnNewAnalysis;
         _entry = null;
     }
     _buffer.Properties.RemoveProperty(typeof(PythonAnalysisClassifier));
 }
Beispiel #30
0
 public IOverloadResult[] GetSignatures(IPythonProjectEntry module, string exprText, int index = 0)
 {
     return(module.Analysis.GetSignaturesByIndex(exprText, index).ToArray());
 }
Beispiel #31
0
        private static void UpdateAnalysisTree(IPythonProjectEntry pyEntry, SortedDictionary<int, ParseResult> parseResults) {
            IAnalysisCookie cookie = new VersionCookie(
                parseResults.ToDictionary(
                    x => x.Key,
                    x => new BufferVersion(x.Value.Version, x.Value.Ast)
                )
            );

            var asts = parseResults.Where(x => x.Value.Ast != null).Select(x => x.Value.Ast).ToArray();
            PythonAst finalAst;
            if (asts.Length == 1) {
                finalAst = asts[0];
            } else if (asts.Length > 0) {
                // multiple ASTs, merge them together
                finalAst = new PythonAst(
                    new SuiteStatement(
                        asts.Select(ast => ast.Body).ToArray()
                    ),
                    new NewLineLocation[0],
                    asts[0].LanguageVersion
                );
            } else {
                // we failed to get any sort of AST out, so we can't analyze...
                // But we need to balance the UpdateTree call, so just fetch the
                // last valid ast and cookie.
                pyEntry.GetTreeAndCookie(out finalAst, out cookie);
            }

            pyEntry.UpdateTree(finalAst, cookie);
        }
Beispiel #32
0
 public void AssertNotHasAttr(IPythonProjectEntry module, string expr, int index, params string[] attrs)
 {
     AssertUtil.DoesntContain(GetMemberNames(module, expr, index), attrs);
 }
Beispiel #33
0
 private async void SendParseComplete(IPythonProjectEntry entry, SortedDictionary<int, ParseResult> parseResults) {
     await _connection.SendEventAsync(
         new AP.FileParsedEvent() {
             fileId = ProjectEntryMap.GetId(entry),
             buffers = parseResults.Select(
                 x => new AP.BufferParseInfo() {
                     bufferId = x.Key,
                     version = x.Value.Version,
                     errors = x.Value.Errors.Errors.Select(MakeError).ToArray(),
                     warnings = x.Value.Errors.Warnings.Select(MakeError).ToArray(),
                     hasErrors = x.Value.Errors.Errors.Any(),
                     tasks = x.Value.Tasks.ToArray()
                 }
             ).ToArray()
         }
     );
 }
Beispiel #34
0
 public void AssertHasParameters(IPythonProjectEntry module, string expr, int index, params string[] paramNames)
 {
     AssertUtil.AreEqual(module.Analysis.GetSignaturesByIndex(expr, index).Single().Parameters.Select(p => p.Name), paramNames);
 }
Beispiel #35
0
 public ImportStatementWalker(PythonAst ast, IPythonProjectEntry entry, PythonAnalyzer analyzer) {
     _ast = ast;
     _entry = entry;
     _analyzer = analyzer;
 }
Beispiel #36
0
 public void AssertIsInstance(IPythonProjectEntry module, string expr, int index)
 {
     AssertIsInstance(module, expr, index, Array.Empty <BuiltinTypeId>());
 }
 public ImportStatementWalker(IPythonProjectEntry entry, PythonAnalyzer analyzer) {
     _entry = entry;
     _analyzer = analyzer;
 }
Beispiel #38
0
 public void AssertIsInstance(IPythonProjectEntry module, string expr, params string[] className)
 {
     AssertIsInstance(module, expr, 0, className);
 }
 public void ListenForNextNewAnalysis(IPythonProjectEntry entry) {
     if (entry != null && !string.IsNullOrEmpty(entry.FilePath)) {
         entry.OnNewAnalysis += OnNewAnalysis;
     }
 }
Beispiel #40
0
 public void AssertAttrIsType(IPythonProjectEntry module, string variable, string memberName, int index, params PythonMemberType[] types)
 {
     AssertUtil.ContainsExactly(GetMember(module, variable, memberName, index).Select(m => m.MemberType), types);
 }
Beispiel #41
0
 public SysModulesDictionaryInfo(SysModuleInfo owner, IPythonProjectEntry declaringModule, Node node)
     : base(declaringModule, node)
 {
     _owner = owner;
 }
Beispiel #42
0
 public void AssertDescriptionContains(IPythonProjectEntry module, string expr, params string[] description)
 {
     AssertDescriptionContains(module, expr, 0, description);
 }
Beispiel #43
0
 public SingleIteratorValue(VariableDef indexTypes, BuiltinClassInfo iterType, IPythonProjectEntry declModule)
     : base(iterType) {
     _indexTypes = indexTypes;
     _declModule = declModule;
 }
Beispiel #44
0
 public void AssertConstantEquals(IPythonProjectEntry module, string expr, string value)
 {
     AssertConstantEquals(module, expr, 0, value);
 }
Beispiel #45
0
 private void RegisterTag(IPythonProjectEntry entry, Dictionary<string, TagInfo> tags, string name, string documentation = null) {
     TagInfo tag;
     if (!tags.TryGetValue(name, out tag) || (String.IsNullOrWhiteSpace(tag.Documentation) && !String.IsNullOrEmpty(documentation))) {
         tags[name] = tag = new TagInfo(documentation, entry);
         if (entry != null && _hookedEntries.Add(entry)) {
             entry.OnNewParseTree += OnNewParseTree;
         }
     }
 }
Beispiel #46
0
 public void AssertReferencesInclude(IPythonProjectEntry module, string expr, int index, params VariableLocation[] expectedVars)
 {
     AssertReferencesWorker(module, expr, index, false, expectedVars);
 }
Beispiel #47
0
        private IEnumerable<IPythonProjectEntry[]> MakeModulePermutations(string prefix, string[] code) {
            foreach (var p in Permutations(code.Length)) {
                var result = new IPythonProjectEntry[code.Length];
                using (var state = PythonAnalyzer.CreateSynchronously(InterpreterFactory, Interpreter)) {
                    state.Limits = GetLimits();

                    for (int i = 0; i < code.Length; i++) {
                        result[p[i]] = state.AddModule(prefix + (p[i] + 1).ToString(), "fob", null);
                    }
                    for (int i = 0; i < code.Length; i++) {
                        Prepare(result[p[i]], GetSourceUnit(code[p[i]]));
                    }
                    for (int i = 0; i < code.Length; i++) {
                        result[p[i]].Analyze(CancellationToken.None, true);
                    }

                    state.AnalyzeQueuedEntries(CancellationToken.None);

                    yield return result;
                }
            }
        }
Beispiel #48
0
        /// <summary>
        /// Returns a sequence of candidate absolute module names for the given
        /// modules.
        /// </summary>
        /// <param name="projectEntry">
        /// The project entry that is importing the module.
        /// </param>
        /// <param name="relativeModuleName">
        /// A dotted name identifying the path to the module.
        /// </param>
        /// <returns>
        /// A sequence of strings representing the absolute names of the module
        /// in order of precedence.
        /// </returns>
        internal static IEnumerable <string> ResolvePotentialModuleNames(
            IPythonProjectEntry projectEntry,
            string relativeModuleName,
            bool absoluteImports
            )
        {
            string importingFrom = null;

            if (projectEntry != null)
            {
                importingFrom = projectEntry.ModuleName;
                if (ModulePath.IsInitPyFile(projectEntry.FilePath))
                {
                    if (string.IsNullOrEmpty(importingFrom))
                    {
                        importingFrom = "__init__";
                    }
                    else
                    {
                        importingFrom += ".__init__";
                    }
                }
            }

            if (string.IsNullOrEmpty(relativeModuleName))
            {
                yield break;
            }

            // Handle relative module names
            if (relativeModuleName.FirstOrDefault() == '.')
            {
                if (string.IsNullOrEmpty(importingFrom))
                {
                    // No source to import relative to.
                    yield break;
                }

                var prefix = importingFrom.Split('.');

                if (relativeModuleName.LastOrDefault() == '.')
                {
                    // Last part empty means the whole name is dots, so there's
                    // nothing to concatenate.
                    yield return(string.Join(".", prefix.Take(prefix.Length - relativeModuleName.Length)));
                }
                else
                {
                    var suffix   = relativeModuleName.Split('.');
                    var dotCount = suffix.TakeWhile(bit => string.IsNullOrEmpty(bit)).Count();
                    if (dotCount < prefix.Length)
                    {
                        // If we have as many dots as prefix parts, the entire
                        // name will disappear. Despite what PEP 328 says, in
                        // reality this means the import will fail.
                        yield return(string.Join(".", prefix.Take(prefix.Length - dotCount).Concat(suffix.Skip(dotCount))));
                    }
                }
                yield break;
            }

            // The two possible names that can be imported here are:
            // * relativeModuleName
            // * importingFrom.relativeModuleName
            // and the order they are returned depends on whether
            // absolute_import is enabled or not.

            // With absolute_import, we treat the name as complete first.
            if (absoluteImports)
            {
                yield return(relativeModuleName);
            }

            if (!string.IsNullOrEmpty(importingFrom))
            {
                var prefix = importingFrom.Split('.');

                if (prefix.Length > 1)
                {
                    var adjacentModuleName = string.Join(".", prefix.Take(prefix.Length - 1)) + "." + relativeModuleName;
                    yield return(adjacentModuleName);
                }
            }

            // Without absolute_import, we treat the name as complete last.
            if (!absoluteImports)
            {
                yield return(relativeModuleName);
            }
        }
Beispiel #49
0
        private SaveLoadResult SaveLoad(PythonLanguageVersion version, params AnalysisModule[] modules) {
            IPythonProjectEntry[] entries = new IPythonProjectEntry[modules.Length];

            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
            var interp = fact.CreateInterpreter();

            var dbFolder = TestData.GetTempPath(randomSubPath: true);
            Directory.CreateDirectory(dbFolder);

            var state = new PythonAnalysis(fact, interp, SharedDatabaseState.BuiltinName2x);
            state.CreateProjectOnDisk = true;
            for (int i = 0; i < modules.Length; i++) {
                state.AddModule(modules[i].ModuleName, modules[i].Code, modules[i].Filename);
            }

            state.WaitForAnalysis();

            new SaveAnalysis().Save(state.Analyzer, dbFolder);

            File.Copy(
                Path.Combine(PythonTypeDatabase.BaselineDatabasePath, "__builtin__.idb"),
                Path.Combine(dbFolder, "__builtin__.idb"),
                true
            );

            var loadFactory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(
                version.ToVersion(),
                null,
                dbFolder
            );
            return new SaveLoadResult(CreateAnalyzer(loadFactory), state.CodeFolder);
        }
 public void StopListening(IPythonProjectEntry entry) {
     if (entry != null) {
         entry.OnNewAnalysis -= OnNewAnalysis;
         _taskProvider.Clear(entry, VsProjectAnalyzer.UnresolvedImportMoniker);
     }
 }
Beispiel #51
0
 public StarArgsDictionaryInfo(IPythonProjectEntry declaringModule, Node node)
     : base(declaringModule, node)
 {
 }
Beispiel #52
0
 public ImportedModuleNameWalker(IPythonProjectEntry entry, int location, PythonAst ast) :
     this(entry.ModuleName, entry.FilePath, location, ast)
 {
 }
Beispiel #53
0
 internal void UpdateProjectEntry(IProjectEntry newEntry) {
     if (newEntry is IPythonProjectEntry) {
         _projectEntry.OnNewParseTree -= ParserOnNewParseTree;
         _projectEntry = (IPythonProjectEntry)newEntry;
         _projectEntry.OnNewParseTree += ParserOnNewParseTree;
     }
 }
Beispiel #54
0
 public TagInfo(string doc, IPythonProjectEntry entry)
 {
     Documentation = doc;
     Entry         = entry;
 }
Beispiel #55
0
 public IEnumerable <string> GetAllNames(IPythonProjectEntry module, int index = 0)
 {
     return(module.Analysis.GetAllAvailableMembers(SourceLocation.MinValue).Select(m => m.Name));
 }
Beispiel #56
0
 public PartialFunctionInfo(ProjectEntry declProjEntry, IAnalysisSet function, IAnalysisSet[] args, NameExpression[] keywordArgNames) {
     _declProjEntry = declProjEntry;
     _function = function;
     _args = args;
     _keywordArgNames = keywordArgNames;
 }
Beispiel #57
0
 public IEnumerable <string> GetNamesNoBuiltins(IPythonProjectEntry module, int index = 0)
 {
     return(module.Analysis.GetVariablesNoBuiltinsByIndex(index));
 }