Content-Length: 330845 | pFad | http://github.com/interactions-py/interactions.py/commit/f3ba43dc3b6b10b2f53bbabc2ff1f61f83da7f6e

D2 feat: add load_extensions method (#1530) · interactions-py/interactions.py@f3ba43d · GitHub
Skip to content

Commit f3ba43d

Browse files
feat: add load_extensions method (#1530)
* feat: add load_extensions method * chore: add documentation * ci: correct from checks. * refactor: change package parameter to *packages * refactor: remove stray print statement --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 450e38b commit f3ba43d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: interactions/client/client.py

+31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import asyncio
22
import contextlib
33
import functools
4+
import glob
45
import importlib.util
56
import inspect
67
import logging
8+
import os
79
import re
810
import sys
911
import time
@@ -2002,6 +2004,35 @@ def load_extension(
20022004
module = importlib.import_module(module_name, package)
20032005
self.__load_module(module, module_name, **load_kwargs)
20042006

2007+
def load_extensions(
2008+
self,
2009+
*packages: str,
2010+
recursive: bool = False,
2011+
) -> None:
2012+
"""
2013+
Load multiple extensions at once.
2014+
2015+
Removes the need of manually looping through the package
2016+
and loading the extensions.
2017+
2018+
Args:
2019+
*packages: The package(s) where the extensions are located.
2020+
recursive: Whether to load extensions from the subdirectories within the package.
2021+
"""
2022+
if not packages:
2023+
raise ValueError("You must specify at least one package.")
2024+
2025+
for package in packages:
2026+
# If recursive then include subdirectories ('**')
2027+
# otherwise just the package specified by the user.
2028+
pattern = os.path.join(package, "**" if recursive else "", "*.py")
2029+
2030+
# Find all files matching the pattern, and convert slashes to dots.
2031+
extensions = [f.replace(os.path.sep, ".").replace(".py", "") for f in glob.glob(pattern, recursive=True)]
2032+
2033+
for ext in extensions:
2034+
self.load_extension(ext)
2035+
20052036
def unload_extension(
20062037
self, name: str, package: str | None = None, force: bool = False, **unload_kwargs: Any
20072038
) -> None:

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/interactions-py/interactions.py/commit/f3ba43dc3b6b10b2f53bbabc2ff1f61f83da7f6e

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy