Example #1
0
    def search(self, criteria: Dict[str, List[str]],
               query_type: str) -> List[Package]:
        """
        Perform a search from pip

        Parameters
        ----------
        criteria : dict
            Dictionary containing the search criteria. Pip sends search criteria
            for "name" and "summary" (typically, both of these lists have the
            same search values).

            Example::

                {
                    "name": ["value1", "value2", ..., "valueN"],
                    "summary": ["value1", "value2", ..., "valueN"]
                }

        query_type : str
            Type of query to perform. By default, pip sends "or".


        """
        name_queries = criteria.get("name", [])
        summary_queries = criteria.get("summary", [])
        packages = []

        # Create matchers for the queries
        match_name = create_matcher(name_queries, query_type)
        match_summary = create_matcher(summary_queries, query_type)

        for key in self.distinct():
            # Search all versions of this package key
            latest = None
            for package in self.all(key):
                # Search for a match. If we've already found a match, make sure
                # we find the most recent version that matches.
                if latest is None or package > latest:
                    if match_name(package.name):
                        latest = package
                    elif package.summary is not None and match_summary(
                            package.summary):
                        latest = package
            if latest is not None:
                packages.append(latest)

        return packages
Example #2
0
    def search(self, criteria, query_type):
        """
        Perform a search from pip

        Parameters
        ----------
        criteria : dict
            Dictionary containing the search criteria. Pip sends search criteria
            for "name" and "summary" (typically, both of these lists have the
            same search values).

            Example::

                {
                    "name": ["value1", "value2", ..., "valueN"],
                    "summary": ["value1", "value2", ..., "valueN"]
                }

        query_type : str
            Type of query to perform. By default, pip sends "or".


        """
        name_queries = criteria.get("name", [])
        summary_queries = criteria.get("summary", [])
        packages = []

        # Create matchers for the queries
        match_name = create_matcher(name_queries, query_type)
        match_summary = create_matcher(summary_queries, query_type)

        for key in self.distinct():
            # Search all versions of this package key
            latest = None
            for package in self.all(key):
                # Search for a match. If we've already found a match, make sure
                # we find the most recent version that matches.
                if latest is None or package > latest:
                    if match_name(package.name):
                        latest = package
                    elif package.summary is not None and match_summary(package.summary):
                        latest = package
            if latest is not None:
                packages.append(latest)

        return packages