Esempio n. 1
0
        public TreeNode CreateProjectCondaEnvironment(EnvDTE.Project project, string packageNames, string envFile, string expectedEnvFile, out string envName, out string envPath)
        {
            var environmentsNode = OpenSolutionExplorer().FindChildOfProject(project, Strings.Environments);

            environmentsNode.Select();

            envName = ApplyCreateCondaEnvironmentDialog(packageNames, envFile, expectedEnvFile);

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

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

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

            envPath = config.GetPrefixPath();

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

            try {
                return(OpenSolutionExplorer().WaitForChildOfProject(project, Strings.Environments, envLabel));
            } finally {
                var text = GetOutputWindowText("General");
                if (!string.IsNullOrEmpty(text))
                {
                    Console.WriteLine("** Output Window text");
                    Console.WriteLine(text);
                    Console.WriteLine("***");
                    Console.WriteLine();
                }
            }
        }
Esempio n. 2
0
        public void CreateWorkspaceCondaEnvironment(string packageNames, string envFile, string expectedEnvFile, out string envName, out string envPath, out string envDescription)
        {
            envName = ApplyCreateCondaEnvironmentDialog(packageNames, envFile, expectedEnvFile);

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

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

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

            Console.WriteLine("Expecting environment: {0}", envDescription);
        }
Esempio n. 3
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();
                }
            }
        }
        private async Task <IPythonInterpreterFactory> CreateFactoryAsync(CondaUI ui, ITaskHandler taskHandler, CancellationToken ct)
        {
            // Force discovery, don't respect the ignore nofitication ref count,
            // which won't go back to 0 if multiple conda environments are being
            // created around the same time. We need the discovery in order to find
            // the new factory.
            using (_factoryProvider?.SuppressDiscoverFactories(forceDiscoveryOnDispose: true)) {
                taskHandler?.Progress.Report(new TaskProgressData()
                {
                    CanBeCanceled   = false,
                    ProgressText    = Strings.CondaStatusCenterCreateProgressCreating,
                    PercentComplete = null,
                });

                bool failed     = true;
                bool useEnvFile = !string.IsNullOrEmpty(_envFilePath);

                try {
                    if (useEnvFile)
                    {
                        if (!await _condaMgr.CreateFromEnvironmentFileAsync(
                                _envNameOrPath,
                                _envFilePath,
                                ui,
                                ct
                                ))
                        {
                            throw new ApplicationException(Strings.CondaStatusCenterCreateFailure);
                        }
                    }
                    else
                    {
                        if (!await _condaMgr.CreateAsync(
                                _envNameOrPath,
                                _packages.ToArray(),
                                ui,
                                ct
                                ))
                        {
                            throw new ApplicationException(Strings.CondaStatusCenterCreateFailure);
                        }
                    }

                    failed = false;
                } finally {
                    _logger?.LogEvent(PythonLogEvent.CreateCondaEnv, new CreateCondaEnvInfo()
                    {
                        Failed = failed,
                        FromEnvironmentFile    = useEnvFile,
                        SetAsDefault           = _setAsDefault,
                        SetAsCurrent           = _setAsCurrent,
                        OpenEnvironmentsWindow = _viewInEnvWindow,
                    });
                }
            }

            var expectedId = CondaEnvironmentFactoryConstants.GetInterpreterId(
                CondaEnvironmentFactoryProvider.EnvironmentCompanyName,
                _actualName
                );

            // This will return null if the environment that was created does
            // not contain a python interpreter. Common case for this is
            // when the package list the user has entered is empty string.
            var factory = _factoryProvider?.GetInterpreterFactory(expectedId);

            return(factory);
        }