コード例 #1
0
        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);
        }
コード例 #2
0
 protected override void SaveCachedCode(AstPythonInterpreter interpreter, Stream code)
 {
     if (interpreter.InterpreterPath != null)
     {
         interpreter.ModuleCache.WriteCachedModule(interpreter.InterpreterPath, code);
     }
 }
コード例 #3
0
 protected override Stream LoadCachedCode(AstPythonInterpreter interpreter)
 {
     if (interpreter.Factory is AstPythonInterpreterFactory factory)
     {
         return(factory.ReadCachedModule(_cachedModuleName));
     }
     return(null);
 }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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
            });
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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
                       ));
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: AstPythonModule.cs プロジェクト: scfunknown/PTVS
        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);
            }
        }
コード例 #11
0
 protected override void SaveCachedCode(AstPythonInterpreter interpreter, Stream code)
 {
     // Cannot save
 }
コード例 #12
0
 protected override List <string> GetScrapeArguments(AstPythonInterpreter factory)
 {
     // Cannot scrape this module
     return(null);
 }
コード例 #13
0
 protected virtual Stream LoadCachedCode(AstPythonInterpreter interpreter)
 {
     return(interpreter.ModuleCache.ReadCachedModule(_filePath));
 }
コード例 #14
0
 internal static async Task <ModulePath> FindModuleAsync(AstPythonInterpreter interpreter, string filePath, CancellationToken cancellationToken)
 {
     try {
         return(await interpreter.ModuleResolution.FindModuleAsync(filePath, cancellationToken));
     } catch (ArgumentException) {
         return(default);
コード例 #15
0
 protected virtual void SaveCachedCode(AstPythonInterpreter interpreter, Stream code)
 {
     interpreter.ModuleCache.WriteCachedModule(_filePath, code);
 }
コード例 #16
0
 protected virtual Stream LoadCachedCode(AstPythonInterpreter interpreter)
 {
     return((interpreter.Factory as AstPythonInterpreterFactory)?.ReadCachedModule(_filePath));
 }
コード例 #17
0
        protected override Stream LoadCachedCode(AstPythonInterpreter interpreter)
        {
            var path = interpreter.InterpreterPath ?? "python.exe";

            return(interpreter.ModuleCache.ReadCachedModule(path));
        }
コード例 #18
0
 protected virtual void SaveCachedCode(AstPythonInterpreter interpreter, Stream code)
 {
     (interpreter.Factory as AstPythonInterpreterFactory)?.WriteCachedModule(_filePath, code);
 }
コード例 #19
0
 protected override Stream LoadCachedCode(AstPythonInterpreter interpreter)
 {
     return(PathUtils.OpenWithRetry(_cachePath, FileMode.Open, FileAccess.Read, FileShare.Read));
 }