Esempio n. 1
0
        internal void OpenProject(VisualStudioApp app, string slnName, out PythonProjectNode projectNode, out EnvDTE.Project dteProject) {
            PythonVersion.AssertInstalled();

            dteProject = app.OpenProject("TestData\\Targets\\" + slnName);
            projectNode = dteProject.GetPythonProject();
            var fact = projectNode.InterpreterFactories.Where(x => x.Configuration.Id == PythonVersion.Id).FirstOrDefault();
            Assert.IsNotNull(fact, "Project does not contain expected interpreter");
            projectNode.ActiveInterpreter = fact;
            dteProject.Save();
        }
Esempio n. 2
0
        private void EnvironmentReplWorkingDirectoryTest(
            PythonVisualStudioApp app,
            EnvDTE.Project project,
            TreeNode env,
            string envName
        ) {
            var path1 = Path.Combine(Path.GetDirectoryName(project.FullName), Guid.NewGuid().ToString("N"));
            var path2 = Path.Combine(Path.GetDirectoryName(project.FullName), Guid.NewGuid().ToString("N"));
            Directory.CreateDirectory(path1);
            Directory.CreateDirectory(path2);

            env.Select();
            app.Dte.ExecuteCommand("Python.Interactive");

            var window = app.GetInteractiveWindow(string.Format("{0} Interactive", envName));
            Assert.IsNotNull(window, string.Format("Failed to find '{0} Interactive'", envName));
            try {
                app.ServiceProvider.GetUIThread().Invoke(() => project.GetPythonProject().SetProjectProperty("WorkingDirectory", path1));

                window.Reset();
                window.ReplWindow.Evaluator.ExecuteText("import os; os.getcwd()").Wait();
                window.WaitForTextEnd(
                    string.Format("'{0}'", path1.Replace("\\", "\\\\")),
                    ">>>"
                );

                app.ServiceProvider.GetUIThread().Invoke(() => project.GetPythonProject().SetProjectProperty("WorkingDirectory", path2));

                window.Reset();
                window.ReplWindow.Evaluator.ExecuteText("import os; os.getcwd()").Wait();
                window.WaitForTextEnd(
                    string.Format("'{0}'", path2.Replace("\\", "\\\\")),
                    ">>>"
                );
            } finally {
                window.Close();
            }
        }
Esempio n. 3
0
        public static SD.Process LaunchFileFromProject(VisualStudioApp app, EnvDTE.Project project, string filename, string interpreterArgs, string programArgs) {
            var item = project.ProjectItems.Item(filename);
            var window = item.Open();
            window.Activate();
            var doc = item.Document;
            var docFN = doc.FullName;
            string fullFilename = Path.GetFullPath(docFN);

            string cmdlineArgs = String.Format("{0} \"{1}\" {2}", interpreterArgs, fullFilename, programArgs);

            var uiThread = app.GetService<UIThreadBase>();
            var projectInterpreter = uiThread.Invoke(() => project.GetPythonProject().GetLaunchConfigurationOrThrow().GetInterpreterPath());

            var psi = new SD.ProcessStartInfo(projectInterpreter, cmdlineArgs);
            psi.RedirectStandardError = true;
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute = false;
            var p = SD.Process.Start(psi);
            p.EnableRaisingEvents = true;
            string output = "";
            p.OutputDataReceived += (sender, args) => {
                output += args.Data;
            };
            p.ErrorDataReceived += (sender, args) => {
                output += args.Data;
            };
            p.BeginErrorReadLine();
            p.BeginOutputReadLine();
            p.Exited += (sender, args) => {
                SD.Debug.WriteLine("Process Id ({0}) exited with ExitCode: {1}", p.Id, p.ExitCode);
                SD.Debug.WriteLine(String.Format("Output: {0}", output));
            };

            Assert.IsNotNull(p, "Failure to start process, {0} {1} ", projectInterpreter, cmdlineArgs);
            return p;
        }