private async Task <AddExistingEnvironmentView> AutoDetectAsync(AddExistingEnvironmentView view)
        {
            if (!Directory.Exists(view.PrefixPath))
            {
                // If view.PrefixPath is not valid by this point, we can't find anything
                // else, so abort without changes.
                return(view);
            }

            if (string.IsNullOrEmpty(view.Description))
            {
                view.Description = PathUtils.GetFileOrDirectoryName(view.PrefixPath);
            }

            if (!File.Exists(view.InterpreterPath))
            {
                view.InterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.ConsoleExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }

            if (!File.Exists(view.WindowsInterpreterPath))
            {
                view.WindowsInterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.WindowsExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }

            if (File.Exists(view.InterpreterPath))
            {
                using (var output = ProcessOutput.RunHiddenAndCapture(
                           view.InterpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1])); print(sys.platform)"
                           )) {
                    var exitCode = await output;
                    if (exitCode == 0)
                    {
                        view.VersionName = output.StandardOutputLines.FirstOrDefault() ?? view.VersionName;
                    }
                }

                var arch = CPythonInterpreterFactoryProvider.ArchitectureFromExe(view.InterpreterPath);
                if (arch != InterpreterArchitecture.Unknown)
                {
                    view.ArchitectureName = arch.ToString();
                }

                if (string.IsNullOrEmpty(view.PathEnvironmentVariable))
                {
                    view.PathEnvironmentVariable = "PYTHONPATH";
                }
            }

            return(view);
        }
        private async Task <ConfigurationValues> AutoDetectAsync(ConfigurationValues view)
        {
            if (!Directory.Exists(view.PrefixPath))
            {
                if (File.Exists(view.InterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.InterpreterPath);
                }
                else if (File.Exists(view.WindowsInterpreterPath))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.WindowsInterpreterPath);
                }
                else
                {
                    // Don't have enough information, so abort without changing
                    // any settings.
                    return(view);
                }
                while (Directory.Exists(view.PrefixPath) && !File.Exists(PathUtils.FindFile(view.PrefixPath, "site.py")))
                {
                    view.PrefixPath = Path.GetDirectoryName(view.PrefixPath);
                }
            }

            if (!Directory.Exists(view.PrefixPath))
            {
                // If view.PrefixPath is not valid by this point, we can't find anything
                // else, so abort withou changing any settings.
                return(view);
            }

            if (string.IsNullOrEmpty(view.Description))
            {
                view.Description = PathUtils.GetFileOrDirectoryName(view.PrefixPath);
            }

            if (!File.Exists(view.InterpreterPath))
            {
                view.InterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.ConsoleExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }
            if (!File.Exists(view.WindowsInterpreterPath))
            {
                view.WindowsInterpreterPath = PathUtils.FindFile(
                    view.PrefixPath,
                    CPythonInterpreterFactoryConstants.WindowsExecutable,
                    firstCheck: new[] { "scripts" }
                    );
            }

            if (File.Exists(view.InterpreterPath))
            {
                using (var output = ProcessOutput.RunHiddenAndCapture(
                           view.InterpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
                           )) {
                    var exitCode = await output;
                    if (exitCode == 0)
                    {
                        view.VersionName = output.StandardOutputLines.FirstOrDefault() ?? view.VersionName;
                    }
                }

                var arch = CPythonInterpreterFactoryProvider.ArchitectureFromExe(view.InterpreterPath);
                if (arch != InterpreterArchitecture.Unknown)
                {
                    view.ArchitectureName = arch.ToString();
                }
            }

            return(view);
        }