From da03458ab72cc8119d5b7e04d824c35f024cf1ae Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 26 Feb 2024 20:40:47 +0100 Subject: [PATCH] fix: missing redis import --- otterdog/providers/github/cache/__init__.py | 36 --------------------- otterdog/providers/github/cache/file.py | 30 +++++++++++++++++ otterdog/providers/github/cache/redis.py | 27 ++++++++++++++++ otterdog/providers/github/rest/__init__.py | 3 +- otterdog/webapp/utils.py | 2 +- 5 files changed, 60 insertions(+), 38 deletions(-) create mode 100644 otterdog/providers/github/cache/file.py create mode 100644 otterdog/providers/github/cache/redis.py diff --git a/otterdog/providers/github/cache/__init__.py b/otterdog/providers/github/cache/__init__.py index 62c45151..36f2c54e 100644 --- a/otterdog/providers/github/cache/__init__.py +++ b/otterdog/providers/github/cache/__init__.py @@ -9,44 +9,8 @@ from abc import ABC, abstractmethod from aiohttp_client_cache import CacheBackend -from redis.asyncio.client import Redis class CacheStrategy(ABC): @abstractmethod def get_cache_backend(self) -> CacheBackend: ... - - -_AIOHTTP_CACHE_DIR = ".cache/async_http" - - -class _FileCache(CacheStrategy): - def __init__(self, cache_dir: str): - self._cache_dir = cache_dir - - def get_cache_backend(self) -> CacheBackend: - from aiohttp_client_cache.backends import FileBackend - - return FileBackend( - cache_name=self._cache_dir, - use_temp=False, - ) - - -class _RedisCache(CacheStrategy): - def __init__(self, redis_uri: str, connection: Redis | None): - self._redis_uri = redis_uri - self._connection = connection - - def get_cache_backend(self) -> CacheBackend: - from aiohttp_client_cache.backends import RedisBackend - - return RedisBackend(address=self._redis_uri, connection=self._connection) - - -def file_cache(cache_dir: str = _AIOHTTP_CACHE_DIR) -> CacheStrategy: - return _FileCache(cache_dir) - - -def redis_cache(uri: str, connection: Redis | None = None) -> CacheStrategy: - return _RedisCache(uri, connection) diff --git a/otterdog/providers/github/cache/file.py b/otterdog/providers/github/cache/file.py new file mode 100644 index 00000000..040ae40c --- /dev/null +++ b/otterdog/providers/github/cache/file.py @@ -0,0 +1,30 @@ +# ******************************************************************************* +# Copyright (c) 2024 Eclipse Foundation and others. +# This program and the accompanying materials are made available +# under the terms of the Eclipse Public License 2.0 +# which is available at http://www.eclipse.org/legal/epl-v20.html +# SPDX-License-Identifier: EPL-2.0 +# ******************************************************************************* + +from aiohttp_client_cache import CacheBackend + +from otterdog.providers.github.cache import CacheStrategy + +_AIOHTTP_CACHE_DIR = ".cache/async_http" + + +def file_cache(cache_dir: str = _AIOHTTP_CACHE_DIR) -> CacheStrategy: + return _FileCache(cache_dir) + + +class _FileCache(CacheStrategy): + def __init__(self, cache_dir: str): + self._cache_dir = cache_dir + + def get_cache_backend(self) -> CacheBackend: + from aiohttp_client_cache.backends import FileBackend + + return FileBackend( + cache_name=self._cache_dir, + use_temp=False, + ) diff --git a/otterdog/providers/github/cache/redis.py b/otterdog/providers/github/cache/redis.py new file mode 100644 index 00000000..55cea5eb --- /dev/null +++ b/otterdog/providers/github/cache/redis.py @@ -0,0 +1,27 @@ +# ******************************************************************************* +# Copyright (c) 2024 Eclipse Foundation and others. +# This program and the accompanying materials are made available +# under the terms of the Eclipse Public License 2.0 +# which is available at http://www.eclipse.org/legal/epl-v20.html +# SPDX-License-Identifier: EPL-2.0 +# ******************************************************************************* + +from aiohttp_client_cache import CacheBackend +from redis.asyncio.client import Redis + +from otterdog.providers.github.cache import CacheStrategy + + +def redis_cache(uri: str, connection: Redis | None = None) -> CacheStrategy: + return _RedisCache(uri, connection) + + +class _RedisCache(CacheStrategy): + def __init__(self, redis_uri: str, connection: Redis | None): + self._redis_uri = redis_uri + self._connection = connection + + def get_cache_backend(self) -> CacheBackend: + from aiohttp_client_cache.backends import RedisBackend + + return RedisBackend(address=self._redis_uri, connection=self._connection) diff --git a/otterdog/providers/github/rest/__init__.py b/otterdog/providers/github/rest/__init__.py index d8f70207..66cd3908 100644 --- a/otterdog/providers/github/rest/__init__.py +++ b/otterdog/providers/github/rest/__init__.py @@ -13,7 +13,8 @@ from functools import cached_property from otterdog.providers.github.auth import AuthStrategy -from otterdog.providers.github.cache import CacheStrategy, file_cache +from otterdog.providers.github.cache import CacheStrategy +from otterdog.providers.github.cache.file import file_cache from .requester import Requester diff --git a/otterdog/webapp/utils.py b/otterdog/webapp/utils.py index adabbe26..6c4ed5b8 100644 --- a/otterdog/webapp/utils.py +++ b/otterdog/webapp/utils.py @@ -21,7 +21,7 @@ from otterdog.config import OtterdogConfig from otterdog.providers.github.auth import app_auth, token_auth -from otterdog.providers.github.cache import redis_cache +from otterdog.providers.github.cache.redis import redis_cache from otterdog.providers.github.graphql import GraphQLClient from otterdog.providers.github.rest import RestApi