public IList <string> GetModuleNames() { var ussp = GetUserSearchPathPackagesAsync(CancellationToken.None).WaitAndUnwrapExceptions(); var ssp = _factory.GetImportableModulesAsync(CancellationToken.None).WaitAndUnwrapExceptions(); var bmn = _builtinModuleNames; if (bmn == null && _builtinModule != null) { var builtinModules = (_builtinModule as IBuiltinPythonModule)?.GetAnyMember("__builtin_module_names__"); bmn = _builtinModuleNames = (builtinModules as AstPythonStringLiteral)?.Value?.Split(',') ?? Array.Empty <string>(); } IEnumerable <string> names = null; if (ussp != null) { names = ussp.Keys; } if (ssp != null) { names = names?.Union(ssp.Keys) ?? ssp.Keys; } if (bmn != null) { names = names?.Union(bmn) ?? bmn; } return(names.MaybeEnumerate().ToArray()); }
private async Task <IReadOnlyDictionary <string, string> > GetUserSearchPathPackagesAsync() { _log?.Log(TraceLevel.Verbose, "GetUserSearchPathPackagesAsync"); var ussp = _userSearchPathPackages; if (ussp == null) { IReadOnlyList <string> usp; lock (_userSearchPathsLock) { usp = _userSearchPaths; ussp = _userSearchPathPackages; } if (ussp != null || usp == null || !usp.Any()) { return(ussp); } _log?.Log(TraceLevel.Verbose, "GetImportableModulesAsync"); ussp = await AstPythonInterpreterFactory.GetImportableModulesAsync(usp); lock (_userSearchPathsLock) { if (_userSearchPathPackages == null) { _userSearchPathPackages = ussp; } else { ussp = _userSearchPathPackages; } } } _log?.Log(TraceLevel.Verbose, "GetUserSearchPathPackagesAsync", ussp.Keys.Cast <object>().ToArray()); return(ussp); }
private async Task <IReadOnlyDictionary <string, string> > GetUserSearchPathPackagesAsync() { var ussp = _userSearchPathPackages; if (ussp == null) { IReadOnlyList <string> usp; lock (_userSearchPathsLock) { usp = _userSearchPaths; ussp = _userSearchPathPackages; } if (ussp != null || usp == null || !usp.Any()) { return(ussp); } ussp = await AstPythonInterpreterFactory.GetImportableModulesAsync(usp); lock (_userSearchPathsLock) { if (_userSearchPathPackages == null) { _userSearchPathPackages = ussp; } else { ussp = _userSearchPathPackages; } } } return(ussp); }
public IList <string> GetModuleNames() { var ussp = GetUserSearchPathPackagesAsync().WaitAndUnwrapExceptions(); var ssp = _factory.GetImportableModulesAsync().WaitAndUnwrapExceptions(); var bmn = _builtinModuleNames; IEnumerable <string> names = null; if (ussp != null) { names = ussp.Keys; } if (ssp != null) { names = names?.Union(ssp.Keys) ?? ssp.Keys; } if (bmn != null) { names = names?.Union(bmn) ?? bmn; } return(names.MaybeEnumerate().ToArray()); }
private async Task <IReadOnlyDictionary <string, string> > GetUserSearchPathPackagesAsync(CancellationToken cancellationToken) { _log?.Log(TraceLevel.Verbose, "GetUserSearchPathPackagesAsync"); var ussp = _userSearchPathPackages; if (ussp == null) { IReadOnlyList <string> usp; lock (_userSearchPathsLock) { usp = _userSearchPaths; ussp = _userSearchPathPackages; } if (ussp != null || usp == null || !usp.Any()) { return(ussp); } _log?.Log(TraceLevel.Verbose, "GetImportableModulesAsync"); var requireInitPy = ModulePath.PythonVersionRequiresInitPyFiles(_factory.Configuration.Version); ussp = await AstPythonInterpreterFactory.GetImportableModulesAsync(usp, requireInitPy, cancellationToken); lock (_userSearchPathsLock) { if (_userSearchPathPackages == null) { _userSearchPathPackages = ussp; } else { ussp = _userSearchPathPackages; } } } _log?.Log(TraceLevel.Verbose, "GetUserSearchPathPackagesAsync", ussp.Keys.Cast <object>().ToArray()); return(ussp); }