private static IReadOnlyCollection <string> GetPackagesFromDirectory(string searchPath) { return(ModulePath.GetModulesInPath( searchPath, recurse: false ).Select(mp => mp.ModuleName).Where(n => !string.IsNullOrEmpty(n)).ToList()); }
private async Task <IReadOnlyCollection <string> > GetPackagesFromDirectoryAsync(string searchPath, CancellationToken cancellationToken) { return(ModulePath.GetModulesInPath( searchPath, recurse: false, requireInitPy: ModulePath.PythonVersionRequiresInitPyFiles(_langVersion) ).Select(mp => mp.ModuleName).Where(n => !string.IsNullOrEmpty(n)).ToList()); }
private static IReadOnlyCollection <string> GetPackagesFromDirectory(string searchPath, CancellationToken cancellationToken) { return(ModulePath.GetModulesInPath( searchPath, recurse: false, includePackages: true ).Select(mp => mp.ModuleName).Where(n => !string.IsNullOrEmpty(n)).TakeWhile(_ => !cancellationToken.IsCancellationRequested).ToList()); }
/// <summary> /// Returns ModulePaths representing the modules that should be analyzed /// for the given search paths. /// </summary> /// <param name="languageVersion"> /// The Python language version to assume. This affects whether /// namespace packages are supported or not. /// </param> /// <param name="searchPaths">A sequence of paths to search.</param> /// <returns> /// All the expected modules, grouped based on codependency. When /// analyzing modules, all those in the same list should be analyzed /// together. /// </returns> /// <remarks>Added in 2.2</remarks> public static IEnumerable <List <ModulePath> > GetDatabaseExpectedModules( Version languageVersion, IEnumerable <PythonLibraryPath> searchPaths ) { var requireInitPy = ModulePath.PythonVersionRequiresInitPyFiles(languageVersion); var stdlibGroup = new List <ModulePath>(); var packages = new List <List <ModulePath> > { stdlibGroup }; foreach (var path in searchPaths ?? Enumerable.Empty <PythonLibraryPath>()) { if (path.IsStandardLibrary) { stdlibGroup.AddRange(ModulePath.GetModulesInPath( path.Path, includeTopLevelFiles: true, recurse: true, // Always require __init__.py for stdlib folders // Otherwise we will probably include libraries multiple // times, and while Python 3.3+ allows this, it's really // not a good idea. requireInitPy: true )); } else { packages.Add(ModulePath.GetModulesInPath( path.Path, includeTopLevelFiles: true, recurse: false, basePackage: path.ModulePrefix ).ToList()); packages.AddRange(ModulePath.GetModulesInPath( path.Path, includeTopLevelFiles: false, recurse: true, basePackage: path.ModulePrefix, requireInitPy: requireInitPy ).GroupBy(g => g.LibraryPath).Select(g => g.ToList())); } } return(packages); }
private static IEnumerable <string> GetChildModules(string filePath, string prefix, AstPythonInterpreter interpreter) { if (interpreter == null || string.IsNullOrEmpty(filePath)) { yield break; } var searchPath = PathUtils.GetParent(filePath); if (!Directory.Exists(searchPath)) { yield break; } foreach (var n in ModulePath.GetModulesInPath( searchPath, recurse: false ).Select(mp => mp.ModuleName).Where(n => !string.IsNullOrEmpty(n))) { yield return(n); } }