Exemplo n.º 1
0
 public static PythonPackage FromFastReference(string fastreference, Request request)
 {
     if (fastreference.StartsWith("distinfo:"))
     {
         string[]      parts   = fastreference.Substring(9).Split(new char[] { '|' }, 2);
         PythonInstall install = PythonInstall.FromPath(parts[0], request);
         return(FromDistInfo(parts[1], install, request));
     }
     else if (fastreference.StartsWith("egginfo:"))
     {
         string[]      parts   = fastreference.Substring(8).Split(new char[] { '|' }, 2);
         PythonInstall install = PythonInstall.FromPath(parts[0], request);
         return(FromEggInfo(parts[1], install, request));
     }
     else if (fastreference.StartsWith("pypi:"))
     {
         string[] parts     = fastreference.Substring(5).Split(new char[] { '#' }, 3);
         string   source    = parts[0];
         string   sourceurl = parts[1];
         parts = parts[2].Split(new char[] { '/' });
         string name    = parts[0];
         string version = parts[1];
         return(PyPI.GetPackage(new Tuple <string, string>(source, sourceurl), name, version, request));
     }
     else if (fastreference.StartsWith("archive:"))
     {
         string[] parts        = fastreference.Substring(8).Split(new char[] { '/' }, 3);
         string   name         = parts[0];
         string   version      = parts[1];
         string   archive_path = parts[2];
         foreach (var package in PackagesFromFile(archive_path, request))
         {
             if (package.name == name && package.version.Compare(version) == 0)
             {
                 return(package);
             }
         }
     }
     else if (fastreference.StartsWith("pythonweb:"))
     {
         return(PythonWebsite.PackageFromWebResource(fastreference.Substring(10), request));
     }
     else if (fastreference.StartsWith("installedpython:"))
     {
         return(PythonInstall.FromPath(fastreference.Substring(16), request));
     }
     return(null);
 }
Exemplo n.º 2
0
        public bool Install(PythonInstall install, Request request)
        {
            DistRequirement failed_dependency;

            request.Debug("Installing {0} {1}", name, version.ToString());
            if (incomplete_metadata)
            {
                return(PyPI.GetPackage(new Tuple <string, string>(source, sourceurl), name, version.raw_version_string, request).Install(install, request));
            }
            if (!CheckDependencies(install, out failed_dependency, request))
            {
                var deps = SimpleResolveDependencies(install, out failed_dependency, request);
                if (deps == null)
                {
                    request.Error(ErrorCategory.NotInstalled, name, string.Format("Dependency '{0}' not found, unable to resolve automatically.", failed_dependency.raw_string));
                    return(false);
                }

                if (!InstallDependencies(install, deps, request))
                {
                    return(false);
                }
            }
            if (is_wheel)
            {
                if (install.InstallWheel(archive_path, request) != 0)
                {
                    request.Error(ErrorCategory.NotSpecified, name, "wheel install failed");
                    return(false);
                }
                foreach (var package in install.FindInstalledPackages(name, null, request))
                {
                    if (package.version.raw_version_string != version.raw_version_string)
                    {
                        package.Uninstall(request);
                    }
                }
                return(true);
            }
            else if (source != null)
            {
                PackageDownload?fallback_download = null;
                foreach (var download in downloads)
                {
                    bool install_specific;
                    if (CanInstall(install, download, out install_specific, request))
                    {
                        if (install_specific)
                        {
                            return(Install(install, download, request));
                        }
                        else if (fallback_download == null)
                        {
                            fallback_download = download;
                        }
                    }
                }
                if (fallback_download != null)
                {
                    return(Install(install, fallback_download.Value, request));
                }
                request.Error(ErrorCategory.NotImplemented, name, "installing not implemented for this package type");
                return(false);
            }
            else
            {
                request.Error(ErrorCategory.NotImplemented, name, "installing not implemented for this package type");
                return(false);
            }
        }
Exemplo n.º 3
0
        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);
        }