public bool InstallPip(Request request)
 {
     foreach (var package in FindInstalledPackages("pip", null, request))
     {
         if (package.version.Compare("7.1.2") >= 0)
         {
             return(true);
         }
     }
     foreach (var package in PyPI.ExactSearch("pip", request))
     {
         return(package.Install(this, request));
     }
     request.Error(ErrorCategory.ObjectNotFound, "pip", "Can't find download for pip");
     return(false);
 }
        private Dictionary <string, PythonPackage> SimpleResolveDependencies(PythonInstall install, out DistRequirement failed_dependency, Request request)
        {
            Dictionary <string, PythonPackage> result     = new Dictionary <string, PythonPackage>();
            Queue <DistRequirement>            to_resolve = new Queue <DistRequirement>();
            var  installed_packages = new Dictionary <string, PythonPackage>();
            bool need_recheck       = true; // True if we're [up|down]grading a package, and therefore may need to recheck deps

            foreach (var package in install.FindInstalledPackages(null, null, request))
            {
                installed_packages[package.name] = package;
            }

            while (need_recheck)
            {
                need_recheck = false;

                to_resolve.Clear();
                foreach (var dep in requires_dist)
                {
                    request.Debug("Adding dependency {0}", dep.raw_string);
                    to_resolve.Enqueue(dep);
                }

                result.Clear();

                while (to_resolve.Count != 0)
                {
                    var           dep = to_resolve.Dequeue();
                    PythonPackage package;

                    request.Debug("Examining dependency {0}", dep.raw_string);

                    if (dep.marker != null && !dep.marker.Eval(install))
                    {
                        request.Debug("Does not apply to current Python environment");
                        continue;
                    }

                    if (result.TryGetValue(NormalizeName(dep.name), out package))
                    {
                        if (!package.SatisfiesDependency(install, dep, request))
                        {
                            failed_dependency = dep;
                            return(null);
                        }
                        request.Debug("Satisfied by package to install {0} {1}", package.name, package.version.ToString());
                    }
                    else
                    {
                        if (installed_packages.TryGetValue(NormalizeName(dep.name), out package))
                        {
                            if (package.SatisfiesDependency(install, dep, request))
                            {
                                request.Debug("Satisfied by installed package {0} {1}", package.name, package.version.ToString());
                                continue;
                            }
                            else
                            {
                                request.Debug("Not satisfied by installed package {0} {1}", package.name, package.version.ToString());
                                need_recheck = true;
                            }
                        }

                        // find newest version of package that satisfies dependency

                        package = null;
                        foreach (var candidate_package in PyPI.ExactSearch(dep.name, request))
                        {
                            request.Debug("Examining {0} {1}", candidate_package.name, candidate_package.version.ToString());
                            if (candidate_package.SatisfiesDependency(install, dep, request))
                            {
                                package = candidate_package;
                                break;
                            }
                        }

                        if (package == null)
                        {
                            request.Debug("Cannot satisfy dependency");
                            failed_dependency = dep;
                            return(null);
                        }

                        request.Debug("Selecting {0} {1}", package.name, package.version.ToString());

                        // need to do another request to find dependencies
                        if (package.incomplete_metadata)
                        {
                            package = PyPI.GetPackage(new Tuple <string, string>(package.source, package.sourceurl),
                                                      package.name, package.version.raw_version_string, request);
                        }

                        // add its dependencies to queue
                        foreach (var dep2 in package.requires_dist)
                        {
                            request.Debug("Adding dependency {0}", dep2.raw_string);
                            to_resolve.Enqueue(dep2);
                        }

                        result[NormalizeName(package.name)] = package;
                    }
                }
            }

            failed_dependency = default(DistRequirement);
            return(result);
        }