/// <summary> /// Gets an instance of each module of the type. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> static public T[] GetAll <T>() where T : class, IModuleInstance { // Must go through the module type manager so that it can affect the instance. IModuleManagement moduleManager = Modules.GetManager <T>(); if (moduleManager != null) { return(moduleManager.GetAll().Cast <T>().ToArray()); } return(null); }
public DependencyCollector(IPythonModule module, bool?isTypeShed = null) { _module = module; _isTypeshed = isTypeShed ?? module.IsTypeshed; _moduleResolution = module.Interpreter.ModuleResolution; _pathResolver = _isTypeshed ? module.Interpreter.TypeshedResolution.CurrentPathResolver : _moduleResolution.CurrentPathResolver; if (module.Stub != null) { Dependencies.Add(new AnalysisModuleKey(module.Stub)); } }
/// <summary> /// Gets an instance of a module. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> static public T Get <T>(Guid id) where T : class, IModuleInstance { // Must go through the module type manager, instead of using // Modules.GetById, so that the type manager can affect the instance. // Modules.ModuleManagement can be called when the name of the module // type is known, which it is not here. IModuleManagement moduleManager = Modules.GetManager <T>(); if (moduleManager != null) { return(moduleManager.Get(id) as T); } return(null); }
public DependencyWalker(IPythonModule module) { _module = module; _isTypeshed = module is StubPythonModule stub && stub.IsTypeshed; _moduleResolution = module.Interpreter.ModuleResolution; _pathResolver = _isTypeshed ? module.Interpreter.TypeshedResolution.CurrentPathResolver : _moduleResolution.CurrentPathResolver; Dependencies = new HashSet <AnalysisModuleKey>(); if (module.Stub != null) { Dependencies.Add(new AnalysisModuleKey(module.Stub)); } }
private async Task <bool> AnalyzeFiles(IModuleManagement moduleManagement, IEnumerable <Uri> files, CancellationToken cancellationToken) { var analysisTasks = new List <Task>(); foreach (var f in files) { if (moduleManagement.TryAddModulePath(f.ToAbsolutePath(), false, out var fullName)) { var module = moduleManagement.GetOrLoadModule(fullName); if (module is IDocument document) { analysisTasks.Add(document.GetAnalysisAsync(cancellationToken: cancellationToken)); } } } if (analysisTasks.Count > 0) { await Task.WhenAll(analysisTasks); } return(analysisTasks.Count > 0); }
private static bool Ignore(IModuleManagement moduleResolution, string fullName, string modulePath) => moduleResolution.BuiltinModuleName.EqualsOrdinal(fullName) || moduleResolution.IsSpecializedModule(fullName, modulePath);
private async Task <bool> AnalyzeFiles(IModuleManagement moduleManagement, IEnumerable <(Uri path, long fileSize)> files, CancellationToken cancellationToken)
private static bool Ignore(IModuleManagement moduleResolution, string name) => moduleResolution.BuiltinModuleName.EqualsOrdinal(name) || moduleResolution.GetSpecializedModule(name) != null;
private static void HandleSearchResults(bool isTypeshed, HashSet <AnalysisModuleKey> dependencies, IModuleManagement moduleResolution, IImportSearchResult searchResult) { switch (searchResult) { case ModuleImport moduleImport when !Ignore(moduleResolution, moduleImport.FullName): dependencies.Add(new AnalysisModuleKey(moduleImport.FullName, moduleImport.ModulePath, isTypeshed)); return; case PossibleModuleImport possibleModuleImport when !Ignore(moduleResolution, possibleModuleImport.PrecedingModuleFullName): dependencies.Add(new AnalysisModuleKey(possibleModuleImport.PrecedingModuleFullName, possibleModuleImport.PrecedingModulePath, isTypeshed)); return; default: return; } }