mathlibtools/lib.py
def find_local_with_fallback(self, rev: Commit, fallback: CacheFallback) -> LocalOleanCache:
        """
        Find (or download) a local cache for `rev` using the provided fallback strategy.
        """
        # if fallback is `NONE`, do not even attempt a search (to conserve network access)
        if fallback == CacheFallback.NONE:
            cache = self.find_exact(rev)
            if not cache:
                raise LeanDownloadError(f"No cache was available for {short_sha(rev)}.\n")
            with cache:
                log.info("Located matching cache")
                return cache.make_local()

        # Otherwise, do a search. This will open as many HTTP connections as
        # necessary, which the `with` statement cleans up.
        ctx, caches = self.find_all(rev)
        with ctx:
            if not caches:
                # this should never happen unless azure goes down
                raise LeanProjectError('No archives available for any commits!')

            cache = caches[0]

            if cache.rev == rev:
                assert len(caches) == 1
                log.info("Using matching cache")
                return caches[0].make_local()

            if len(caches) > 1:
                archive_items = ''.join([f'\n * {short_sha(c.rev)}' for c in caches])
                commit_args = ''.join([f' {short_sha(c.rev)}^!' for c in caches])
                log.warn(
                    f"No cache was available for {short_sha(rev)}.\n"
                    f"There are multiple viable caches from parent commits:{archive_items}\n"
                    f"To see the commits in question, run:\n"
                    f"  git log --graph {short_sha(rev)}{commit_args}")
            else:
                log.warn(
                    f"No cache was available for {short_sha(rev)}. "
                    f"A cache was found for the ancestor {short_sha(cache.rev)}.\n"
                    f"To see the intermediate commits, run:\n"
                    f"  git log --graph {short_sha(rev)} {short_sha(cache.rev)}^!")

            if fallback == CacheFallback.DOWNLOAD_ALL:
                log.info("Preparing all caches, using the first")
                with concurrent.futures.ThreadPoolExecutor() as executor:
                    local_caches = list(executor.map(lambda c: c.make_local(), caches))
                return local_caches[0]
            elif fallback == CacheFallback.DOWNLOAD_FIRST:
                log.info("Using first cache")
                return caches[0].make_local()
            elif fallback == CacheFallback.SHOW:
                log.info(f"Run `leanproject get-cache --rev` on one of the available commits above.")
                raise LeanDownloadError
            else:
                raise RuntimeError('Invalid fallback argument')

        # https://github.com/python/mypy/issues/7726
        assert False

        Find (or download) a local cache for `rev` using the provided fallback strategy.
        
Find (or download) a local cache for `rev` using the provided fallback strategy.
Find ( or download ) a local cache for ` rev ` using the provided fallback strategy .
def find_local_with_fallback(self, rev: Commit, fallback: CacheFallback) -> LocalOleanCache:
        if fallback == CacheFallback.NONE:
            cache = self.find_exact(rev)
            if not cache:
                raise LeanDownloadError(f"No cache was available for {short_sha(rev)}.\n")
            with cache:
                log.info("Located matching cache")
                return cache.make_local()
        ctx, caches = self.find_all(rev)
        with ctx:
            if not caches:
                raise LeanProjectError('No archives available for any commits!')
            cache = caches[0]
            if cache.rev == rev:
                assert len(caches) == 1
                log.info("Using matching cache")
                return caches[0].make_local()
            if len(caches) > 1:
                archive_items = ''.join([f'\n * {short_sha(c.rev)}' for c in caches])
                commit_args = ''.join([f' {short_sha(c.rev)}^!' for c in caches])
                log.warn(
                    f"No cache was available for {short_sha(rev)}.\n"
                    f"There are multiple viable caches from parent commits:{archive_items}\n"
                    f"To see the commits in question, run:\n"
                    f"  git log --graph {short_sha(rev)}{commit_args}")
            else:
                log.warn(
                    f"No cache was available for {short_sha(rev)}. "
                    f"A cache was found for the ancestor {short_sha(cache.rev)}.\n"
                    f"To see the intermediate commits, run:\n"
                    f"  git log --graph {short_sha(rev)} {short_sha(cache.rev)}^!")
            if fallback == CacheFallback.DOWNLOAD_ALL:
                log.info("Preparing all caches, using the first")
                with concurrent.futures.ThreadPoolExecutor() as executor:
                    local_caches = list(executor.map(lambda c: c.make_local(), caches))
                return local_caches[0]
            elif fallback == CacheFallback.DOWNLOAD_FIRST:
                log.info("Using first cache")
                return caches[0].make_local()
            elif fallback == CacheFallback.SHOW:
                log.info(f"Run `leanproject get-cache --rev` on one of the available commits above.")
                raise LeanDownloadError
            else:
                raise RuntimeError('Invalid fallback argument')
        assert False
def find_local_with_fallback ( self , rev : Commit , fallback : CacheFallback ) -> LocalOleanCache : if fallback == CacheFallback . NONE : cache = self . find_exact ( rev ) if not cache : raise LeanDownloadError ( f"No cache was available for {short_sha(rev)}.\n" ) with cache : log . info ( "Located matching cache" ) return cache . make_local ( ) ctx , caches = self . find_all ( rev ) with ctx : if not caches : raise LeanProjectError ( 'No archives available for any commits!' ) cache = caches [ 0 ] if cache . rev == rev : assert len ( caches ) == 1 log . info ( "Using matching cache" ) return caches [ 0 ] . make_local ( ) if len ( caches ) > 1 : archive_items = '' . join ( [ f'\n * {short_sha(c.rev)}' for c in caches ] ) commit_args = '' . join ( [ f' {short_sha(c.rev)}^!' for c in caches ] ) log . warn ( f"No cache was available for {short_sha(rev)}.\n" f"There are multiple viable caches from parent commits:{archive_items}\n" f"To see the commits in question, run:\n" f"  git log --graph {short_sha(rev)}{commit_args}" ) else : log . warn ( f"No cache was available for {short_sha(rev)}. " f"A cache was found for the ancestor {short_sha(cache.rev)}.\n" f"To see the intermediate commits, run:\n" f"  git log --graph {short_sha(rev)} {short_sha(cache.rev)}^!" ) if fallback == CacheFallback . DOWNLOAD_ALL : log . info ( "Preparing all caches, using the first" ) with concurrent . futures . ThreadPoolExecutor ( ) as executor : local_caches = list ( executor . map ( lambda c : c . make_local ( ) , caches ) ) return local_caches [ 0 ] elif fallback == CacheFallback . DOWNLOAD_FIRST : log . info ( "Using first cache" ) return caches [ 0 ] . make_local ( ) elif fallback == CacheFallback . SHOW : log . info ( f"Run `leanproject get-cache --rev` on one of the available commits above." ) raise LeanDownloadError else : raise RuntimeError ( 'Invalid fallback argument' ) assert False
Find (or download) a local cache for `rev` using the provided fallback strategy.
Find ( or download ) a local cache for ` rev ` using the provided fallback strategy .
"""
        Find (or download) a local cache for `rev` using the provided fallback strategy.
        """ # if fallback is `NONE`, do not even attempt a search (to conserve network access) # Otherwise, do a search. This will open as many HTTP connections as # necessary, which the `with` statement cleans up. # this should never happen unless azure goes down # https://github.com/python/mypy/issues/7726
self
rev
Commit
fallback
CacheFallback