Esempio n. 1
0
        public static bool CheckForExternalProfiler()
        {
            var driver = PythonToolsInstallPath.TryGetFile(ExternalProfilerDriverExe, typeof(PythonProfilingPackage).Assembly);

            if (string.IsNullOrEmpty(driver))
            {
                return(false);
            }

            try {
                var psi = new ProcessStartInfo(driver, "-p")
                {
                    UseShellExecute = false,
                    // Arguments = args,
                    CreateNoWindow         = true,
                    RedirectStandardOutput = false,
                    RedirectStandardError  = false,
                };

                using (var process = Process.Start(psi)) {
                    process.WaitForExit();
                    return(process.ExitCode == 0);
                }
            } catch (Exception ex) {
                Debug.Fail($"Failed to launch {driver} because {ex}");
            }

            return(false);
        }
Esempio n. 2
0
        protected virtual List <string> GetScrapeArguments(IPythonInterpreterFactory factory)
        {
            var args = new List <string> {
                "-B", "-E"
            };

            ModulePath mp = AstPythonInterpreterFactory.FindModule(factory, _filePath);

            if (string.IsNullOrEmpty(mp.FullName))
            {
                return(null);
            }

            var sm = PythonToolsInstallPath.TryGetFile("scrape_module.py", GetType().Assembly);

            if (!File.Exists(sm))
            {
                return(null);
            }

            args.Add(sm);
            args.Add("-u8");
            args.Add(mp.ModuleName);
            args.Add(mp.LibraryPath);

            return(args);
        }
Esempio n. 3
0
        private CookiecutterPythonInterpreter FindEmbeddedInterpreter()
        {
            var path = PythonToolsInstallPath.TryGetFile(@"python-3.5.1-embed-win32\python.exe");

            if (!string.IsNullOrEmpty(path))
            {
                return(new CookiecutterPythonInterpreter(path));
            }

            return(null);
        }
Esempio n. 4
0
        protected override List <string> GetScrapeArguments(IPythonInterpreterFactory factory)
        {
            var sm = PythonToolsInstallPath.TryGetFile("scrape_module.py", GetType().Assembly);

            if (!File.Exists(sm))
            {
                return(null);
            }

            return(new List <string> {
                "-B", "-E", sm, "-u8", Name
            });
        }
Esempio n. 5
0
        protected override List <string> GetScrapeArguments(IPythonInterpreterFactory factory)
        {
            var args = new List <string> {
                "-B", "-E"
            };

            var sb = PythonToolsInstallPath.TryGetFile("scrape_module.py", GetType().Assembly);

            if (!File.Exists(sb))
            {
                return(null);
            }
            args.Add(sb);

            return(args);
        }
Esempio n. 6
0
        public void ProjectItemFinishedGenerating(ProjectItem projectItem)
        {
            if (!projectItem.Name.Equals("web.debug.config", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var projectDir = PathUtils.GetParent(projectItem.get_FileNames(0));

            // Also copy Microsoft.PythonTools.WebRole.dll and ptvsd into the project
            var ptvsdSource = PythonToolsInstallPath.TryGetFile("ptvsd\\__init__.py", GetType().Assembly);
            var ptvsdDest   = PathUtils.GetAbsoluteDirectoryPath(projectDir, "ptvsd");

            if (File.Exists(ptvsdSource) && !Directory.Exists(ptvsdDest))
            {
                Directory.CreateDirectory(ptvsdDest);
                var sourceDir = PathUtils.GetParent(ptvsdSource);
                foreach (var file in PathUtils.EnumerateFiles(sourceDir, pattern: "*.py", fullPaths: false))
                {
                    var destFile = PathUtils.GetAbsoluteFilePath(ptvsdDest, file);
                    if (!Directory.Exists(PathUtils.GetParent(destFile)))
                    {
                        Directory.CreateDirectory(PathUtils.GetParent(destFile));
                    }

                    File.Copy(PathUtils.GetAbsoluteFilePath(sourceDir, file), destFile, true);
                }

                projectItem.ContainingProject.ProjectItems.AddFromDirectory(PathUtils.TrimEndSeparator(ptvsdDest));
            }


            var webRoleSource = PythonToolsInstallPath.TryGetFile("Microsoft.PythonTools.WebRole.dll", GetType().Assembly);

            if (File.Exists(webRoleSource))
            {
                ProjectItem binFolderItem;
                try {
                    binFolderItem = projectItem.ContainingProject.ProjectItems.Item("bin");
                } catch (ArgumentException) {
                    binFolderItem = projectItem.ContainingProject.ProjectItems.AddFolder("bin");
                }

                binFolderItem?.ProjectItems.AddFromFileCopy(webRoleSource);
            }
        }
Esempio n. 7
0
        public void Imported(IModuleContext context)
        {
            if (_scraped)
            {
                return;
            }
            _scraped = true;

            var interp = context as AstPythonInterpreter;
            var fact   = interp?.Factory;

            if (fact == null || !File.Exists(fact.Configuration.InterpreterPath))
            {
                return;
            }

            ModulePath mp = AstPythonInterpreterFactory.FindModule(fact, _filePath);

            if (string.IsNullOrEmpty(mp.FullName))
            {
                return;
            }

            var sm = PythonToolsInstallPath.TryGetFile("scrape_module.py", GetType().Assembly);

            if (!File.Exists(sm))
            {
                return;
            }

            Stream code = null;

            using (var p = ProcessOutput.RunHiddenAndCapture(
                       fact.Configuration.InterpreterPath, "-E", sm, mp.LibraryPath, mp.ModuleName
                       )) {
                p.Wait();
                if (p.ExitCode == 0)
                {
                    var ms = new MemoryStream();
                    code = ms;
                    using (var sw = new StreamWriter(ms, Encoding.UTF8, 4096, true)) {
                        foreach (var line in p.StandardOutputLines)
                        {
                            sw.WriteLine(line);
                        }
                    }
                }
            }

            if (code == null)
            {
                return;
            }

            PythonAst ast;

            code.Seek(0, SeekOrigin.Begin);
            using (var sr = new StreamReader(code, Encoding.UTF8))
                using (var parser = Parser.CreateParser(sr, fact.GetLanguageVersion())) {
                    ast = parser.ParseFile();
                }

            lock (_members) {
                var walker = new AstAnalysisWalker(interp, ast, this, _filePath, _members, false);
                ast.Walk(walker);
            }
        }