def check_expand()

in mozregression/build_range.py [0:0]


    def check_expand(self, expand, range_before, range_after, interrupt=None):
        """
        Check the limits of the build range, expanding it if needed.

        :param expand: number of builds to try in case expanding is required
        :param range_before: a callable that takes 2 parameters,
                             (FutureBuildInfo, size) that should construct a
                             new BuildRange of the given size before the given
                             build info.
        :param range_after: same as `range_before`, but should build the range
                            after the given build info.
        :param interrupt: a callable that can interrupt the process (raising
                          StopIteration) or None.
        """
        if len(self) < 2:
            # we need at least two build to expand the range
            return

        first, last = self.get_future(0), self.get_future(-1)
        self._fetch((0, -1))
        self.filter_invalid_builds()

        if len(self) < 2:
            # we need at least two valid builds to expand the range
            return

        def _search(br, index, rng):
            while len(br):
                if interrupt and interrupt():
                    raise StopIteration
                build = br._future_build_infos[index]
                if build.is_available() and build.is_valid():
                    return build
                br._fetch(rng(len(br)))
                br.filter_invalid_builds()

        def search_first(br):
            # search the first available build in br, 3 at a time
            return _search(br, 0, lambda s: list(range(0, min(3, s))))

        def search_last(br):
            # search the last available build in br, 3 at a time
            return _search(br, -1, lambda s: list(range(max(s - 3, 0), s)))

        if self.get_future(0) != first:
            new_first = search_last(range_before(first, expand))
            if new_first:
                LOG.info("Expanding lower limit of the range to %s" % new_first)
                self._future_build_infos.insert(0, new_first)
            else:
                LOG.critical(
                    "First build %s is missing, but mozregression"
                    " can't find a build before - so it is excluded,"
                    " but it could contain the regression!" % first
                )
        if self.get_future(-1) != last:
            new_last = search_first(range_after(last, expand))
            if new_last:
                LOG.info("Expanding higher limit of the range to %s" % new_last)
                self._future_build_infos.append(new_last)
            else:
                LOG.critical(
                    "Last build %s is missing, but mozregression"
                    " can't find a build after - so it is excluded,"
                    " but it could contain the regression!" % last
                )