Пример #1
0
    def get_provider(
        self,
        strategy: str = "all",
        tracked_names: Iterable[str] | None = None,
        for_install: bool = False,
    ) -> BaseProvider:
        """Build a provider class for resolver.

        :param strategy: the resolve strategy
        :param tracked_names: the names of packages that needs to update
        :param for_install: if the provider is for install
        :returns: The provider object
        """

        from pdm.resolver.providers import (
            BaseProvider,
            EagerUpdateProvider,
            ReusePinProvider,
        )

        repository = self.get_repository(cls=self.core.repository_class)
        allow_prereleases = self.allow_prereleases
        overrides = {
            normalize_name(k): v
            for k, v in self.tool_settings.get("overrides", {}).items()
        }
        if strategy != "all" and not self.is_lockfile_compatible():
            self.core.ui.echo(
                "Updating the whole lock file as it is not compatible with PDM",
                fg="yellow",
                err=True,
            )
            strategy = "all"
        if not for_install and strategy == "all":
            return BaseProvider(repository, allow_prereleases, overrides)

        locked_repository = self.locked_repository
        if for_install:
            return BaseProvider(locked_repository, allow_prereleases, overrides)
        provider_class = (
            ReusePinProvider if strategy == "reuse" else EagerUpdateProvider
        )
        return provider_class(
            locked_repository.all_candidates,
            tracked_names or (),
            repository,
            allow_prereleases,
            overrides,
        )
Пример #2
0
    def get_provider(
        self,
        strategy: str = "all",
        tracked_names: Optional[Iterable[str]] = None,
    ) -> BaseProvider:
        """Build a provider class for resolver.

        :param strategy: the resolve strategy
        :param tracked_names: the names of packages that needs to update
        :returns: The provider object
        """
        from pdm.resolver.providers import (
            BaseProvider,
            ReusePinProvider,
            EagerUpdateProvider,
        )

        repository = self.get_repository(cls=self.core.repository_class)
        allow_prereleases = self.allow_prereleases
        requires_python = self.environment.python_requires
        if strategy == "all":
            provider = BaseProvider(repository, requires_python,
                                    allow_prereleases)
        else:
            provider_class = (ReusePinProvider
                              if strategy == "reuse" else EagerUpdateProvider)
            preferred_pins = self.get_locked_candidates("__all__")
            provider = provider_class(
                preferred_pins,
                tracked_names or (),
                repository,
                requires_python,
                allow_prereleases,
            )
        return provider
Пример #3
0
def resolve_requirements(
    repository,
    lines,
    requires_python="",
    allow_prereleases=None,
    strategy="all",
    preferred_pins=None,
    tracked_names=None,
):
    requirements = []
    for line in lines:
        if line.startswith("-e "):
            requirements.append(parse_requirement(line[3:], True))
        else:
            requirements.append(parse_requirement(line))
    requires_python = PySpecSet(requires_python)
    if not preferred_pins:
        provider = BaseProvider(repository, requires_python, allow_prereleases)
    else:
        provider_class = (ReusePinProvider
                          if strategy == "reuse" else EagerUpdateProvider)
        provider = provider_class(
            preferred_pins,
            tracked_names or (),
            repository,
            requires_python,
            allow_prereleases,
        )
    ui = termui.UI()
    with ui.open_spinner("Resolving dependencies") as spin, ui.logging("lock"):
        reporter = SpinnerReporter(spin, requirements)
        resolver = Resolver(provider, reporter)
        mapping, *_ = resolve(resolver, requirements, requires_python)
        return mapping
Пример #4
0
 def from_requirement(cls, provider: BaseProvider, requirement: Requirement,
                      parent: Candidate) -> "Criterion":
     """Build an instance from a requirement.
     """
     candidates = provider.find_matches(requirement)
     if not candidates:
         raise NoVersionsAvailable(requirement, parent)
     return cls(
         candidates=candidates,
         information=[RequirementInformation(requirement, parent)],
     )
Пример #5
0
    def get_provider(
        self,
        strategy: str = "all",
        tracked_names: Optional[Iterable[str]] = None,
        for_install: bool = False,
    ) -> BaseProvider:
        """Build a provider class for resolver.

        :param strategy: the resolve strategy
        :param tracked_names: the names of packages that needs to update
        :param for_install: if the provider is for install
        :returns: The provider object
        """

        from pdm.resolver.providers import (
            BaseProvider,
            EagerUpdateProvider,
            ReusePinProvider,
        )

        repository = self.get_repository(cls=self.core.repository_class)
        requires_python = self.environment.python_requires
        allow_prereleases = self.allow_prereleases
        if not for_install and strategy == "all":
            return BaseProvider(repository, requires_python, allow_prereleases)

        locked_repository = self.locked_repository
        if for_install:
            return BaseProvider(locked_repository, requires_python,
                                allow_prereleases)
        provider_class = (ReusePinProvider
                          if strategy == "reuse" else EagerUpdateProvider)
        return provider_class(
            locked_repository.all_candidates,
            tracked_names or (),
            repository,
            requires_python,
            allow_prereleases,
        )
Пример #6
0
 def merged_with(self, provider: BaseProvider, requirement: Requirement,
                 parent: Candidate) -> "Criterion":
     """Build a new instance from this and a new requirement.
     """
     infos = list(self.information)
     infos.append(RequirementInformation(requirement, parent))
     candidates = [
         c for c in self.candidates
         if provider.is_satisfied_by(requirement, c)
     ]
     if not candidates:
         raise RequirementsConflicted([info.requirement for info in infos])
     return type(self)(candidates, infos)