Esempio n. 1
0
        internal PythonAnalyzer(IPythonInterpreterFactory factory, IPythonInterpreter pythonInterpreter, string builtinName)
        {
            _interpreterFactory           = factory;
            _langVersion                  = factory.GetLanguageVersion();
            _disposeInterpreter           = pythonInterpreter == null;
            _interpreter                  = pythonInterpreter ?? factory.CreateInterpreter();
            _builtinName                  = builtinName ?? (_langVersion.Is3x() ? SharedDatabaseState.BuiltinName3x : SharedDatabaseState.BuiltinName2x);
            _modules                      = new ModuleTable(this, _interpreter);
            _modulesByFilename            = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);
            _modulesWithUnresolvedImports = new HashSet <ModuleInfo>();
            _itemCache                    = new Dictionary <object, AnalysisValue>();

            try {
                using (var key = Registry.CurrentUser.OpenSubKey(AnalysisLimitsKey)) {
                    Limits = AnalysisLimits.LoadFromStorage(key);
                }
            } catch (SecurityException) {
                Limits = new AnalysisLimits();
            } catch (UnauthorizedAccessException) {
                Limits = new AnalysisLimits();
            } catch (IOException) {
                Limits = new AnalysisLimits();
            }

            _queue = new Deque <AnalysisUnit>();

            _defaultContext = _interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);

            LoadInitialKnownTypes();
        }
Esempio n. 2
0
        internal PythonAnalyzer(IPythonInterpreterFactory factory, IPythonInterpreter pythonInterpreter)
        {
            _interpreterFactory           = factory;
            _langVersion                  = factory.GetLanguageVersion();
            _disposeInterpreter           = pythonInterpreter == null;
            _interpreter                  = pythonInterpreter ?? factory.CreateInterpreter();
            _builtinName                  = _langVersion.Is3x() ? SharedDatabaseState.BuiltinName3x : SharedDatabaseState.BuiltinName2x;
            _modules                      = new ModuleTable(this, _interpreter);
            _modulesByFilename            = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);
            _modulesWithUnresolvedImports = new HashSet <ModuleInfo>();
            _itemCache                    = new Dictionary <object, AnalysisValue>();

            Limits = AnalysisLimits.GetDefaultLimits();

            _queue = new Deque <AnalysisUnit>();

            _defaultContext = _interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);

            try {
                LoadInitialKnownTypes();
            } catch (Exception ex) {
                if (ex.IsCriticalException())
                {
                    throw;
                }
                // This will be rethrown in LoadKnownTypesAsync
                _loadKnownTypesException = ExceptionDispatchInfo.Capture(ex);
            }
        }
        internal PythonAnalyzer(IPythonInterpreterFactory factory)
        {
            InterpreterFactory = factory;
            LanguageVersion    = factory.GetLanguageVersion();
            Interpreter        = factory.CreateInterpreter();
            _pathResolver      = new PathResolver(LanguageVersion);

            _builtinName      = BuiltinTypeId.Unknown.GetModuleName(LanguageVersion);
            Modules           = new ModuleTable(this, Interpreter);
            ModulesByFilename = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);

            Limits = AnalysisLimits.GetDefaultLimits();
            Queue  = new Deque <AnalysisUnit>();

            _defaultContext = Interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);
        }
Esempio n. 4
0
        internal PythonAnalyzer(IPythonInterpreterFactory factory, IPythonInterpreter pythonInterpreter)
        {
            _interpreterFactory           = factory;
            _langVersion                  = factory.GetLanguageVersion();
            _disposeInterpreter           = pythonInterpreter == null;
            _interpreter                  = pythonInterpreter ?? factory.CreateInterpreter();
            _builtinName                  = BuiltinTypeId.Unknown.GetModuleName(_langVersion);
            _modules                      = new ModuleTable(this, _interpreter);
            _modulesByFilename            = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);
            _modulesWithUnresolvedImports = new HashSet <ModuleInfo>();
            _itemCache                    = new Dictionary <object, AnalysisValue>();

            Limits = AnalysisLimits.GetDefaultLimits();

            Queue = new Deque <AnalysisUnit>();

            _defaultContext = _interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);
        }
Esempio n. 5
0
 internal VsProjectAnalyzer(
     IServiceProvider serviceProvider,
     IPythonInterpreterFactory factory,
     IPythonInterpreterFactory[] allFactories)
     : this(serviceProvider, factory.CreateInterpreter(), factory, allFactories) {
 }
Esempio n. 6
0
 public PythonAnalyzer(IPythonInterpreterFactory interpreterFactory)
     : this(interpreterFactory.CreateInterpreter(), interpreterFactory.GetLanguageVersion())
 {
 }
Esempio n. 7
0
 public BaseAnalysisTest(IPythonInterpreterFactory factory)
     : this(factory, factory.CreateInterpreter())
 {
 }
Esempio n. 8
0
        public AnalysisView(
            string dbDir,
            Version version     = null,
            bool withContention = false,
            bool withRecursion  = false
            )
        {
            var paths = new List <string>();

            paths.Add(dbDir);
            while (!File.Exists(IOPath.Combine(paths[0], "__builtin__.idb")) &&
                   !File.Exists(IOPath.Combine(paths[0], "builtins.idb")))
            {
                var upOne = IOPath.GetDirectoryName(paths[0]);
                if (string.IsNullOrEmpty(upOne) || upOne == paths[0])
                {
                    break;
                }
                paths.Insert(0, upOne);
            }

            if (withRecursion)
            {
                paths.AddRange(Directory.EnumerateDirectories(dbDir, "*", SearchOption.AllDirectories));
            }

            if (version == null)
            {
                if (File.Exists(IOPath.Combine(paths[0], "builtins.idb")))
                {
                    version = new Version(3, 3);
                }
                else
                {
                    version = new Version(2, 7);
                }
            }

            _factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(
                version,
                dbDir,
                paths.ToArray()
                );
            Path         = dbDir;
            _interpreter = _factory.CreateInterpreter();
            _context     = _interpreter.CreateModuleContext();

            var modNames = _interpreter.GetModuleNames();
            IEnumerable <Tuple <string, string> > modItems;

            if (!withRecursion)
            {
                modItems = modNames
                           .Select(n => Tuple.Create(n, IOPath.Combine(dbDir, n + ".idb")))
                           .Where(t => File.Exists(t.Item2));
            }
            else
            {
                modItems = modNames
                           .Select(n => Tuple.Create(
                                       n,
                                       Directory.EnumerateFiles(dbDir, n + ".idb", SearchOption.AllDirectories).FirstOrDefault()
                                       ))
                           .Where(t => File.Exists(t.Item2));
            }

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            if (withContention)
            {
                modItems = modItems
                           .AsParallel()
                           .WithExecutionMode(ParallelExecutionMode.ForceParallelism);
            }
            _modules = modItems
                       .Select(t => new ModuleView(_interpreter, _context, t.Item1, t.Item2))
                       .OrderBy(m => m.SortKey)
                       .ThenBy(m => m.Name)
                       .ToList <IAnalysisItemView>();
            stopwatch.Stop();

            _modules.Insert(0, new KnownTypesView(_interpreter, version));

            LoadMilliseconds    = stopwatch.ElapsedMilliseconds;
            TopLevelModuleCount = _modules.Count - 1;
        }
 public PythonAnalyzer(IPythonInterpreterFactory factory, IPythonInterpreter interpreter = null)
     : this(factory, interpreter ?? factory.CreateInterpreter(), null)
 {
 }
Esempio n. 10
0
        public AnalysisView(
            string dbDir,
            Version version = null,
            bool withContention = false,
            bool withRecursion = false
        ) {
            var paths = new List<string>();
            paths.Add(dbDir);
            while (!File.Exists(IOPath.Combine(paths[0], "__builtin__.idb")) &&
                !File.Exists(IOPath.Combine(paths[0], "builtins.idb"))) {
                var upOne = IOPath.GetDirectoryName(paths[0]);
                if (string.IsNullOrEmpty(upOne) || upOne == paths[0]) {
                    break;
                }
                paths.Insert(0, upOne);
            }

            if (withRecursion) {
                paths.AddRange(Directory.EnumerateDirectories(dbDir, "*", SearchOption.AllDirectories));
            }

            if (version == null) {
                if (File.Exists(IOPath.Combine(paths[0], "builtins.idb"))) {
                    version = new Version(3, 3);
                } else {
                    version = new Version(2, 7);
                }
            }

            _factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(
                version,
                dbDir,
                paths.ToArray()
            );
            Path = dbDir;
            _interpreter = _factory.CreateInterpreter();
            _context = _interpreter.CreateModuleContext();

            var modNames = _interpreter.GetModuleNames();
            IEnumerable<Tuple<string, string>> modItems;

            if (!withRecursion) {
                modItems = modNames
                    .Select(n => Tuple.Create(n, IOPath.Combine(dbDir, n + ".idb")))
                    .Where(t => File.Exists(t.Item2));
            } else {
                modItems = modNames
                    .Select(n => Tuple.Create(
                        n,
                        Directory.EnumerateFiles(dbDir, n + ".idb", SearchOption.AllDirectories).FirstOrDefault()
                    ))
                    .Where(t => File.Exists(t.Item2));
            }

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            if (withContention) {
                modItems = modItems
                    .AsParallel()
                    .WithExecutionMode(ParallelExecutionMode.ForceParallelism);
            }
            _modules = modItems
                .Select(t => new ModuleView(_interpreter, _context, t.Item1, t.Item2))
                .OrderBy(m => m.SortKey)
                .ThenBy(m => m.Name)
                .ToList<IAnalysisItemView>();
            stopwatch.Stop();

            _modules.Insert(0, new KnownTypesView(_interpreter, version));

            LoadMilliseconds = stopwatch.ElapsedMilliseconds;
            TopLevelModuleCount = _modules.Count - 1;
        }
Esempio n. 11
0
 public BaseAnalysisTest(IPythonInterpreterFactory factory)
     : this(factory, factory.CreateInterpreter()) {
 }
Esempio n. 12
0
 public IPythonInterpreter CreateInterpreter()
 {
     return(_realFactory.CreateInterpreter());
 }
Esempio n. 13
0
 public ProjectAnalyzer(IPythonInterpreterFactory factory, IErrorProviderFactory errorProvider)
     : this(factory.CreateInterpreter(), factory, errorProvider)
 {
 }