Exemple #1
0
    def search_for(
        self,
        dependency: (Dependency
                     | VCSDependency
                     | FileDependency
                     | DirectoryDependency
                     | URLDependency),
    ) -> list[DependencyPackage]:
        """
        Search for the specifications that match the given dependency.

        The specifications in the returned list will be considered in reverse
        order, so the latest version ought to be last.
        """
        if dependency.is_root:
            return PackageCollection(dependency, [self._package])

        for constraint in self._search_for:
            if (constraint.is_same_package_as(dependency)
                    and constraint.constraint.intersect(
                        dependency.constraint) == dependency.constraint):
                packages = [
                    p for p in self._search_for[constraint]
                    if dependency.constraint.allows(p.version)
                ]

                packages.sort(
                    key=lambda p: (
                        not p.is_prerelease() and not dependency.
                        allows_prereleases(),
                        p.version,
                    ),
                    reverse=True,
                )

                return PackageCollection(dependency, packages)

        if dependency.is_vcs():
            packages = self.search_for_vcs(dependency)
        elif dependency.is_file():
            packages = self.search_for_file(dependency)
        elif dependency.is_directory():
            packages = self.search_for_directory(dependency)
        elif dependency.is_url():
            packages = self.search_for_url(dependency)
        else:
            packages = self._pool.find_packages(dependency)

            packages.sort(
                key=lambda p: (
                    not p.is_prerelease() and not dependency.
                    allows_prereleases(),
                    p.version,
                ),
                reverse=True,
            )

        self._search_for[dependency] = packages

        return PackageCollection(dependency, packages)
Exemple #2
0
    def search_for(self, dependency: Dependency) -> list[DependencyPackage]:
        """
        Search for the specifications that match the given dependency.

        The specifications in the returned list will be considered in reverse
        order, so the latest version ought to be last.
        """
        if dependency.is_root:
            return PackageCollection(dependency, [self._package])

        if dependency.is_direct_origin():
            packages = [self.search_for_direct_origin_dependency(dependency)]

        else:
            packages = self._pool.find_packages(dependency)

            packages.sort(
                key=lambda p: (
                    not p.is_prerelease() and not dependency.
                    allows_prereleases(),
                    p.version,
                ),
                reverse=True,
            )

        if not packages:
            packages = self.search_for_installed_packages(dependency)

        return PackageCollection(dependency, packages)
Exemple #3
0
    def search_for(
        self,
        dependency: (Dependency
                     | VCSDependency
                     | FileDependency
                     | DirectoryDependency
                     | URLDependency),
    ) -> list[DependencyPackage]:
        """
        Search for the specifications that match the given dependency.

        The specifications in the returned list will be considered in reverse
        order, so the latest version ought to be last.
        """
        if dependency.is_root:
            return PackageCollection(dependency, [self._package])

        if dependency.is_vcs():
            dependency = cast(VCSDependency, dependency)
            packages = self.search_for_vcs(dependency)
        elif dependency.is_file():
            dependency = cast(FileDependency, dependency)
            packages = self.search_for_file(dependency)
        elif dependency.is_directory():
            dependency = cast(DirectoryDependency, dependency)
            packages = self.search_for_directory(dependency)
        elif dependency.is_url():
            dependency = cast(URLDependency, dependency)
            packages = self.search_for_url(dependency)
        else:
            packages = self._pool.find_packages(dependency)

            packages.sort(
                key=lambda p: (
                    not p.is_prerelease() and not dependency.
                    allows_prereleases(),
                    p.version,
                ),
                reverse=True,
            )

        if not packages:
            packages = self.search_for_installed_packages(dependency)

        return PackageCollection(dependency, packages)
Exemple #4
0
    def search_for(self, dependency):  # type: (Dependency) -> List[Package]
        """
        Search for the specifications that match the given dependency.

        The specifications in the returned list will be considered in reverse
        order, so the latest version ought to be last.
        """
        if dependency.is_root:
            return PackageCollection(dependency, [self._package])

        # 所以_search_for就是一個暫存candidate的概念
        for constraint in self._search_for.keys():
            if (constraint.name == dependency.name
                    and constraint.constraint.intersect(
                        dependency.constraint) == dependency.constraint):
                packages = [
                    p for p in self._search_for[constraint]
                    # constraint.allows 檢查 candidate 是否符合 constraint
                    if dependency.constraint.allows(p.version)
                ]

                packages.sort(
                    key=lambda p: (
                        not p.is_prerelease() and not dependency.
                        allows_prereleases(),
                        p.version,
                    ),
                    reverse=True,
                )

                return PackageCollection(dependency, packages)

        if dependency.is_vcs():
            packages = self.search_for_vcs(dependency)
        elif dependency.is_file():
            packages = self.search_for_file(dependency)
        elif dependency.is_directory():
            packages = self.search_for_directory(dependency)
        elif dependency.is_url():
            packages = self.search_for_url(dependency)
        else:
            constraint = dependency.constraint

            packages = self._pool.find_packages(
                dependency.name,
                constraint,
                extras=dependency.extras,
                allow_prereleases=dependency.allows_prereleases(),
                repository=dependency.source_name,
            )

            packages.sort(
                key=lambda p: (
                    not p.is_prerelease() and not dependency.
                    allows_prereleases(),
                    p.version,
                ),
                reverse=True,
            )

        self._search_for[dependency] = packages

        return PackageCollection(dependency, packages)