diff options
author | 2021-07-17 20:10:11 +0100 | |
---|---|---|
committer | 2021-07-17 20:10:11 +0100 | |
commit | d3d81582cd7005df16fe3f5306e6afbed75bdb74 (patch) | |
tree | 323a7441f6c4d32833fee922208121497c77a9de /arthur/extensions.py |
Initial commit
Diffstat (limited to 'arthur/extensions.py')
-rw-r--r-- | arthur/extensions.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/arthur/extensions.py b/arthur/extensions.py new file mode 100644 index 0000000..2170d68 --- /dev/null +++ b/arthur/extensions.py @@ -0,0 +1,15 @@ +"""Utilities for working with extensions.""" +from pathlib import Path +from typing import Generator + + +def find_extensions() -> Generator[tuple[Path, str], None, None]: + """Search the exts directory to find cogs to load.""" + for path in Path("arthur/exts").rglob("**/*.py"): + # Convert a path like "arthur/exts/foo/bar.py" to "arthur.exts.foo.bar" + yield path, path_to_module(path) + + +def path_to_module(path: Path) -> str: + """Convert a path like "arthur/exts/foo/bar.py" to "arthur.exts.foo.bar".""" + return str(path.parent.as_posix()).replace("/", ".") + f".{path.stem}" |