diff options
author | 2020-03-07 13:25:47 +0100 | |
---|---|---|
committer | 2020-03-07 13:25:47 +0100 | |
commit | 89bd07acf2a32ace0679d85fb5d98d234ac064a1 (patch) | |
tree | 1c12195e22203d5e5ebb5fe1fb9681ab5597aa2c | |
parent | Deseasonify: move `get_seasons` util function to package init (diff) |
Deseasonify: add `get_extensions` helper function
See docstring for further details.
-rw-r--r-- | bot/seasons/__init__.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/bot/seasons/__init__.py b/bot/seasons/__init__.py index 4f091116..af270901 100644 --- a/bot/seasons/__init__.py +++ b/bot/seasons/__init__.py @@ -5,7 +5,7 @@ from typing import List from bot.seasons.season import SeasonBase -__all__ = ("SeasonBase", "get_seasons") +__all__ = ("SeasonBase", "get_seasons", "get_extensions") log = logging.getLogger(__name__) @@ -18,3 +18,22 @@ def get_seasons() -> List[str]: if module.ispkg: seasons.append(module.name) return seasons + + +def get_extensions() -> List[str]: + """ + Give a list of dot-separated paths to all extensions. + + The strings are formatted in a way such that the bot's `load_extension` + method can take them. Use this to load all available extensions. + """ + base_path = Path("bot", "seasons") + extensions = [] + + for package in pkgutil.iter_modules([base_path]): + package_path = base_path.joinpath(package.name) + + for module in pkgutil.iter_modules([package_path]): + extensions.append(f"bot.seasons.{package.name}.{module.name}") + + return extensions |