예제 #1
0
        private AstPythonInterpreterFactory(
            InterpreterConfiguration config,
            InterpreterFactoryCreationOptions options,
            bool useDefaultDatabase
            )
        {
            Configuration   = config ?? throw new ArgumentNullException(nameof(config));
            CreationOptions = options ?? new InterpreterFactoryCreationOptions();
            try {
                LanguageVersion = Configuration.Version.ToLanguageVersion();
            } catch (InvalidOperationException ex) {
                throw new ArgumentException(ex.Message, ex);
            }

            _useDefaultDatabase = useDefaultDatabase;
            if (!string.IsNullOrEmpty(CreationOptions.DatabasePath) && CreationOptions.TraceLevel != TraceLevel.Off)
            {
                _log = new AnalysisLogWriter(Path.Combine(CreationOptions.DatabasePath, "AnalysisLog.txt"), false, LogToConsole, LogCacheSize);
                _log.Rotate(LogRotationSize);
                _log.MinimumLevel = CreationOptions.TraceLevel;
            }

            ModuleCache      = new AstModuleCache(config, CreationOptions.DatabasePath, useDefaultDatabase, !CreationOptions.UseExistingCache, _log);
            ModuleResolution = new AstModuleResolution(ModuleCache, config, _log);
        }
예제 #2
0
        protected virtual List <string> GetScrapeArguments(IPythonInterpreterFactory factory)
        {
            var args = new List <string> {
                "-B", "-E"
            };

            ModulePath mp = AstModuleResolution.FindModuleAsync(factory, _filePath, CancellationToken.None)
                            .WaitAndUnwrapExceptions();

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

            if (!InstallPath.TryGetFile("scrape_module.py", out string sm))
            {
                return(null);
            }

            args.Add(sm);
            args.Add("-u8");
            args.Add(mp.ModuleName);
            args.Add(mp.LibraryPath);

            return(args);
        }
        public AstPythonInterpreter(AstPythonInterpreterFactory factory, bool useDefaultDatabase, AnalysisLogWriter log = null)
        {
            _factory = factory ?? throw new ArgumentNullException(nameof(factory));
            _factory.ImportableModulesChanged += Factory_ImportableModulesChanged;

            Log = log;

            ModuleCache      = new AstModuleCache(factory.Configuration, factory.CreationOptions.DatabasePath, useDefaultDatabase, factory.CreationOptions.UseExistingCache, log);
            ModuleResolution = new AstModuleResolution(this, _modules, ModuleCache, factory.Configuration, log);
        }