예제 #1
0
        private static void ProfileProject(SessionNode session, EnvDTE.Project projectToProfile, bool openReport)
        {
            var project = projectToProfile.AsPythonProject();

            var config = project?.GetLaunchConfigurationOrThrow();

            if (config == null)
            {
                MessageBox.Show("Could not find interpreter for project {0}".FormatUI(projectToProfile.Name), "Python Tools for Visual Studio");
                return;
            }

            if (string.IsNullOrEmpty(config.ScriptName))
            {
                MessageBox.Show("Project has no configured startup file, cannot start profiling.", "Python Tools for Visual Studio");
                return;
            }

            if (string.IsNullOrEmpty(config.WorkingDirectory) || config.WorkingDirectory == ".")
            {
                config.WorkingDirectory = project.ProjectHome;
                if (string.IsNullOrEmpty(config.WorkingDirectory))
                {
                    config.WorkingDirectory = Path.GetDirectoryName(config.ScriptName);
                }
            }

            RunProfiler(session, config, openReport);
        }
예제 #2
0
        private static void ProfileProject(SessionNode session, EnvDTE.Project projectToProfile, bool openReport)
        {
            var project = projectToProfile.AsPythonProject();

            var config = project?.GetLaunchConfigurationOrThrow();

            if (config == null)
            {
                MessageBox.Show(Strings.ProjectInterpreterNotFound.FormatUI(projectToProfile.Name), Strings.ProductTitle);
                return;
            }

            if (string.IsNullOrEmpty(config.ScriptName))
            {
                MessageBox.Show(Strings.NoProjectStartupFile, Strings.ProductTitle);
                return;
            }

            if (string.IsNullOrEmpty(config.WorkingDirectory) || config.WorkingDirectory == ".")
            {
                config.WorkingDirectory = project.ProjectHome;
                if (string.IsNullOrEmpty(config.WorkingDirectory))
                {
                    config.WorkingDirectory = Path.GetDirectoryName(config.ScriptName);
                }
            }

            RunProfiler(session, config, openReport);
        }
예제 #3
0
        internal static void ProfileProject(SessionNode session, EnvDTE.Project projectToProfile, bool openReport)
        {
            var model = (IComponentModel)(session._serviceProvider.GetService(typeof(SComponentModel)));

            var projectHome = PathUtils.GetAbsoluteDirectoryPath(
                Path.GetDirectoryName(projectToProfile.FullName),
                (string)projectToProfile.Properties.Item("ProjectHome").Value
                );

            var args            = (string)projectToProfile.Properties.Item("CommandLineArguments").Value;
            var interpreterPath = (string)projectToProfile.Properties.Item("InterpreterPath").Value;
            var searchPath      = (string)projectToProfile.Properties.Item("SearchPath").Value;
            var project         = projectToProfile.AsPythonProject();

            var interpreter = project != null?project.GetInterpreterFactory() : null;

            if (interpreter == null /*|| interpreter == interpreterService.NoInterpretersValue*/)
            {
                MessageBox.Show(String.Format("Could not find interpreter for project {0}", projectToProfile.Name), "Python Tools for Visual Studio");
                return;
            }

            var arch           = interpreter.Configuration.Architecture;
            var pathEnvVarName = interpreter.Configuration.PathEnvironmentVariable;

            if (String.IsNullOrWhiteSpace(interpreterPath))
            {
                interpreterPath = interpreter.Configuration.InterpreterPath;
            }

            string startupFile = (string)projectToProfile.Properties.Item("StartupFile").Value;

            if (String.IsNullOrEmpty(startupFile))
            {
                MessageBox.Show("Project has no configured startup file, cannot start profiling.", "Python Tools for Visual Studio");
                return;
            }

            string workingDir = projectToProfile.Properties.Item("WorkingDirectory").Value as string;

            if (String.IsNullOrEmpty(workingDir) || workingDir == ".")
            {
                workingDir = projectToProfile.Properties.Item("ProjectHome").Value as string;
                if (String.IsNullOrEmpty(workingDir))
                {
                    workingDir = Path.GetDirectoryName(projectToProfile.FullName);
                }
            }

            var env = new Dictionary <string, string>();

            if (!String.IsNullOrWhiteSpace(pathEnvVarName) && !String.IsNullOrEmpty(searchPath))
            {
                var searchPaths = searchPath.Split(';').ToList();
                var pyService   = (PythonToolsService)session._serviceProvider.GetService(typeof(PythonToolsService));
                if (!pyService.GeneralOptions.ClearGlobalPythonPath)
                {
                    searchPaths.AddRange(Environment.GetEnvironmentVariable(pathEnvVarName).Split(';'));
                }

                env[pathEnvVarName] = string.Join(";", searchPaths
                                                  .Where(PathUtils.IsValidPath)
                                                  .Select(p => PathUtils.GetAbsoluteDirectoryPath(projectHome, p))
                                                  .Where(Directory.Exists)
                                                  .Distinct(StringComparer.OrdinalIgnoreCase)
                                                  );
            }

            var userEnv = projectToProfile.Properties.Item("Environment").Value as string;

            if (userEnv != null)
            {
                foreach (var envVar in userEnv.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var nameValue = envVar.Split(new[] { '=' }, 2);
                    if (nameValue.Length == 2)
                    {
                        env[nameValue[0]] = nameValue[1];
                    }
                }
            }

            RunProfiler(session, interpreterPath, startupFile, args, workingDir, env, openReport, arch);
        }