Replace retry with tenacity

Proprietary

Rewrite @retry(...) from the retry library as tenacity's @retry, and retry_call(f, fargs, fkwargs, ...) as Retrying(...)(f, *fargs, **fkwargs), keeping retry's behaviour exactly. exceptions becomes retry_if_exception_type, tries becomes stop_after_attempt with reraise=True, so an exhausted retry still raises the original exception, and the schedule of delay, backoff, jitter and max_delay becomes wait_fixed, wait_exponential or wait_incrementing where one of them is that schedule, and _retry_wait, retry's own, where none is. A tries that is not a literal goes through _retry_stop, which retries for ever when it is negative, as retry did. A @retry on an async def never retried, because calling the function only creates a coroutine, so it becomes _retry_calls(Retrying(...)), which retries the call alone as retry did; so does a retry(...) decorator made without an @, which may be applied to either kind of function. The helpers go in one _retry_compat module per package, and into the file itself where it is in none. retry's logging is dropped, because tenacity logs nothing by default. A file is migrated whole or not at all: one with a use that cannot be migrated, such as a * argument or tries=0, is left alone, and so is a project with a module of its own named retry. Run org.openrewrite.python.migrate.FindRetryNotMigrated for those.

org.openrewrite.python.migrate.ReplaceRetryWithTenacity
mod run . --recipe=org.openrewrite.python.migrate.ReplaceRetryWithTenacity

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.