aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-03-21 16:08:28 +0100
committerGravatar kwzrd <[email protected]>2020-03-21 16:09:20 +0100
commit4687bd4fb3348db9b151b3c8178631153a7b28e5 (patch)
tree3bdafc40a75b36a33cec5b7278a8e3b6330efc4d
parentDeseasonify: improve `get_seasons` convenience function (diff)
Deseasonify: simplify `get_extensions` convenience function
This is a little tricky, as we only want to walk the modules in each season's package. The pkgutil module provides a convenient function called `walk_packages` which can walk recursively, but this isn't desirable as not all modules are cogs - for example, the modules nested under `evergreen.snakes` are only helpers, and the `setup` function is instead present in the package's `__init__.py`. As we no longer have modules directly in the seasons package, we can remove the `ispkg` check.
-rw-r--r--bot/seasons/__init__.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/bot/seasons/__init__.py b/bot/seasons/__init__.py
index 8cefd156..7caaf615 100644
--- a/bot/seasons/__init__.py
+++ b/bot/seasons/__init__.py
@@ -157,18 +157,12 @@ def get_extensions() -> List[str]:
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")
+ base_path = Path(__path__[0])
extensions = []
- for package in pkgutil.iter_modules([base_path]):
-
- if package.ispkg:
- package_path = base_path.joinpath(package.name)
-
- for module in pkgutil.iter_modules([package_path]):
- extensions.append(f"bot.seasons.{package.name}.{module.name}")
- else:
- extensions.append(f"bot.seasons.{package.name}")
+ for season in get_season_names():
+ for module in pkgutil.iter_modules([base_path.joinpath(season)]):
+ extensions.append(f"bot.seasons.{season}.{module.name}")
return extensions