Esempio n. 1
0
        private string ApplyCreateCondaEnvironmentDialog(string packageNames, string envFile, string expectedEnvFile)
        {
            if (packageNames == null && envFile == null)
            {
                throw new ArgumentException("Must set either package names or environment file");
            }

            string envName;
            var    dlg = AddCondaEnvironmentDialogWrapper.FromDte(this);

            try {
                Assert.AreNotEqual(string.Empty, dlg.EnvName);

                envName     = "test" + Guid.NewGuid().ToString().Replace("-", "");
                dlg.EnvName = envName;

                if (packageNames != null)
                {
                    dlg.SetPackagesMode();
                    dlg.Packages = packageNames;
                    dlg.WaitForPreviewPackage("python", TimeSpan.FromMinutes(2));
                }
                else if (envFile != null)
                {
                    if (expectedEnvFile == string.Empty)
                    {
                        Assert.AreEqual(string.Empty, dlg.EnvFile);
                    }
                    else if (expectedEnvFile != null)
                    {
                        Assert.IsTrue(
                            PathUtils.IsSamePath(dlg.EnvFile, expectedEnvFile),
                            string.Format("Env file doesn't match.\nExpected: {0}\nActual: {1}", dlg.EnvFile, expectedEnvFile)
                            );
                    }
                    dlg.SetEnvFileMode();
                    dlg.EnvFile = envFile;
                }

                Console.WriteLine("Creating conda env");
                Console.WriteLine("  Name: {0}", envName);

                dlg.ClickAdd();
            } catch (Exception) {
                dlg.CloseWindow();
                throw;
            }

            return(envName);
        }
Esempio n. 2
0
        public TreeNode CreateCondaEnvironment(EnvDTE.Project project, string packageNames, string envFile, string expectedEnvFile, out string envName, out string envPath)
        {
            if (packageNames == null && envFile == null)
            {
                throw new ArgumentException("Must set either package names or environment file");
            }

            var environmentsNode = OpenSolutionExplorer().FindChildOfProject(project, Strings.Environments);

            environmentsNode.Select();

            var dlg = AddCondaEnvironmentDialogWrapper.FromDte(this);

            try {
                Assert.AreNotEqual(string.Empty, dlg.EnvName);

                envName     = "test" + Guid.NewGuid().ToString().Replace("-", "");
                dlg.EnvName = envName;

                if (packageNames != null)
                {
                    dlg.SetPackagesMode();
                    dlg.Packages = packageNames;
                    dlg.WaitForPreviewPackage("python", TimeSpan.FromMinutes(2));
                }
                else if (envFile != null)
                {
                    if (expectedEnvFile == string.Empty)
                    {
                        Assert.AreEqual(string.Empty, dlg.EnvFile);
                    }
                    else if (expectedEnvFile != null)
                    {
                        Assert.IsTrue(PathUtils.IsSamePath(dlg.EnvFile, expectedEnvFile));
                    }
                    dlg.SetEnvFileMode();
                    dlg.EnvFile = envFile;
                }

                dlg.ClickAdd();
            } catch (Exception) {
                dlg.CloseWindow();
                throw;
            }

            var id     = CondaEnvironmentFactoryConstants.GetInterpreterId(CondaEnvironmentFactoryProvider.EnvironmentCompanyName, envName);
            var config = WaitForEnvironment(id, TimeSpan.FromMinutes(3));

            Assert.IsNotNull(config, "Could not find intepreter configuration");

            envName = string.Format("{0} ({1}, {2})", envName, config.Version, config.Architecture);
            envPath = config.PrefixPath;

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

            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();
                }
            }
        }