diff --git a/.github/labeler.yml b/.github/labeler.yml index b81b57e4d..292e13f32 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -156,8 +156,8 @@ "Category: Core - API - Config": # Source - any: - - redbot/core/drivers/**/* - - "!redbot/core/drivers/**/locales/*" + - redbot/core/_drivers/**/* + - "!redbot/core/_drivers/**/locales/*" - redbot/core/config.py # Docs - docs/framework_config.rst @@ -167,16 +167,13 @@ # Source - redbot/__init__.py - redbot/core/__init__.py - - redbot/core/cog_manager.py # TODO: privatize cog manager module - redbot/core/data_manager.py - redbot/core/errors.py - redbot/core/tree.py # Docs - - docs/framework_cogmanager.rst # TODO: privatize cog manager module - docs/framework_datamanager.rst - docs/framework_tree.rst # Tests - - redbot/pytest/cog_manager.py # TODO: privatize cog manager module - redbot/pytest/data_manager.py - tests/core/test_cog_manager.py - tests/core/test_data_manager.py @@ -207,8 +204,8 @@ "Category: Core - Command-line Interfaces": - redbot/__main__.py - redbot/logging.py + - redbot/core/_cli.py - redbot/core/_debuginfo.py - - redbot/core/cli.py - redbot/setup.py "Category: Core - Help": - redbot/core/commands/help.py @@ -227,18 +224,20 @@ - docs/framework_modlog.rst "Category: Core - Other Internals": # Source + - redbot/core/_cog_manager.py + - redbot/core/_events.py + - redbot/core/_global_checks.py + - redbot/core/_settings_caches.py - redbot/core/_sharedlibdeprecation.py - - redbot/core/events.py - - redbot/core/global_checks.py - - redbot/core/settings_caches.py - redbot/core/utils/_internal_utils.py # Tests - redbot/pytest/__init__.py + - redbot/pytest/cog_manager.py - redbot/pytest/core.py - tests/core/test_installation.py "Category: Core - RPC/ZMQ": # Source - - redbot/core/rpc.py + - redbot/core/_rpc.py # Docs - docs/framework_rpc.rst # Tests @@ -304,9 +303,6 @@ - docs/_templates/**/* # empty file - redbot/cogs/__init__.py - # can't go more meta than that :) - # TODO: remove this useless file - - redbot/meta.py # py.typed file - redbot/py.typed # requirements files diff --git a/MANIFEST.in b/MANIFEST.in index 10bddfaa1..54c6453ca 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -21,7 +21,7 @@ recursive-include redbot *.export recursive-include redbot py.typed # include *.sql files from postgres driver -recursive-include redbot/core/drivers/postgres *.sql +recursive-include redbot/core/_drivers/postgres *.sql # include tests graft tests diff --git a/docs/framework_cogmanager.rst b/docs/framework_cogmanager.rst deleted file mode 100644 index af094f136..000000000 --- a/docs/framework_cogmanager.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. cog manager docs - -=========== -Cog Manager -=========== - -.. automodule:: redbot.core.cog_manager - :members: diff --git a/docs/framework_config.rst b/docs/framework_config.rst index 52aa30056..7ee852477 100644 --- a/docs/framework_config.rst +++ b/docs/framework_config.rst @@ -540,30 +540,14 @@ Value :members: :special-members: __call__ +IdentifierData +^^^^^^^^^^^^^^ -**************** -Driver Reference -**************** - -.. autofunction:: redbot.core.drivers.get_driver - -.. autoclass:: redbot.core.drivers.BackendType +.. autoclass:: IdentifierData :members: -.. autoclass:: redbot.core.drivers.ConfigCategory - :members: +ConfigCategory +^^^^^^^^^^^^^^ -Base Driver -^^^^^^^^^^^ -.. autoclass:: redbot.core.drivers.BaseDriver - :members: - -JSON Driver -^^^^^^^^^^^ -.. autoclass:: redbot.core.drivers.JsonDriver - :members: - -Postgres Driver -^^^^^^^^^^^^^^^ -.. autoclass:: redbot.core.drivers.PostgresDriver +.. autoclass:: ConfigCategory :members: diff --git a/docs/index.rst b/docs/index.rst index 2eebf2788..83a6e7963 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -69,7 +69,6 @@ Welcome to Red - Discord Bot's documentation! framework_bank framework_bot framework_checks - framework_cogmanager framework_commands framework_config framework_datamanager diff --git a/docs/version_guarantees.rst b/docs/version_guarantees.rst index 0c38801ad..5769fda75 100644 --- a/docs/version_guarantees.rst +++ b/docs/version_guarantees.rst @@ -87,8 +87,17 @@ Ubuntu 22.10 x86-64, aarch64 2023-07-31 (`End of Developer Guarantees ==================== -Anything in the ``redbot.core`` module or any of its submodules -which is not private (even if not documented) should not break without notice. +Any name (function, class, attribute) listed in the ``__all__`` attribute of +the ``redbot`` module (excluding its submodules), ``redbot.core`` package, +or any of its public submodules (modules that do not start with "_") +is considered a public API and should not break without notice. + +Methods of public classes are considered public if they do not start with "_" +or are dunder methods (e.g. ``method()`` and ``__getattr__()`` are public but ``_method()`` isn't). + +Any other name (function, class, attribute) in the ``redbot`` package is considered private, +even if it doesn't start with "_". +Lack of ``__all__`` in the module means that all of its names are considered private APIs. Anything in the ``redbot.cogs`` and ``redbot.vendored`` modules or any of their submodules is specifically excluded from being guaranteed. @@ -100,6 +109,9 @@ This allows us to add certain optional features non-breakingly without a name co Any RPC method exposed by Red may break without notice. +Any exclusion from these guarantees should be noted in the documentation of +the affected attribute, function, class, or method. + If you would like something in here to be guaranteed, open an issue making a case for it to be moved. diff --git a/redbot/__init__.py b/redbot/__init__.py index 8f4963649..cea25ad6d 100644 --- a/redbot/__init__.py +++ b/redbot/__init__.py @@ -13,16 +13,13 @@ from typing import ( Union as _Union, ) - -MIN_PYTHON_VERSION = (3, 8, 1) - -__all__ = [ - "MIN_PYTHON_VERSION", +__all__ = ( "__version__", "version_info", "VersionInfo", - "_update_event_loop_policy", -] +) + +MIN_PYTHON_VERSION = (3, 8, 1) if _sys.version_info < MIN_PYTHON_VERSION: print( f"Python {'.'.join(map(str, MIN_PYTHON_VERSION))} is required to run Red, but you have " diff --git a/redbot/__main__.py b/redbot/__main__.py index 87a273307..716ae1af4 100644 --- a/redbot/__main__.py +++ b/redbot/__main__.py @@ -25,9 +25,9 @@ import rich import redbot.logging from redbot import __version__ from redbot.core.bot import Red, ExitCodes, _NoOwnerSet -from redbot.core.cli import interactive_config, confirm, parse_cli_flags +from redbot.core._cli import interactive_config, confirm, parse_cli_flags from redbot.setup import get_data_dir, get_name, save_config -from redbot.core import data_manager, drivers +from redbot.core import data_manager, _drivers from redbot.core._debuginfo import DebugInfo from redbot.core._sharedlibdeprecation import SharedLibImportWarner @@ -281,7 +281,7 @@ def early_exit_runner( data_manager.load_basic_configuration(cli_flags.instance_name) red = Red(cli_flags=cli_flags, description="Red V3", dm_help=None) - driver_cls = drivers.get_driver_class() + driver_cls = _drivers.get_driver_class() loop.run_until_complete(driver_cls.initialize(**data_manager.storage_details())) loop.run_until_complete(func(red, cli_flags)) loop.run_until_complete(driver_cls.teardown()) @@ -307,7 +307,7 @@ async def run_bot(red: Red, cli_flags: Namespace) -> None: need additional handling in this function. """ - driver_cls = drivers.get_driver_class() + driver_cls = _drivers.get_driver_class() await driver_cls.initialize(**data_manager.storage_details()) diff --git a/redbot/core/cli.py b/redbot/core/_cli.py similarity index 100% rename from redbot/core/cli.py rename to redbot/core/_cli.py diff --git a/redbot/core/cog_manager.py b/redbot/core/_cog_manager.py similarity index 99% rename from redbot/core/cog_manager.py rename to redbot/core/_cog_manager.py index 75bfa034c..ad9287c72 100644 --- a/redbot/core/cog_manager.py +++ b/redbot/core/_cog_manager.py @@ -18,7 +18,7 @@ from .data_manager import cog_data_path from .utils.chat_formatting import box, pagify, humanize_list, inline -__all__ = ["CogManager"] +__all__ = ("CogManager", "CogManagerUI") class NoSuchCog(ImportError): diff --git a/redbot/core/drivers/__init__.py b/redbot/core/_drivers/__init__.py similarity index 100% rename from redbot/core/drivers/__init__.py rename to redbot/core/_drivers/__init__.py diff --git a/redbot/core/drivers/_mongo.py b/redbot/core/_drivers/_mongo.py similarity index 100% rename from redbot/core/drivers/_mongo.py rename to redbot/core/_drivers/_mongo.py diff --git a/redbot/core/drivers/base.py b/redbot/core/_drivers/base.py similarity index 100% rename from redbot/core/drivers/base.py rename to redbot/core/_drivers/base.py diff --git a/redbot/core/drivers/json.py b/redbot/core/_drivers/json.py similarity index 100% rename from redbot/core/drivers/json.py rename to redbot/core/_drivers/json.py diff --git a/redbot/core/drivers/locales/af-ZA.po b/redbot/core/_drivers/locales/af-ZA.po similarity index 100% rename from redbot/core/drivers/locales/af-ZA.po rename to redbot/core/_drivers/locales/af-ZA.po diff --git a/redbot/core/drivers/locales/ar-SA.po b/redbot/core/_drivers/locales/ar-SA.po similarity index 100% rename from redbot/core/drivers/locales/ar-SA.po rename to redbot/core/_drivers/locales/ar-SA.po diff --git a/redbot/core/drivers/locales/bg-BG.po b/redbot/core/_drivers/locales/bg-BG.po similarity index 100% rename from redbot/core/drivers/locales/bg-BG.po rename to redbot/core/_drivers/locales/bg-BG.po diff --git a/redbot/core/drivers/locales/bs-BA.po b/redbot/core/_drivers/locales/bs-BA.po similarity index 100% rename from redbot/core/drivers/locales/bs-BA.po rename to redbot/core/_drivers/locales/bs-BA.po diff --git a/redbot/core/drivers/locales/ca-ES.po b/redbot/core/_drivers/locales/ca-ES.po similarity index 100% rename from redbot/core/drivers/locales/ca-ES.po rename to redbot/core/_drivers/locales/ca-ES.po diff --git a/redbot/core/drivers/locales/cs-CZ.po b/redbot/core/_drivers/locales/cs-CZ.po similarity index 100% rename from redbot/core/drivers/locales/cs-CZ.po rename to redbot/core/_drivers/locales/cs-CZ.po diff --git a/redbot/core/drivers/locales/da-DK.po b/redbot/core/_drivers/locales/da-DK.po similarity index 100% rename from redbot/core/drivers/locales/da-DK.po rename to redbot/core/_drivers/locales/da-DK.po diff --git a/redbot/core/drivers/locales/de-DE.po b/redbot/core/_drivers/locales/de-DE.po similarity index 100% rename from redbot/core/drivers/locales/de-DE.po rename to redbot/core/_drivers/locales/de-DE.po diff --git a/redbot/core/drivers/locales/el-GR.po b/redbot/core/_drivers/locales/el-GR.po similarity index 100% rename from redbot/core/drivers/locales/el-GR.po rename to redbot/core/_drivers/locales/el-GR.po diff --git a/redbot/core/drivers/locales/es-ES.po b/redbot/core/_drivers/locales/es-ES.po similarity index 100% rename from redbot/core/drivers/locales/es-ES.po rename to redbot/core/_drivers/locales/es-ES.po diff --git a/redbot/core/drivers/locales/fi-FI.po b/redbot/core/_drivers/locales/fi-FI.po similarity index 100% rename from redbot/core/drivers/locales/fi-FI.po rename to redbot/core/_drivers/locales/fi-FI.po diff --git a/redbot/core/drivers/locales/fr-FR.po b/redbot/core/_drivers/locales/fr-FR.po similarity index 100% rename from redbot/core/drivers/locales/fr-FR.po rename to redbot/core/_drivers/locales/fr-FR.po diff --git a/redbot/core/drivers/locales/he-IL.po b/redbot/core/_drivers/locales/he-IL.po similarity index 100% rename from redbot/core/drivers/locales/he-IL.po rename to redbot/core/_drivers/locales/he-IL.po diff --git a/redbot/core/drivers/locales/hi-IN.po b/redbot/core/_drivers/locales/hi-IN.po similarity index 100% rename from redbot/core/drivers/locales/hi-IN.po rename to redbot/core/_drivers/locales/hi-IN.po diff --git a/redbot/core/drivers/locales/hu-HU.po b/redbot/core/_drivers/locales/hu-HU.po similarity index 100% rename from redbot/core/drivers/locales/hu-HU.po rename to redbot/core/_drivers/locales/hu-HU.po diff --git a/redbot/core/drivers/locales/id-ID.po b/redbot/core/_drivers/locales/id-ID.po similarity index 100% rename from redbot/core/drivers/locales/id-ID.po rename to redbot/core/_drivers/locales/id-ID.po diff --git a/redbot/core/drivers/locales/it-IT.po b/redbot/core/_drivers/locales/it-IT.po similarity index 100% rename from redbot/core/drivers/locales/it-IT.po rename to redbot/core/_drivers/locales/it-IT.po diff --git a/redbot/core/drivers/locales/ja-JP.po b/redbot/core/_drivers/locales/ja-JP.po similarity index 100% rename from redbot/core/drivers/locales/ja-JP.po rename to redbot/core/_drivers/locales/ja-JP.po diff --git a/redbot/core/drivers/locales/ko-KR.po b/redbot/core/_drivers/locales/ko-KR.po similarity index 100% rename from redbot/core/drivers/locales/ko-KR.po rename to redbot/core/_drivers/locales/ko-KR.po diff --git a/redbot/core/drivers/locales/nb-NO.po b/redbot/core/_drivers/locales/nb-NO.po similarity index 100% rename from redbot/core/drivers/locales/nb-NO.po rename to redbot/core/_drivers/locales/nb-NO.po diff --git a/redbot/core/drivers/locales/nl-NL.po b/redbot/core/_drivers/locales/nl-NL.po similarity index 100% rename from redbot/core/drivers/locales/nl-NL.po rename to redbot/core/_drivers/locales/nl-NL.po diff --git a/redbot/core/drivers/locales/pl-PL.po b/redbot/core/_drivers/locales/pl-PL.po similarity index 100% rename from redbot/core/drivers/locales/pl-PL.po rename to redbot/core/_drivers/locales/pl-PL.po diff --git a/redbot/core/drivers/locales/pt-BR.po b/redbot/core/_drivers/locales/pt-BR.po similarity index 100% rename from redbot/core/drivers/locales/pt-BR.po rename to redbot/core/_drivers/locales/pt-BR.po diff --git a/redbot/core/drivers/locales/pt-PT.po b/redbot/core/_drivers/locales/pt-PT.po similarity index 100% rename from redbot/core/drivers/locales/pt-PT.po rename to redbot/core/_drivers/locales/pt-PT.po diff --git a/redbot/core/drivers/locales/ro-RO.po b/redbot/core/_drivers/locales/ro-RO.po similarity index 100% rename from redbot/core/drivers/locales/ro-RO.po rename to redbot/core/_drivers/locales/ro-RO.po diff --git a/redbot/core/drivers/locales/ru-RU.po b/redbot/core/_drivers/locales/ru-RU.po similarity index 100% rename from redbot/core/drivers/locales/ru-RU.po rename to redbot/core/_drivers/locales/ru-RU.po diff --git a/redbot/core/drivers/locales/sk-SK.po b/redbot/core/_drivers/locales/sk-SK.po similarity index 100% rename from redbot/core/drivers/locales/sk-SK.po rename to redbot/core/_drivers/locales/sk-SK.po diff --git a/redbot/core/drivers/locales/sl-SI.po b/redbot/core/_drivers/locales/sl-SI.po similarity index 100% rename from redbot/core/drivers/locales/sl-SI.po rename to redbot/core/_drivers/locales/sl-SI.po diff --git a/redbot/core/drivers/locales/sr-CS.po b/redbot/core/_drivers/locales/sr-CS.po similarity index 100% rename from redbot/core/drivers/locales/sr-CS.po rename to redbot/core/_drivers/locales/sr-CS.po diff --git a/redbot/core/drivers/locales/sr-SP.po b/redbot/core/_drivers/locales/sr-SP.po similarity index 100% rename from redbot/core/drivers/locales/sr-SP.po rename to redbot/core/_drivers/locales/sr-SP.po diff --git a/redbot/core/drivers/locales/sv-SE.po b/redbot/core/_drivers/locales/sv-SE.po similarity index 100% rename from redbot/core/drivers/locales/sv-SE.po rename to redbot/core/_drivers/locales/sv-SE.po diff --git a/redbot/core/drivers/locales/tr-TR.po b/redbot/core/_drivers/locales/tr-TR.po similarity index 100% rename from redbot/core/drivers/locales/tr-TR.po rename to redbot/core/_drivers/locales/tr-TR.po diff --git a/redbot/core/drivers/locales/uk-UA.po b/redbot/core/_drivers/locales/uk-UA.po similarity index 100% rename from redbot/core/drivers/locales/uk-UA.po rename to redbot/core/_drivers/locales/uk-UA.po diff --git a/redbot/core/drivers/locales/vi-VN.po b/redbot/core/_drivers/locales/vi-VN.po similarity index 100% rename from redbot/core/drivers/locales/vi-VN.po rename to redbot/core/_drivers/locales/vi-VN.po diff --git a/redbot/core/drivers/locales/zh-CN.po b/redbot/core/_drivers/locales/zh-CN.po similarity index 100% rename from redbot/core/drivers/locales/zh-CN.po rename to redbot/core/_drivers/locales/zh-CN.po diff --git a/redbot/core/drivers/locales/zh-HK.po b/redbot/core/_drivers/locales/zh-HK.po similarity index 100% rename from redbot/core/drivers/locales/zh-HK.po rename to redbot/core/_drivers/locales/zh-HK.po diff --git a/redbot/core/drivers/locales/zh-TW.po b/redbot/core/_drivers/locales/zh-TW.po similarity index 100% rename from redbot/core/drivers/locales/zh-TW.po rename to redbot/core/_drivers/locales/zh-TW.po diff --git a/redbot/core/drivers/log.py b/redbot/core/_drivers/log.py similarity index 100% rename from redbot/core/drivers/log.py rename to redbot/core/_drivers/log.py diff --git a/redbot/core/drivers/postgres/__init__.py b/redbot/core/_drivers/postgres/__init__.py similarity index 100% rename from redbot/core/drivers/postgres/__init__.py rename to redbot/core/_drivers/postgres/__init__.py diff --git a/redbot/core/drivers/postgres/ddl.sql b/redbot/core/_drivers/postgres/ddl.sql similarity index 100% rename from redbot/core/drivers/postgres/ddl.sql rename to redbot/core/_drivers/postgres/ddl.sql diff --git a/redbot/core/drivers/postgres/drop_ddl.sql b/redbot/core/_drivers/postgres/drop_ddl.sql similarity index 100% rename from redbot/core/drivers/postgres/drop_ddl.sql rename to redbot/core/_drivers/postgres/drop_ddl.sql diff --git a/redbot/core/drivers/postgres/locales/af-ZA.po b/redbot/core/_drivers/postgres/locales/af-ZA.po similarity index 100% rename from redbot/core/drivers/postgres/locales/af-ZA.po rename to redbot/core/_drivers/postgres/locales/af-ZA.po diff --git a/redbot/core/drivers/postgres/locales/ar-SA.po b/redbot/core/_drivers/postgres/locales/ar-SA.po similarity index 100% rename from redbot/core/drivers/postgres/locales/ar-SA.po rename to redbot/core/_drivers/postgres/locales/ar-SA.po diff --git a/redbot/core/drivers/postgres/locales/bg-BG.po b/redbot/core/_drivers/postgres/locales/bg-BG.po similarity index 100% rename from redbot/core/drivers/postgres/locales/bg-BG.po rename to redbot/core/_drivers/postgres/locales/bg-BG.po diff --git a/redbot/core/drivers/postgres/locales/bs-BA.po b/redbot/core/_drivers/postgres/locales/bs-BA.po similarity index 100% rename from redbot/core/drivers/postgres/locales/bs-BA.po rename to redbot/core/_drivers/postgres/locales/bs-BA.po diff --git a/redbot/core/drivers/postgres/locales/ca-ES.po b/redbot/core/_drivers/postgres/locales/ca-ES.po similarity index 100% rename from redbot/core/drivers/postgres/locales/ca-ES.po rename to redbot/core/_drivers/postgres/locales/ca-ES.po diff --git a/redbot/core/drivers/postgres/locales/cs-CZ.po b/redbot/core/_drivers/postgres/locales/cs-CZ.po similarity index 100% rename from redbot/core/drivers/postgres/locales/cs-CZ.po rename to redbot/core/_drivers/postgres/locales/cs-CZ.po diff --git a/redbot/core/drivers/postgres/locales/da-DK.po b/redbot/core/_drivers/postgres/locales/da-DK.po similarity index 100% rename from redbot/core/drivers/postgres/locales/da-DK.po rename to redbot/core/_drivers/postgres/locales/da-DK.po diff --git a/redbot/core/drivers/postgres/locales/de-DE.po b/redbot/core/_drivers/postgres/locales/de-DE.po similarity index 100% rename from redbot/core/drivers/postgres/locales/de-DE.po rename to redbot/core/_drivers/postgres/locales/de-DE.po diff --git a/redbot/core/drivers/postgres/locales/el-GR.po b/redbot/core/_drivers/postgres/locales/el-GR.po similarity index 100% rename from redbot/core/drivers/postgres/locales/el-GR.po rename to redbot/core/_drivers/postgres/locales/el-GR.po diff --git a/redbot/core/drivers/postgres/locales/es-ES.po b/redbot/core/_drivers/postgres/locales/es-ES.po similarity index 100% rename from redbot/core/drivers/postgres/locales/es-ES.po rename to redbot/core/_drivers/postgres/locales/es-ES.po diff --git a/redbot/core/drivers/postgres/locales/fi-FI.po b/redbot/core/_drivers/postgres/locales/fi-FI.po similarity index 100% rename from redbot/core/drivers/postgres/locales/fi-FI.po rename to redbot/core/_drivers/postgres/locales/fi-FI.po diff --git a/redbot/core/drivers/postgres/locales/fr-FR.po b/redbot/core/_drivers/postgres/locales/fr-FR.po similarity index 100% rename from redbot/core/drivers/postgres/locales/fr-FR.po rename to redbot/core/_drivers/postgres/locales/fr-FR.po diff --git a/redbot/core/drivers/postgres/locales/he-IL.po b/redbot/core/_drivers/postgres/locales/he-IL.po similarity index 100% rename from redbot/core/drivers/postgres/locales/he-IL.po rename to redbot/core/_drivers/postgres/locales/he-IL.po diff --git a/redbot/core/drivers/postgres/locales/hi-IN.po b/redbot/core/_drivers/postgres/locales/hi-IN.po similarity index 100% rename from redbot/core/drivers/postgres/locales/hi-IN.po rename to redbot/core/_drivers/postgres/locales/hi-IN.po diff --git a/redbot/core/drivers/postgres/locales/hu-HU.po b/redbot/core/_drivers/postgres/locales/hu-HU.po similarity index 100% rename from redbot/core/drivers/postgres/locales/hu-HU.po rename to redbot/core/_drivers/postgres/locales/hu-HU.po diff --git a/redbot/core/drivers/postgres/locales/id-ID.po b/redbot/core/_drivers/postgres/locales/id-ID.po similarity index 100% rename from redbot/core/drivers/postgres/locales/id-ID.po rename to redbot/core/_drivers/postgres/locales/id-ID.po diff --git a/redbot/core/drivers/postgres/locales/it-IT.po b/redbot/core/_drivers/postgres/locales/it-IT.po similarity index 100% rename from redbot/core/drivers/postgres/locales/it-IT.po rename to redbot/core/_drivers/postgres/locales/it-IT.po diff --git a/redbot/core/drivers/postgres/locales/ja-JP.po b/redbot/core/_drivers/postgres/locales/ja-JP.po similarity index 100% rename from redbot/core/drivers/postgres/locales/ja-JP.po rename to redbot/core/_drivers/postgres/locales/ja-JP.po diff --git a/redbot/core/drivers/postgres/locales/ko-KR.po b/redbot/core/_drivers/postgres/locales/ko-KR.po similarity index 100% rename from redbot/core/drivers/postgres/locales/ko-KR.po rename to redbot/core/_drivers/postgres/locales/ko-KR.po diff --git a/redbot/core/drivers/postgres/locales/nb-NO.po b/redbot/core/_drivers/postgres/locales/nb-NO.po similarity index 100% rename from redbot/core/drivers/postgres/locales/nb-NO.po rename to redbot/core/_drivers/postgres/locales/nb-NO.po diff --git a/redbot/core/drivers/postgres/locales/nl-NL.po b/redbot/core/_drivers/postgres/locales/nl-NL.po similarity index 100% rename from redbot/core/drivers/postgres/locales/nl-NL.po rename to redbot/core/_drivers/postgres/locales/nl-NL.po diff --git a/redbot/core/drivers/postgres/locales/pl-PL.po b/redbot/core/_drivers/postgres/locales/pl-PL.po similarity index 100% rename from redbot/core/drivers/postgres/locales/pl-PL.po rename to redbot/core/_drivers/postgres/locales/pl-PL.po diff --git a/redbot/core/drivers/postgres/locales/pt-BR.po b/redbot/core/_drivers/postgres/locales/pt-BR.po similarity index 100% rename from redbot/core/drivers/postgres/locales/pt-BR.po rename to redbot/core/_drivers/postgres/locales/pt-BR.po diff --git a/redbot/core/drivers/postgres/locales/pt-PT.po b/redbot/core/_drivers/postgres/locales/pt-PT.po similarity index 100% rename from redbot/core/drivers/postgres/locales/pt-PT.po rename to redbot/core/_drivers/postgres/locales/pt-PT.po diff --git a/redbot/core/drivers/postgres/locales/ro-RO.po b/redbot/core/_drivers/postgres/locales/ro-RO.po similarity index 100% rename from redbot/core/drivers/postgres/locales/ro-RO.po rename to redbot/core/_drivers/postgres/locales/ro-RO.po diff --git a/redbot/core/drivers/postgres/locales/ru-RU.po b/redbot/core/_drivers/postgres/locales/ru-RU.po similarity index 100% rename from redbot/core/drivers/postgres/locales/ru-RU.po rename to redbot/core/_drivers/postgres/locales/ru-RU.po diff --git a/redbot/core/drivers/postgres/locales/sk-SK.po b/redbot/core/_drivers/postgres/locales/sk-SK.po similarity index 100% rename from redbot/core/drivers/postgres/locales/sk-SK.po rename to redbot/core/_drivers/postgres/locales/sk-SK.po diff --git a/redbot/core/drivers/postgres/locales/sl-SI.po b/redbot/core/_drivers/postgres/locales/sl-SI.po similarity index 100% rename from redbot/core/drivers/postgres/locales/sl-SI.po rename to redbot/core/_drivers/postgres/locales/sl-SI.po diff --git a/redbot/core/drivers/postgres/locales/sr-CS.po b/redbot/core/_drivers/postgres/locales/sr-CS.po similarity index 100% rename from redbot/core/drivers/postgres/locales/sr-CS.po rename to redbot/core/_drivers/postgres/locales/sr-CS.po diff --git a/redbot/core/drivers/postgres/locales/sr-SP.po b/redbot/core/_drivers/postgres/locales/sr-SP.po similarity index 100% rename from redbot/core/drivers/postgres/locales/sr-SP.po rename to redbot/core/_drivers/postgres/locales/sr-SP.po diff --git a/redbot/core/drivers/postgres/locales/sv-SE.po b/redbot/core/_drivers/postgres/locales/sv-SE.po similarity index 100% rename from redbot/core/drivers/postgres/locales/sv-SE.po rename to redbot/core/_drivers/postgres/locales/sv-SE.po diff --git a/redbot/core/drivers/postgres/locales/tr-TR.po b/redbot/core/_drivers/postgres/locales/tr-TR.po similarity index 100% rename from redbot/core/drivers/postgres/locales/tr-TR.po rename to redbot/core/_drivers/postgres/locales/tr-TR.po diff --git a/redbot/core/drivers/postgres/locales/uk-UA.po b/redbot/core/_drivers/postgres/locales/uk-UA.po similarity index 100% rename from redbot/core/drivers/postgres/locales/uk-UA.po rename to redbot/core/_drivers/postgres/locales/uk-UA.po diff --git a/redbot/core/drivers/postgres/locales/vi-VN.po b/redbot/core/_drivers/postgres/locales/vi-VN.po similarity index 100% rename from redbot/core/drivers/postgres/locales/vi-VN.po rename to redbot/core/_drivers/postgres/locales/vi-VN.po diff --git a/redbot/core/drivers/postgres/locales/zh-CN.po b/redbot/core/_drivers/postgres/locales/zh-CN.po similarity index 100% rename from redbot/core/drivers/postgres/locales/zh-CN.po rename to redbot/core/_drivers/postgres/locales/zh-CN.po diff --git a/redbot/core/drivers/postgres/locales/zh-HK.po b/redbot/core/_drivers/postgres/locales/zh-HK.po similarity index 100% rename from redbot/core/drivers/postgres/locales/zh-HK.po rename to redbot/core/_drivers/postgres/locales/zh-HK.po diff --git a/redbot/core/drivers/postgres/locales/zh-TW.po b/redbot/core/_drivers/postgres/locales/zh-TW.po similarity index 100% rename from redbot/core/drivers/postgres/locales/zh-TW.po rename to redbot/core/_drivers/postgres/locales/zh-TW.po diff --git a/redbot/core/drivers/postgres/postgres.py b/redbot/core/_drivers/postgres/postgres.py similarity index 100% rename from redbot/core/drivers/postgres/postgres.py rename to redbot/core/_drivers/postgres/postgres.py diff --git a/redbot/core/events.py b/redbot/core/_events.py similarity index 100% rename from redbot/core/events.py rename to redbot/core/_events.py diff --git a/redbot/core/global_checks.py b/redbot/core/_global_checks.py similarity index 100% rename from redbot/core/global_checks.py rename to redbot/core/_global_checks.py diff --git a/redbot/core/rpc.py b/redbot/core/_rpc.py similarity index 98% rename from redbot/core/rpc.py rename to redbot/core/_rpc.py index 58eddfff4..5cd2e1660 100644 --- a/redbot/core/rpc.py +++ b/redbot/core/_rpc.py @@ -8,11 +8,11 @@ from aiohttp_json_rpc.rpc import JsonRpcMethod import logging -from redbot.core.cli import ExitCodes +from redbot.core._cli import ExitCodes log = logging.getLogger("red.rpc") -__all__ = ["RPC", "RPCMixin", "get_name"] +__all__ = ("RPC", "RPCMixin", "get_name") def get_name(func, prefix=""): diff --git a/redbot/core/settings_caches.py b/redbot/core/_settings_caches.py similarity index 100% rename from redbot/core/settings_caches.py rename to redbot/core/_settings_caches.py diff --git a/redbot/core/app_commands/__init__.py b/redbot/core/app_commands/__init__.py index cd5b2ddb8..b6f613c67 100644 --- a/redbot/core/app_commands/__init__.py +++ b/redbot/core/app_commands/__init__.py @@ -59,3 +59,57 @@ from discord.app_commands import ( locale_str as locale_str, rename as rename, ) + +__all__ = ( + "AllChannels", + "AppCommand", + "AppCommandChannel", + "AppCommandError", + "AppCommandGroup", + "AppCommandPermissions", + "AppCommandThread", + "Argument", + "BotMissingPermissions", + "Command", + "CommandAlreadyRegistered", + "CommandInvokeError", + "CommandLimitReached", + "CommandNotFound", + "CommandOnCooldown", + "CommandSignatureMismatch", + "CommandSyncFailure", + "CommandTree", + "ContextMenu", + "Cooldown", + "Group", + "GuildAppCommandPermissions", + "MissingAnyRole", + "MissingApplicationID", + "MissingPermissions", + "MissingRole", + "Namespace", + "NoPrivateMessage", + "Parameter", + "Range", + "Transform", + "Transformer", + "TransformerError", + "TranslationContext", + "TranslationContextLocation", + "TranslationContextTypes", + "TranslationError", + "Translator", + "autocomplete", + "check", + "CheckFailure", + "Choice", + "choices", + "command", + "context_menu", + "default_permissions", + "describe", + "guild_only", + "guilds", + "locale_str", + "rename", +) diff --git a/redbot/core/bank.py b/redbot/core/bank.py index bca1a8775..9af9dd8ab 100644 --- a/redbot/core/bank.py +++ b/redbot/core/bank.py @@ -20,15 +20,19 @@ if TYPE_CHECKING: _ = Translator("Bank API", __file__) -__all__ = [ +__all__ = ( + "is_owner_if_bank_global", "Account", "get_balance", + "can_spend", "set_balance", "withdraw_credits", "deposit_credits", - "can_spend", "transfer_credits", "wipe_bank", + "bank_prune", + "get_leaderboard", + "get_leaderboard_position", "get_account", "is_global", "set_global", @@ -36,15 +40,13 @@ __all__ = [ "set_bank_name", "get_currency_name", "set_currency_name", - "get_default_balance", - "set_default_balance", "get_max_balance", "set_max_balance", - "cost", + "get_default_balance", + "set_default_balance", "AbortPurchase", - "bank_prune", - "is_owner_if_bank_global", -] + "cost", +) _MAX_BALANCE = 2**63 - 1 diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 4666e99b7..f4cb894eb 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -37,15 +37,15 @@ import discord from discord.ext import commands as dpy_commands from discord.ext.commands import when_mentioned_or -from . import Config, i18n, app_commands, commands, errors, drivers, modlog, bank -from .cli import ExitCodes -from .cog_manager import CogManager, CogManagerUI +from . import Config, i18n, app_commands, commands, errors, _drivers, modlog, bank +from ._cli import ExitCodes +from ._cog_manager import CogManager, CogManagerUI from .core_commands import Core from .data_manager import cog_data_path from .dev_commands import Dev -from .events import init_events -from .global_checks import init_global_checks -from .settings_caches import ( +from ._events import init_events +from ._global_checks import init_global_checks +from ._settings_caches import ( PrefixManager, IgnoreManager, WhitelistBlacklistManager, @@ -53,7 +53,7 @@ from .settings_caches import ( I18nManager, ) from .utils.predicates import MessagePredicate -from .rpc import RPCMixin +from ._rpc import RPCMixin from .tree import RedTree from .utils import can_user_send_messages_in, common_filters, AsyncIter from .utils.chat_formatting import box, text_to_file @@ -2161,7 +2161,7 @@ class Red( async def close(self): """Logs out of Discord and closes all connections.""" await super().close() - await drivers.get_driver_class().teardown() + await _drivers.get_driver_class().teardown() try: if self.rpc_enabled: await self.rpc.close() diff --git a/redbot/core/commands/__init__.py b/redbot/core/commands/__init__.py index 5b51643aa..96bd69a64 100644 --- a/redbot/core/commands/__init__.py +++ b/redbot/core/commands/__init__.py @@ -207,3 +207,194 @@ from discord.ext.commands import ( parameter as parameter, HybridCommandError as HybridCommandError, ) + +__all__ = ( + "Cog", + "CogMixin", + "CogCommandMixin", + "CogGroupMixin", + "Command", + "Group", + "GroupCog", + "GroupMixin", + "command", + "HybridCommand", + "HybridGroup", + "hybrid_command", + "hybrid_group", + "group", + "RedUnhandledAPI", + "RESERVED_COMMAND_NAMES", + "Context", + "GuildContext", + "DMContext", + "DictConverter", + "RelativedeltaConverter", + "TimedeltaConverter", + "get_dict_converter", + "get_timedelta_converter", + "parse_relativedelta", + "parse_timedelta", + "NoParseOptional", + "UserInputOptional", + "RawUserIdConverter", + "CogConverter", + "CommandConverter", + "BotMissingPermissions", + "UserFeedbackCheckFailure", + "ArgParserFailure", + "red_help", + "RedHelpFormatter", + "HelpSettings", + "CheckPredicate", + "GlobalPermissionModel", + "GuildPermissionModel", + "PermissionModel", + "PrivilegeLevel", + "PermState", + "Requires", + "permissions_check", + "bot_has_permissions", + "bot_in_a_guild", + "bot_can_manage_channel", + "bot_can_react", + "has_permissions", + "can_manage_channel", + "has_guild_permissions", + "is_owner", + "guildowner", + "guildowner_or_can_manage_channel", + "guildowner_or_permissions", + "admin", + "admin_or_can_manage_channel", + "admin_or_permissions", + "mod", + "mod_or_can_manage_channel", + "mod_or_permissions", + "BadArgument", + "EmojiConverter", + "GuildConverter", + "InvalidEndOfQuotedStringError", + "MemberConverter", + "BotMissingRole", + "PrivateMessageOnly", + "HelpCommand", + "MinimalHelpCommand", + "DisabledCommand", + "ExtensionFailed", + "Bot", + "NotOwner", + "CategoryChannelConverter", + "CogMeta", + "ConversionError", + "UserInputError", + "Converter", + "InviteConverter", + "ExtensionError", + "Cooldown", + "CheckFailure", + "PartialMessageConverter", + "MessageConverter", + "MissingPermissions", + "BadUnionArgument", + "DefaultHelpCommand", + "ExtensionNotFound", + "UserConverter", + "MissingRole", + "CommandOnCooldown", + "MissingAnyRole", + "ExtensionNotLoaded", + "clean_content", + "CooldownMapping", + "ArgumentParsingError", + "RoleConverter", + "CommandError", + "TextChannelConverter", + "UnexpectedQuoteError", + "Paginator", + "BucketType", + "NoEntryPointError", + "CommandInvokeError", + "TooManyArguments", + "Greedy", + "ExpectedClosingQuoteError", + "ColourConverter", + "ColorConverter", + "VoiceChannelConverter", + "StageChannelConverter", + "NSFWChannelRequired", + "IDConverter", + "MissingRequiredArgument", + "GameConverter", + "CommandNotFound", + "BotMissingAnyRole", + "NoPrivateMessage", + "AutoShardedBot", + "ExtensionAlreadyLoaded", + "PartialEmojiConverter", + "check_any", + "max_concurrency", + "CheckAnyFailure", + "MaxConcurrency", + "MaxConcurrencyReached", + "bot_has_guild_permissions", + "CommandRegistrationError", + "GuildNotFound", + "MessageNotFound", + "MemberNotFound", + "UserNotFound", + "ChannelNotFound", + "ChannelNotReadable", + "BadColourArgument", + "RoleNotFound", + "BadInviteArgument", + "EmojiNotFound", + "PartialEmojiConversionFailure", + "BadBoolArgument", + "TooManyFlags", + "MissingRequiredFlag", + "flag", + "FlagError", + "ObjectNotFound", + "GuildStickerNotFound", + "ThreadNotFound", + "GuildChannelConverter", + "run_converters", + "Flag", + "BadFlagArgument", + "BadColorArgument", + "dynamic_cooldown", + "BadLiteralArgument", + "DynamicCooldownMapping", + "ThreadConverter", + "GuildStickerConverter", + "ObjectConverter", + "FlagConverter", + "MissingFlagArgument", + "ScheduledEventConverter", + "ScheduledEventNotFound", + "check", + "guild_only", + "cooldown", + "dm_only", + "is_nsfw", + "has_role", + "has_any_role", + "bot_has_role", + "when_mentioned_or", + "when_mentioned", + "bot_has_any_role", + "before_invoke", + "after_invoke", + "CurrentChannel", + "Author", + "param", + "MissingRequiredAttachment", + "Parameter", + "ForumChannelConverter", + "CurrentGuild", + "Range", + "RangeError", + "parameter", + "HybridCommandError", +) diff --git a/redbot/core/commands/commands.py b/redbot/core/commands/commands.py index 3a64d7038..b8ce5fd90 100644 --- a/redbot/core/commands/commands.py +++ b/redbot/core/commands/commands.py @@ -68,7 +68,7 @@ else: _P = TypeVar("_P") -__all__ = [ +__all__ = ( "Cog", "CogMixin", "CogCommandMixin", @@ -77,13 +77,15 @@ __all__ = [ "Group", "GroupCog", "GroupMixin", + "HybridCommand", + "HybridGroup", "command", "group", "hybrid_command", "hybrid_group", "RESERVED_COMMAND_NAMES", "RedUnhandledAPI", -] +) #: The following names are reserved for various reasons RESERVED_COMMAND_NAMES = ( diff --git a/redbot/core/commands/errors.py b/redbot/core/commands/errors.py index 8c4752bba..6cc5b3ccd 100644 --- a/redbot/core/commands/errors.py +++ b/redbot/core/commands/errors.py @@ -4,6 +4,7 @@ import discord from discord.ext import commands __all__ = ( + "ConversionFailure", "BotMissingPermissions", "UserFeedbackCheckFailure", "ArgParserFailure", diff --git a/redbot/core/config.py b/redbot/core/config.py index af3e41a3c..0e4cf1110 100644 --- a/redbot/core/config.py +++ b/redbot/core/config.py @@ -19,9 +19,15 @@ from typing import ( import discord -from .drivers import IdentifierData, get_driver, ConfigCategory, BaseDriver +from ._drivers import BaseDriver, ConfigCategory, IdentifierData, get_driver -__all__ = ["Config", "get_latest_confs", "migrate"] +__all__ = ( + "ConfigCategory", + "IdentifierData", + "Value", + "Group", + "Config", +) log = logging.getLogger("red.config") @@ -122,21 +128,22 @@ class _ValueCtxManager(Awaitable[_T], AsyncContextManager[_T]): # pylint: disab class Value: """A singular "value" of data. + This class should not be instantiated directly - you should get instances of this class + through methods and attribute lookup on instances of `Config` and `Group`. + Attributes ---------- identifier_data : IdentifierData Information on identifiers for this value. default The default value for the data element that `identifiers` points at. - driver : `redbot.core.drivers.BaseDriver` - A reference to `Config.driver`. """ def __init__(self, identifier_data: IdentifierData, default_value, driver, config: "Config"): self.identifier_data = identifier_data self.default = default_value - self.driver = driver + self._driver = driver self._config = config def get_lock(self) -> asyncio.Lock: @@ -174,7 +181,7 @@ class Value: async def _get(self, default=...): try: - ret = await self.driver.get(self.identifier_data) + ret = await self._driver.get(self.identifier_data) except KeyError: return default if default is not ... else self.default return ret @@ -255,13 +262,13 @@ class Value: """ if isinstance(value, dict): value = _str_key_dict(value) - await self.driver.set(self.identifier_data, value=value) + await self._driver.set(self.identifier_data, value=value) async def clear(self): """ Clears the value from record for the data element pointed to by `identifiers`. """ - await self.driver.clear(self.identifier_data) + await self._driver.clear(self.identifier_data) class Group(Value): @@ -271,14 +278,15 @@ class Group(Value): Inherits from `Value` which means that all of the attributes and methods available in `Value` are also available when working with a `Group` object. + This class should not be instantiated directly - you should get instances of this class + through methods and attribute lookup on instances of `Config` and `Group`. + Attributes ---------- defaults : `dict` All registered default values for this Group. force_registration : `bool` Same as `Config.force_registration`. - driver : `redbot.core.drivers.BaseDriver` - A reference to `Config.driver`. """ @@ -292,9 +300,9 @@ class Group(Value): ): self._defaults = defaults self.force_registration = force_registration - self.driver = driver + self._driver = driver - super().__init__(identifier_data, {}, self.driver, config) + super().__init__(identifier_data, {}, self._driver, config) @property def defaults(self): @@ -340,7 +348,7 @@ class Group(Value): return Group( identifier_data=new_identifiers, defaults=self._defaults[item], - driver=self.driver, + driver=self._driver, force_registration=self.force_registration, config=self._config, ) @@ -348,7 +356,7 @@ class Group(Value): return Value( identifier_data=new_identifiers, default_value=self._defaults[item], - driver=self.driver, + driver=self._driver, config=self._config, ) elif self.force_registration: @@ -357,7 +365,7 @@ class Group(Value): return Value( identifier_data=new_identifiers, default_value=None, - driver=self.driver, + driver=self._driver, config=self._config, ) @@ -383,7 +391,7 @@ class Group(Value): """ path = tuple(str(p) for p in nested_path) identifier_data = self.identifier_data.get_child(*path) - await self.driver.clear(identifier_data) + await self._driver.clear(identifier_data) def is_group(self, item: Any) -> bool: """A helper method for `__getattr__`. Most developers will have no need @@ -502,7 +510,7 @@ class Group(Value): identifier_data = self.identifier_data.get_child(*path) try: - raw = await self.driver.get(identifier_data) + raw = await self._driver.get(identifier_data) except KeyError: if default is not ...: return default @@ -587,7 +595,7 @@ class Group(Value): identifier_data = self.identifier_data.get_child(*path) if isinstance(value, dict): value = _str_key_dict(value) - await self.driver.set(identifier_data, value=value) + await self._driver.set(identifier_data, value=value) class Config(metaclass=ConfigMeta): @@ -612,8 +620,6 @@ class Config(metaclass=ConfigMeta): unique_identifier : `int` Unique identifier provided to differentiate cog data when name conflicts occur. - driver - An instance of a driver that implements `redbot.core.drivers.BaseDriver`. force_registration : `bool` Determines if Config should throw an error if a cog attempts to access an attribute which has not been previously registered. @@ -644,7 +650,7 @@ class Config(metaclass=ConfigMeta): self.cog_name = cog_name self.unique_identifier = unique_identifier - self.driver = driver + self._driver = driver self.force_registration = force_registration self._defaults = defaults or {} @@ -940,7 +946,7 @@ class Config(metaclass=ConfigMeta): return Group( identifier_data=identifier_data, defaults=defaults, - driver=self.driver, + driver=self._driver, force_registration=self.force_registration, config=self, ) @@ -1184,7 +1190,7 @@ class Config(metaclass=ConfigMeta): defaults = self.defaults.get(scope, {}) try: - dict_ = await self.driver.get(group.identifier_data) + dict_ = await self._driver.get(group.identifier_data) except KeyError: pass else: @@ -1301,7 +1307,7 @@ class Config(metaclass=ConfigMeta): if guild is None: group = self._get_base_group(self.MEMBER) try: - dict_ = await self.driver.get(group.identifier_data) + dict_ = await self._driver.get(group.identifier_data) except KeyError: pass else: @@ -1310,7 +1316,7 @@ class Config(metaclass=ConfigMeta): else: group = self._get_base_group(self.MEMBER, str(guild.id)) try: - guild_data = await self.driver.get(group.identifier_data) + guild_data = await self._driver.get(group.identifier_data) except KeyError: pass else: @@ -1338,7 +1344,7 @@ class Config(metaclass=ConfigMeta): if not scopes: # noinspection PyTypeChecker identifier_data = IdentifierData(self.cog_name, self.unique_identifier, "", (), (), 0) - group = Group(identifier_data, defaults={}, driver=self.driver, config=self) + group = Group(identifier_data, defaults={}, driver=self._driver, config=self) else: cat, *scopes = scopes group = self._get_base_group(cat, *scopes) diff --git a/redbot/core/data_manager.py b/redbot/core/data_manager.py index 85169ad86..bb5bfac1d 100644 --- a/redbot/core/data_manager.py +++ b/redbot/core/data_manager.py @@ -9,21 +9,19 @@ from pathlib import Path from typing import Any, Dict import platformdirs -from discord.utils import deprecated from . import commands -from .cli import ExitCodes +from ._cli import ExitCodes -__all__ = [ - "create_temp_config", - "load_basic_configuration", +__all__ = ( "cog_data_path", "core_data_path", - "load_bundled_data", "bundled_data_path", + "data_path", + "metadata_file", "storage_details", "storage_type", -] +) log = logging.getLogger("red.data_manager") @@ -197,12 +195,6 @@ def core_data_path() -> Path: return core_path.resolve() -# noinspection PyUnusedLocal -@deprecated("bundled_data_path() without calling this function") -def load_bundled_data(cog_instance, init_location: str): - pass - - def bundled_data_path(cog_instance: commands.Cog) -> Path: """ Get the path to the "data" directory bundled with this cog. @@ -239,6 +231,28 @@ def bundled_data_path(cog_instance: commands.Cog) -> Path: return bundled_path +def data_path() -> Path: + """Gets the base data path. + + Returns + ------- + str + Storage type. + """ + return _base_data_path() + + +def metadata_file() -> Path: + """Gets the path of metadata file. + + Returns + ------- + str + Storage type. + """ + return config_file + + def storage_type() -> str: """Gets the storage type as a string. @@ -253,14 +267,14 @@ def storage_type() -> str: raise RuntimeError("Bot basic config has not been loaded yet.") from e -def storage_details() -> dict: +def storage_details() -> Dict[str, str]: """Gets any details necessary for config drivers to load. These are set on setup. Returns ------- - dict + Dict[str, str] Storage details. """ - return basic_config.get("STORAGE_DETAILS", {}) + return deepcopy(basic_config.get("STORAGE_DETAILS", {})) diff --git a/redbot/core/errors.py b/redbot/core/errors.py index 7b9bd855d..c3e6da8c9 100644 --- a/redbot/core/errors.py +++ b/redbot/core/errors.py @@ -7,6 +7,18 @@ from .i18n import Translator _ = Translator(__name__, __file__) +__all__ = ( + "RedError", + "PackageAlreadyLoaded", + "CogLoadError", + "BankError", + "BalanceTooHigh", + "BankPruneError", + "ConfigError", + "StoredTypeError", + "CannotSetSubfield", +) + class RedError(Exception): """Base error class for Red-related errors.""" diff --git a/redbot/core/generic_casetypes.py b/redbot/core/generic_casetypes.py index 281479c36..78f526c83 100644 --- a/redbot/core/generic_casetypes.py +++ b/redbot/core/generic_casetypes.py @@ -3,6 +3,26 @@ Contains generic mod action casetypes for use in Red and 3rd party cogs. These do not need to be registered to the modlog, as it is done for you. """ +__all__ = ( + "ban", + "kick", + "hackban", + "tempban", + "softban", + "unban", + "voiceban", + "voiceunban", + "voicemute", + "channelmute", + "servermute", + "voiceunmute", + "channelunmute", + "serverunmute", + "voicekick", + "warning", + "all_generics", +) + ban = {"name": "ban", "default_setting": True, "image": "\N{HAMMER}", "case_str": "Ban"} kick = {"name": "kick", "default_setting": True, "image": "\N{WOMANS BOOTS}", "case_str": "Kick"} diff --git a/redbot/core/i18n.py b/redbot/core/i18n.py index 46ef35f48..a789589d3 100644 --- a/redbot/core/i18n.py +++ b/redbot/core/i18n.py @@ -20,15 +20,14 @@ if TYPE_CHECKING: __all__ = [ "get_locale", - "set_locale", - "reload_locales", - "cog_i18n", - "Translator", - "get_babel_locale", - "get_babel_regional_format", + "get_regional_format", "get_locale_from_guild", "get_regional_format_from_guild", "set_contextual_locales_from_guild", + "Translator", + "get_babel_locale", + "get_babel_regional_format", + "cog_i18n", ] log = logging.getLogger("red.i18n") @@ -48,6 +47,14 @@ _translators = [] def get_locale() -> str: + """ + Get locale in a current context. + + Returns + ------- + str + Current locale's language code with country code included, e.g. "en-US". + """ return str(_current_locale.get()) @@ -63,6 +70,14 @@ def set_contextual_locale(locale: str) -> None: def get_regional_format() -> str: + """ + Get regional format in a current context. + + Returns + ------- + str + Current regional format's language code with country code included, e.g. "en-US". + """ if _current_regional_format.get() is None: return str(_current_locale.get()) return str(_current_regional_format.get()) @@ -97,7 +112,7 @@ async def get_locale_from_guild(bot: Red, guild: Optional[discord.Guild]) -> str Returns ------- str - Guild's locale string. + Guild locale's language code with country code included, e.g. "en-US". """ return await bot._i18n_cache.get_locale(guild) @@ -117,7 +132,7 @@ async def get_regional_format_from_guild(bot: Red, guild: Optional[discord.Guild Returns ------- str - Guild's locale string. + Guild regional format's language code with country code included, e.g. "en-US". """ return await bot._i18n_cache.get_regional_format(guild) diff --git a/redbot/core/modlog.py b/redbot/core/modlog.py index b57876bdc..8e0f8185a 100644 --- a/redbot/core/modlog.py +++ b/redbot/core/modlog.py @@ -25,10 +25,11 @@ if TYPE_CHECKING: log = logging.getLogger("red.core.modlog") -__all__ = [ +__all__ = ( "Case", "CaseType", "get_case", + "get_latest_case", "get_all_cases", "get_cases_for_member", "create_case", @@ -39,7 +40,7 @@ __all__ = [ "get_modlog_channel", "set_modlog_channel", "reset_cases", -] +) _config: Optional[Config] = None _bot_ref: Optional[Red] = None @@ -243,6 +244,8 @@ class Case: A single mod log case + This class should ONLY be instantiated by the modlog itself. + Attributes ---------- bot: Red @@ -730,6 +733,8 @@ class CaseType: """ A single case type + This class should ONLY be instantiated by the modlog itself. + Attributes ---------- name: str diff --git a/redbot/core/tree.py b/redbot/core/tree.py index cd93ca11d..11df7a0dd 100644 --- a/redbot/core/tree.py +++ b/redbot/core/tree.py @@ -26,6 +26,7 @@ import traceback from datetime import datetime, timedelta, timezone from typing import List, Dict, Tuple, Union, Optional, Sequence +__all__ = ("RedTree",) log = logging.getLogger("red") diff --git a/redbot/core/utils/__init__.py b/redbot/core/utils/__init__.py index 179343c9a..5e4ae02a1 100644 --- a/redbot/core/utils/__init__.py +++ b/redbot/core/utils/__init__.py @@ -40,6 +40,8 @@ if TYPE_CHECKING: DMMessageable = Union[commands.DMContext, discord.Member, discord.User, discord.DMChannel] __all__ = ( + "async_filter", + "async_enumerate", "bounded_gather", "bounded_gather_iter", "deduplicate_iterables", diff --git a/redbot/core/utils/antispam.py b/redbot/core/utils/antispam.py index 4a49bc4c1..70d46d9a0 100644 --- a/redbot/core/utils/antispam.py +++ b/redbot/core/utils/antispam.py @@ -2,6 +2,8 @@ from datetime import datetime, timedelta from typing import Tuple, List from collections import namedtuple +__all__ = ("AntiSpam",) + _AntiSpamInterval = namedtuple("_AntiSpamInterval", ["period", "frequency"]) diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index a62867555..8cf37e8a2 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -13,6 +13,29 @@ from babel.numbers import format_decimal from redbot.core.i18n import Translator, get_babel_locale, get_babel_regional_format +__all__ = ( + "error", + "warning", + "info", + "success", + "question", + "bold", + "box", + "inline", + "italics", + "spoiler", + "pagify", + "strikethrough", + "underline", + "quote", + "escape", + "humanize_list", + "format_perms_list", + "humanize_timedelta", + "humanize_number", + "text_to_file", +) + _ = Translator("UtilsChatFormatting", __file__) diff --git a/redbot/core/utils/embed.py b/redbot/core/utils/embed.py index ede53c780..ec8840039 100644 --- a/redbot/core/utils/embed.py +++ b/redbot/core/utils/embed.py @@ -2,6 +2,8 @@ import discord import random +__all__ = ("randomize_colour", "randomize_color") + def randomize_colour(embed: discord.Embed) -> discord.Embed: """ diff --git a/redbot/core/utils/menus.py b/redbot/core/utils/menus.py index 693681c4d..bdf2f25d8 100644 --- a/redbot/core/utils/menus.py +++ b/redbot/core/utils/menus.py @@ -14,6 +14,15 @@ from .. import commands from .predicates import ReactionPredicate from .views import SimpleMenu, _SimplePageSource +__all__ = ( + "menu", + "next_page", + "prev_page", + "close_menu", + "start_adding_reactions", + "DEFAULT_CONTROLS", +) + _T = TypeVar("_T") _PageList = TypeVar("_PageList", List[str], List[discord.Embed]) _ReactableEmoji = Union[str, discord.Emoji] diff --git a/redbot/core/utils/mod.py b/redbot/core/utils/mod.py index 09212f821..f795a459f 100644 --- a/redbot/core/utils/mod.py +++ b/redbot/core/utils/mod.py @@ -8,6 +8,16 @@ if TYPE_CHECKING: from ..bot import Red from ..commands import Context +__all__ = ( + "mass_purge", + "slow_deletion", + "get_audit_reason", + "is_mod_or_superior", + "strfdelta", + "is_admin_or_superior", + "check_permissions", +) + async def mass_purge( messages: List[discord.Message], diff --git a/redbot/core/utils/predicates.py b/redbot/core/utils/predicates.py index 0f383533f..d6d22dfb1 100644 --- a/redbot/core/utils/predicates.py +++ b/redbot/core/utils/predicates.py @@ -8,6 +8,8 @@ from discord.ext import commands as dpy_commands from redbot.core import commands +__all__ = ("MessagePredicate", "ReactionPredicate") + _ID_RE = re.compile(r"([0-9]{15,20})$") _USER_MENTION_RE = re.compile(r"<@!?([0-9]{15,20})>$") _CHAN_MENTION_RE = re.compile(r"<#([0-9]{15,20})>$") diff --git a/redbot/core/utils/tunnel.py b/redbot/core/utils/tunnel.py index 614f56702..5c38f1192 100644 --- a/redbot/core/utils/tunnel.py +++ b/redbot/core/utils/tunnel.py @@ -7,6 +7,8 @@ import weakref from typing import List, Optional, Union from .common_filters import filter_mass_mentions +__all__ = ("Tunnel",) + _instances = weakref.WeakValueDictionary({}) diff --git a/redbot/core/utils/views.py b/redbot/core/utils/views.py index 4bcd4c25b..960131b99 100644 --- a/redbot/core/utils/views.py +++ b/redbot/core/utils/views.py @@ -8,10 +8,11 @@ from redbot.core.i18n import Translator from redbot.vendored.discord.ext import menus from redbot.core.commands.converter import get_dict_converter - if TYPE_CHECKING: from redbot.core.commands import Context +__all__ = ("SimpleMenu", "SetApiModal", "SetApiView") + _ = Translator("UtilsViews", __file__) _ACCEPTABLE_PAGE_TYPES = Union[Dict[str, Union[str, discord.Embed]], discord.Embed, str] diff --git a/redbot/meta.py b/redbot/meta.py deleted file mode 100644 index 62961fbc6..000000000 --- a/redbot/meta.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -This module will contain various attributes useful for testing and cog development. -""" - -testing = False diff --git a/redbot/pytest/core.py b/redbot/pytest/core.py index ee41822cc..4eb60b3cf 100644 --- a/redbot/pytest/core.py +++ b/redbot/pytest/core.py @@ -6,7 +6,7 @@ import weakref import pytest from redbot.core import Config from redbot.core.bot import Red -from redbot.core import config as config_module, drivers +from redbot.core import config as config_module, _drivers __all__ = [ "override_data_path", @@ -50,7 +50,7 @@ def driver(tmpdir_factory): rand = str(uuid.uuid4()) path = Path(str(tmpdir_factory.mktemp(rand))) - return drivers.get_driver("PyTest", str(random.randint(1, 999999)), data_path_override=path) + return _drivers.get_driver("PyTest", str(random.randint(1, 999999)), data_path_override=path) @pytest.fixture() @@ -154,7 +154,7 @@ def ctx(empty_member, empty_channel, red): # region Red Mock @pytest.fixture() def red(config_fr): - from redbot.core.cli import parse_cli_flags + from redbot.core._cli import parse_cli_flags cli_flags = parse_cli_flags(["ignore_me"]) diff --git a/redbot/pytest/rpc.py b/redbot/pytest/rpc.py index ffe3029d7..db189e5de 100644 --- a/redbot/pytest/rpc.py +++ b/redbot/pytest/rpc.py @@ -1,5 +1,5 @@ import pytest -from redbot.core.rpc import RPC, RPCMixin +from redbot.core._rpc import RPC, RPCMixin from unittest.mock import MagicMock diff --git a/redbot/setup.py b/redbot/setup.py index 3e4ba8e8d..270fa7315 100644 --- a/redbot/setup.py +++ b/redbot/setup.py @@ -14,16 +14,16 @@ from typing import Dict, Any, Optional, Union import click -from redbot.core.cli import confirm +from redbot.core._cli import confirm from redbot.core.utils._internal_utils import ( safe_delete, create_backup as red_create_backup, cli_level_to_log_level, ) -from redbot.core import config, data_manager, drivers -from redbot.core.cli import ExitCodes +from redbot.core import config, data_manager, _drivers +from redbot.core._cli import ExitCodes from redbot.core.data_manager import appdir, config_dir, config_file -from redbot.core.drivers import BackendType, IdentifierData +from redbot.core._drivers import BackendType, IdentifierData conversion_log = logging.getLogger("red.converter") @@ -211,7 +211,7 @@ def basic_setup( storage_type = get_storage_type(backend, interactive=interactive) default_dirs["STORAGE_TYPE"] = storage_type.value - driver_cls = drivers.get_driver_class(storage_type) + driver_cls = _drivers.get_driver_class(storage_type) default_dirs["STORAGE_DETAILS"] = driver_cls.get_config_details() if name in instance_data: @@ -262,8 +262,8 @@ def get_target_backend(backend: str) -> BackendType: async def do_migration( current_backend: BackendType, target_backend: BackendType ) -> Dict[str, Any]: - cur_driver_cls = drivers._get_driver_class_include_old(current_backend) - new_driver_cls = drivers.get_driver_class(target_backend) + cur_driver_cls = _drivers._get_driver_class_include_old(current_backend) + new_driver_cls = _drivers.get_driver_class(target_backend) cur_storage_details = data_manager.storage_details() new_storage_details = new_driver_cls.get_config_details() @@ -284,7 +284,7 @@ async def create_backup(instance: str, destination_folder: Path = Path.home()) - if backend_type != BackendType.JSON: await do_migration(backend_type, BackendType.JSON) print("Backing up the instance's data...") - driver_cls = drivers.get_driver_class() + driver_cls = _drivers.get_driver_class() await driver_cls.initialize(**data_manager.storage_details()) backup_fpath = await red_create_backup(destination_folder) await driver_cls.teardown() @@ -320,7 +320,7 @@ async def remove_instance( if _create_backup is True: await create_backup(instance) - driver_cls = drivers.get_driver_class(backend) + driver_cls = _drivers.get_driver_class(backend) if delete_data is True: await driver_cls.initialize(**data_manager.storage_details()) try: diff --git a/tests/conftest.py b/tests/conftest.py index 32038d835..cb5cb7c66 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,7 @@ import os import pytest from redbot import _update_event_loop_policy -from redbot.core import drivers, data_manager +from redbot.core import _drivers, data_manager _update_event_loop_policy() @@ -21,9 +21,9 @@ def event_loop(request): def _get_backend_type(): if os.getenv("RED_STORAGE_TYPE") == "postgres": - return drivers.BackendType.POSTGRES + return _drivers.BackendType.POSTGRES else: - return drivers.BackendType.JSON + return _drivers.BackendType.JSON @pytest.fixture(scope="session", autouse=True) @@ -32,7 +32,7 @@ async def _setup_driver(): storage_details = {} data_manager.storage_type = lambda: backend_type.value data_manager.storage_details = lambda: storage_details - driver_cls = drivers.get_driver_class(backend_type) + driver_cls = _drivers.get_driver_class(backend_type) await driver_cls.initialize(**storage_details) yield await driver_cls.teardown() diff --git a/tests/core/test_cog_manager.py b/tests/core/test_cog_manager.py index ac85e3290..2d3b132ed 100644 --- a/tests/core/test_cog_manager.py +++ b/tests/core/test_cog_manager.py @@ -3,7 +3,7 @@ from pathlib import Path import pytest from redbot.pytest.cog_manager import * -from redbot.core import cog_manager +from redbot.core import _cog_manager @pytest.mark.skip @@ -12,7 +12,7 @@ async def test_ensure_cogs_in_paths(cog_mgr, default_dir): assert cogs_dir in await cog_mgr.paths() -async def test_install_path_set(cog_mgr: cog_manager.CogManager, tmpdir): +async def test_install_path_set(cog_mgr: _cog_manager.CogManager, tmpdir): path = Path(str(tmpdir)) await cog_mgr.set_install_path(path) assert await cog_mgr.install_path() == path diff --git a/tests/core/test_rpc.py b/tests/core/test_rpc.py index 6565956b9..12e3c6b5e 100644 --- a/tests/core/test_rpc.py +++ b/tests/core/test_rpc.py @@ -1,7 +1,7 @@ import pytest from redbot.pytest.rpc import * -from redbot.core.rpc import get_name +from redbot.core._rpc import get_name def test_get_name(cog):