diff --git a/.github/labeler.yml b/.github/labeler.yml index 849b7db011c..0a8b9cf7bdd 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -158,6 +158,7 @@ - any: - redbot/core/_drivers/**/* - "!redbot/core/_drivers/**/locales/*" + - redbot/core/_config.py - redbot/core/config.py # Docs - docs/framework_config.rst diff --git a/redbot/core/_config.py b/redbot/core/_config.py new file mode 100644 index 00000000000..40160f352a0 --- /dev/null +++ b/redbot/core/_config.py @@ -0,0 +1,26 @@ +import weakref +from typing import Tuple, Type + +from redbot.core.config import Config, _config_cache +from redbot.core._drivers import BaseDriver + +__all__ = ("get_latest_confs", "migrate") + +_retrieved = weakref.WeakSet() + + +def get_latest_confs() -> Tuple[Config, ...]: + global _retrieved + ret = set(_config_cache.values()) - set(_retrieved) + _retrieved |= ret + return tuple(ret) + + +async def migrate(cur_driver_cls: Type[BaseDriver], new_driver_cls: Type[BaseDriver]) -> None: + """Migrate from one driver type to another.""" + # Get custom group data + core_conf = Config.get_core_conf(allow_old=True) + core_conf.init_custom("CUSTOM_GROUPS", 2) + all_custom_group_data = await core_conf.custom("CUSTOM_GROUPS").all() + + await cur_driver_cls.migrate_to(new_driver_cls, all_custom_group_data) diff --git a/redbot/core/_events.py b/redbot/core/_events.py index 53e8a4ff24b..d352b660ca5 100644 --- a/redbot/core/_events.py +++ b/redbot/core/_events.py @@ -20,7 +20,7 @@ ) from .. import __version__ as red_version, version_info as red_version_info from . import commands -from .config import get_latest_confs +from ._config import get_latest_confs from .utils._internal_utils import ( fuzzy_command_search, format_fuzzy_results, diff --git a/redbot/core/config.py b/redbot/core/config.py index 0e4cf1110ca..83990a9368c 100644 --- a/redbot/core/config.py +++ b/redbot/core/config.py @@ -34,7 +34,6 @@ _T = TypeVar("_T") _config_cache = weakref.WeakValueDictionary() -_retrieved = weakref.WeakSet() class ConfigMeta(type): @@ -64,14 +63,6 @@ def __call__( return instance -def get_latest_confs() -> Tuple["Config"]: - global _retrieved - ret = set(_config_cache.values()) - set(_retrieved) - _retrieved |= ret - # noinspection PyTypeChecker - return tuple(ret) - - class _ValueCtxManager(Awaitable[_T], AsyncContextManager[_T]): # pylint: disable=duplicate-bases """Context manager implementation of config values. @@ -1528,16 +1519,6 @@ def get_custom_lock(self, group_identifier: str) -> asyncio.Lock: return self._lock_cache.setdefault(id_data, asyncio.Lock()) -async def migrate(cur_driver_cls: Type[BaseDriver], new_driver_cls: Type[BaseDriver]) -> None: - """Migrate from one driver type to another.""" - # Get custom group data - core_conf = Config.get_core_conf(allow_old=True) - core_conf.init_custom("CUSTOM_GROUPS", 2) - all_custom_group_data = await core_conf.custom("CUSTOM_GROUPS").all() - - await cur_driver_cls.migrate_to(new_driver_cls, all_custom_group_data) - - def _str_key_dict(value: Dict[Any, _T]) -> Dict[str, _T]: """ Recursively casts all keys in the given `dict` to `str`. diff --git a/redbot/setup.py b/redbot/setup.py index 18eb2fe8338..696db1c7104 100644 --- a/redbot/setup.py +++ b/redbot/setup.py @@ -21,7 +21,8 @@ cli_level_to_log_level, ) from redbot.core import config, data_manager -from redbot.core._cli import ExitCodes +from redbot.core._config import migrate +from redbot.core.cli import ExitCodes from redbot.core.data_manager import appdir, config_dir, config_file from redbot.core._drivers import ( BackendType, @@ -275,7 +276,7 @@ async def do_migration( await cur_driver_cls.initialize(**cur_storage_details) await new_driver_cls.initialize(**new_storage_details) - await config.migrate(cur_driver_cls, new_driver_cls) + await migrate(cur_driver_cls, new_driver_cls) await cur_driver_cls.teardown() await new_driver_cls.teardown()