Files
mongo/buildscripts/resmokelib/utils/autoloader.py
Steve McClure b4b23946cd SERVER-90570: Enable formatting checks for buildscripts directory, excluding idl (#22254)
GitOrigin-RevId: 9d997a9f44cd43a8dec7c2a17fa2dbcd875e92f6
2024-05-16 22:07:36 +00:00

23 lines
677 B
Python

"""Utility for loading all modules within a package."""
import importlib
import pkgutil
def load_all_modules(name, path):
"""Dynamically load all modules in the 'name' package.
This function is useful in combination with the registry.py module
so that any classes declared within the package are automatically
registered.
The following is the intended usage within the __init__.py file for
a package:
from utils import autoloader as _autoloader
_autoloader.load_all_modules(name=__name__, path=__path__)
"""
for _, module, _ in pkgutil.walk_packages(path=path):
importlib.import_module("." + module, package=name)