public TreeNode AddExistingVirtualEnvironment(EnvDTE.Project project, string envPath, out string envName)
        {
            var environmentsNode = OpenSolutionExplorer().FindChildOfProject(project, Strings.Environments);

            environmentsNode.Select();

            using (var createVenv = AutomationDialog.FromDte(this, "Python.AddVirtualEnvironment")) {
                new TextBox(createVenv.FindByAutomationId("VirtualEnvPath")).SetValue(envPath);
                var baseInterp = new ComboBox(createVenv.FindByAutomationId("BaseInterpreter")).GetSelectedItemName();

                envName = string.Format("{0} ({1})", Path.GetFileName(envPath), baseInterp);

                Console.WriteLine("Expecting environment named: {0}", envName);

                createVenv.ClickButtonAndClose("Add", nameIsAutomationId: true);
            }

            return(OpenSolutionExplorer().WaitForChildOfProject(project, Strings.Environments, envName));
        }
Beispiel #2
0
        public void DeferredSaveWithDot()
        {
            string fullname;

            using (var app = new PythonVisualStudioApp()) {
                // http://pytools.codeplex.com/workitem/623
                // enable deferred saving on projects
                var props     = app.Dte.get_Properties("Environment", "ProjectsAndSolution");
                var prevValue = props.Item("SaveNewProjects").Value;
                props.Item("SaveNewProjects").Value = false;
                app.OnDispose(() => { props.Item("SaveNewProjects").Value = prevValue; });


                using (var newProjDialog = app.FileNewProject()) {
                    newProjDialog.FocusLanguageNode();

                    var consoleApp = newProjDialog.ProjectTypes.FindItem("Python Application");
                    consoleApp.Select();
                    newProjDialog.ProjectName = "Fob.Oar";
                    newProjDialog.OK();
                }

                // wait for new solution to load...
                for (int i = 0; i < 100 && app.Dte.Solution.Projects.Count == 0; i++)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                using (var saveDialog = AutomationDialog.FromDte(app, "File.SaveAll")) {
                    saveDialog.ClickButtonAndClose("Save");
                }

                fullname = app.Dte.Solution.FullName;
            }

            try {
                // Delete the created directory after the solution has been
                // closed.
                Directory.Delete(Path.GetDirectoryName(fullname), true);
            } catch {
            }
        }
Beispiel #3
0
        public void InstallUninstallPackage()
        {
            using (var app = new PythonVisualStudioApp())
                using (var dis = Init(app)) {
                    var project = CreateTemporaryProject(app);

                    string envName;
                    var    env = app.CreateVirtualEnvironment(project, out envName);
                    env.Select();

                    using (var installPackage = AutomationDialog.FromDte(app, "Python.InstallPackage")) {
                        var packageName = new TextBox(installPackage.FindByAutomationId("Name"));
                        packageName.SetValue("azure==0.6.2");
                        installPackage.ClickButtonAndClose("OK", nameIsAutomationId: true);
                    }

                    var azure = app.SolutionExplorerTreeView.WaitForChildOfProject(
                        project,
                        SR.GetString(SR.Environments),
                        envName,
                        "azure (0.6.2)"
                        );

                    azure.Select();

                    using (var confirmation = AutomationDialog.FromDte(app, "Edit.Delete")) {
                        confirmation.OK();
                    }

                    app.SolutionExplorerTreeView.WaitForChildOfProjectRemoved(
                        project,
                        SR.GetString(SR.Environments),
                        envName,
                        "azure (0.6.2)"
                        );
                }
        }
Beispiel #4
0
        public TreeNode CreateVirtualEnvironment(EnvDTE.Project project, out string envName, out string envPath)
        {
            var environmentsNode = OpenSolutionExplorer().FindChildOfProject(project, Strings.Environments);

            environmentsNode.Select();

            using (var pss = new ProcessScope("python")) {
                using (var createVenv = AutomationDialog.FromDte(this, "Python.AddVirtualEnvironment")) {
                    envPath = new TextBox(createVenv.FindByAutomationId("VirtualEnvPath")).GetValue();
                    var baseInterp = new ComboBox(createVenv.FindByAutomationId("BaseInterpreter")).GetSelectedItemName();

                    var baseConfig = ComponentModel.GetService <IInterpreterRegistryService>().Configurations
                                     .FirstOrDefault(c => c.FullDescription == baseInterp);

                    if (baseConfig == null)
                    {
                        envName = "{0} ({1})".FormatUI(envPath, baseInterp);
                    }
                    else
                    {
                        envName = "{0} {1} {2} ({3})".FormatUI(
                            envPath,
                            baseConfig.Architecture == System.Reflection.ProcessorArchitecture.Amd64 ? "64-bit" : "32-bit",
                            baseConfig.Version,
                            baseInterp
                            );
                    }

                    Console.WriteLine("Expecting environment named: {0}", envName);

                    // Force a wait for the view to be updated.
                    var wnd = (DialogWindowVersioningWorkaround)HwndSource.FromHwnd(
                        new IntPtr(createVenv.Element.Current.NativeWindowHandle)
                        ).RootVisual;
                    wnd.Dispatcher.Invoke(() => {
                        var view = (AddVirtualEnvironmentView)wnd.DataContext;
                        return(view.UpdateInterpreter(view.BaseInterpreter));
                    }).Wait();

                    createVenv.ClickButtonByAutomationId("Create");
                    createVenv.ClickButtonAndClose("Close", nameIsAutomationId: true);
                }

                var nowRunning = pss.WaitForNewProcess(TimeSpan.FromMinutes(1));
                if (nowRunning == null || !nowRunning.Any())
                {
                    Assert.Fail("Failed to see python process start to create virtualenv");
                }
                foreach (var p in nowRunning)
                {
                    if (p.HasExited)
                    {
                        continue;
                    }
                    try {
                        p.WaitForExit(30000);
                    } catch (Win32Exception ex) {
                        Console.WriteLine("Error waiting for process ID {0}\n{1}", p.Id, ex);
                    }
                }
            }

            try {
                return(OpenSolutionExplorer().WaitForChildOfProject(project, Strings.Environments, envName));
            } finally {
                var text = GetOutputWindowText("General");
                if (!string.IsNullOrEmpty(text))
                {
                    Console.WriteLine("** Output Window text");
                    Console.WriteLine(text);
                    Console.WriteLine("***");
                    Console.WriteLine();
                }
            }
        }
Beispiel #5
0
        public TreeNode CreateVirtualEnvironment(EnvDTE.Project project, out string envName, out string envPath)
        {
            var environmentsNode = OpenSolutionExplorer().FindChildOfProject(
                project,
                SR.GetString(SR.Environments)
                );

            environmentsNode.Select();

            var alreadyRunning = new HashSet <int>(Process.GetProcessesByName("python").Select(p => p.Id));

            using (var createVenv = AutomationDialog.FromDte(this, "Python.AddVirtualEnvironment")) {
                envPath = new TextBox(createVenv.FindByAutomationId("VirtualEnvPath")).GetValue();
                var baseInterp = new ComboBox(createVenv.FindByAutomationId("BaseInterpreter")).GetSelectedItemName();

                envName = string.Format("{0} ({1})", envPath, baseInterp);

                Console.WriteLine("Expecting environment named: {0}", envName);

                // Force a wait for the view to be updated.
                var wnd = (DialogWindowVersioningWorkaround)HwndSource.FromHwnd(
                    new IntPtr(createVenv.Element.Current.NativeWindowHandle)
                    ).RootVisual;
                wnd.Dispatcher.Invoke(() => {
                    var view = (AddVirtualEnvironmentView)wnd.DataContext;
                    return(view.UpdateInterpreter(view.BaseInterpreter));
                }).Wait();

                createVenv.ClickButtonByAutomationId("Create");
                createVenv.ClickButtonAndClose("Close", nameIsAutomationId: true);
            }

            List <Process> nowRunning = null;

            for (int retries = 100; retries > 0 && (nowRunning == null || !nowRunning.Any()); --retries)
            {
                System.Threading.Thread.Sleep(100);
                nowRunning = Process.GetProcessesByName("python").Where(p => !alreadyRunning.Contains(p.Id)).ToList();
            }
            if (nowRunning == null || !nowRunning.Any())
            {
                Assert.Fail("Failed to see python process start to create virtualenv");
            }
            foreach (var p in nowRunning)
            {
                if (p.HasExited)
                {
                    continue;
                }
                try {
                    p.WaitForExit(30000);
                } catch (Win32Exception ex) {
                    Console.WriteLine("Error waiting for process ID {0}\n{1}", p.Id, ex);
                }
            }

            return(OpenSolutionExplorer().WaitForChildOfProject(
                       project,
                       SR.GetString(SR.Environments),
                       envName
                       ));
        }