protected virtual List <string> GetScrapeArguments(AstPythonInterpreter interpreter) { var args = new List <string> { "-B", "-E" }; ModulePath mp = AstModuleResolution.FindModuleAsync(interpreter, _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); }
protected override void SaveCachedCode(AstPythonInterpreter interpreter, Stream code) { if (interpreter.InterpreterPath != null) { interpreter.ModuleCache.WriteCachedModule(interpreter.InterpreterPath, code); } }
protected override Stream LoadCachedCode(AstPythonInterpreter interpreter) { if (interpreter.Factory is AstPythonInterpreterFactory factory) { return(factory.ReadCachedModule(_cachedModuleName)); } return(null); }
protected override Stream LoadCachedCode(AstPythonInterpreter interpreter) { var fact = interpreter.Factory as AstPythonInterpreterFactory; if (fact?.Configuration.InterpreterPath == null) { return(fact.ReadCachedModule("python.exe")); } return(fact.ReadCachedModule(fact.Configuration.InterpreterPath)); }
protected override void SaveCachedCode(AstPythonInterpreter interpreter, Stream code) { var fact = interpreter.Factory as AstPythonInterpreterFactory; if (fact?.Configuration.InterpreterPath == null) { return; } fact.WriteCachedModule(fact.Configuration.InterpreterPath, code); }
protected override List <string> GetScrapeArguments(AstPythonInterpreter interpreter) { if (!InstallPath.TryGetFile("scrape_module.py", out string sm)) { return(null); } return(new List <string> { "-B", "-E", sm, "-u8", Name }); }
protected override Stream LoadCachedCode(AstPythonInterpreter interpreter) { var filePath = _cachePath; if (Directory.Exists(_cachePath)) { filePath = Path.Combine(_cachePath, Name); if (!File.Exists(filePath)) { return(new MemoryStream()); } } return(PathUtils.OpenWithRetry(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)); }
protected virtual PythonWalker PrepareWalker(AstPythonInterpreter interpreter, PythonAst ast) { #if DEBUG // In debug builds we let you F12 to the scraped file var filePath = string.IsNullOrEmpty(_filePath) ? null : interpreter.ModuleCache.GetCacheFilePath(_filePath); var uri = string.IsNullOrEmpty(filePath) ? null : new Uri(filePath); const bool includeLocations = true; #else const string filePath = null; const Uri uri = null; const bool includeLocations = false; #endif return(new AstAnalysisWalker( interpreter, interpreter.CurrentPathResolver, ast, this, filePath, uri, _members, includeLocations, warnAboutUndefinedValues: true, suppressBuiltinLookup: false )); }
protected override PythonWalker PrepareWalker(AstPythonInterpreter interpreter, PythonAst ast) { string filePath = null; #if DEBUG filePath = interpreter.ModuleCache.GetCacheFilePath(interpreter.InterpreterPath ?? "python.exe"); const bool includeLocations = true; #else const bool includeLocations = false; #endif var walker = new AstAnalysisWalker( interpreter, interpreter.CurrentPathResolver, ast, this, filePath, null, _members, includeLocations, warnAboutUndefinedValues: true, suppressBuiltinLookup: true ) { CreateBuiltinTypes = true }; return(walker); }
private static IEnumerable <string> GetChildModules(string filePath, string prefix, AstPythonInterpreter interpreter) { if (interpreter == null || string.IsNullOrEmpty(filePath)) { yield break; } var searchPath = Path.GetDirectoryName(filePath); if (!Directory.Exists(searchPath)) { yield break; } foreach (var n in ModulePath.GetModulesInPath( searchPath, recurse: false, includePackages: true ).Select(mp => mp.ModuleName).Where(n => !string.IsNullOrEmpty(n))) { yield return(n); } }
protected override void SaveCachedCode(AstPythonInterpreter interpreter, Stream code) { // Cannot save }
protected override List <string> GetScrapeArguments(AstPythonInterpreter factory) { // Cannot scrape this module return(null); }
protected virtual Stream LoadCachedCode(AstPythonInterpreter interpreter) { return(interpreter.ModuleCache.ReadCachedModule(_filePath)); }
internal static async Task <ModulePath> FindModuleAsync(AstPythonInterpreter interpreter, string filePath, CancellationToken cancellationToken) { try { return(await interpreter.ModuleResolution.FindModuleAsync(filePath, cancellationToken)); } catch (ArgumentException) { return(default);
protected virtual void SaveCachedCode(AstPythonInterpreter interpreter, Stream code) { interpreter.ModuleCache.WriteCachedModule(_filePath, code); }
protected virtual Stream LoadCachedCode(AstPythonInterpreter interpreter) { return((interpreter.Factory as AstPythonInterpreterFactory)?.ReadCachedModule(_filePath)); }
protected override Stream LoadCachedCode(AstPythonInterpreter interpreter) { var path = interpreter.InterpreterPath ?? "python.exe"; return(interpreter.ModuleCache.ReadCachedModule(path)); }
protected virtual void SaveCachedCode(AstPythonInterpreter interpreter, Stream code) { (interpreter.Factory as AstPythonInterpreterFactory)?.WriteCachedModule(_filePath, code); }
protected override Stream LoadCachedCode(AstPythonInterpreter interpreter) { return(PathUtils.OpenWithRetry(_cachePath, FileMode.Open, FileAccess.Read, FileShare.Read)); }