Example #1
0
 public PythonInstaller(ProgramPathContainer pythonPathContainer, IEnumerable <string> packages, TextWriter writer)
     : this(pythonPathContainer, packages, PythonUtil.CheckInstalled(pythonPathContainer.ProgramVersion), writer)
 {
 }
Example #2
0
        private bool GetPackages()
        {
            ICollection <string> downloadablePackages = new Collection <string>();
            ICollection <string> localPackages        = new Collection <string>();

            AssignPackagesToInstall(ref downloadablePackages, ref localPackages);

            IEnumerable <string> packagePaths = null;

            try
            {
                // download packages
                using (var waitDlg = new LongWaitDlg {
                    ProgressValue = 0
                })
                {
                    waitDlg.PerformWork(this, 500, longWaitBroker => packagePaths = DownloadPackages(longWaitBroker, downloadablePackages));
                }

                // separate packages
                ICollection <string> exePaths    = new Collection <string>();
                ICollection <string> sourcePaths = new Collection <string>();
                foreach (var package in (packagePaths == null) ? localPackages : packagePaths.Concat(localPackages))
                {
                    if (package.EndsWith(".exe")) // Not L10N
                    {
                        exePaths.Add(package);
                    }
                    else
                    {
                        sourcePaths.Add(package);
                    }
                }

                // first install executable packages, if any
                if (exePaths.Count != 0)
                {
                    using (var waitDlg = new LongWaitDlg(null, false)
                    {
                        Message = Resources.PythonInstaller_GetPackages_Installing_Packages
                    })
                    {
                        waitDlg.PerformWork(this, 500, () => InstallExecutablePackages(exePaths));
                    }
                }

                // then install source paths, if any
                if (sourcePaths.Count != 0)
                {
                    // try and find the path to the pip package manager .exe
                    string pipPath = PythonUtil.GetPipPath(_version);

                    // if it can't be found, install it
                    if (pipPath == null || TestingPip)
                    {
                        DialogResult result = MultiButtonMsgDlg.Show(
                            this,
                            Resources.PythonInstaller_InstallPackages_Skyline_uses_the_Python_tool_setuptools_and_the_Python_package_manager_Pip_to_install_packages_from_source__Click_install_to_begin_the_installation_process_,
                            Resources.PythonInstaller_InstallPackages_Install);
                        if (result == DialogResult.OK && GetPip())
                        {
                            pipPath = PythonUtil.GetPipPath(_version);
                            MessageDlg.Show(this, Resources.PythonInstaller_InstallPackages_Pip_installation_complete_);
                        }
                        else
                        {
                            MessageDlg.Show(this, Resources.PythonInstaller_InstallPackages_Python_package_installation_cannot_continue__Canceling_tool_installation_);
                            return(false);
                        }
                    }

                    using (var waitDlg = new LongWaitDlg(null, false)
                    {
                        Message = Resources.PythonInstaller_GetPackages_Installing_Packages
                    })
                    {
                        waitDlg.PerformWork(this, 500, () => InstallSourcePackages(sourcePaths, pipPath));
                    }
                }
                MessageDlg.Show(this, Resources.PythonInstaller_GetPackages_Package_installation_completed_);
                return(true);
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException is ToolExecutionException)
                {
                    MessageDlg.ShowException(this, ex);
                    return(false);
                }
                throw;
            }
        }