def load_extensions(self, directory: str, prefix: str = 'Recursive load'):
"""Loads extensions from a directory recursively."""
IGNORE = {'__init__.py', '__pycache__', '.DS_Store'}
base = directory.replace('/', '.')
# build list of extension stems
extension_stems = [
path.stem for path in Path(directory).resolve().iterdir() \
if path.name not in IGNORE and path.suffix != 'pyc'
]
logger.debug('Extensions to load: %s', extension_stems)
for ext in extension_stems:
load_path = base + '.' + ext
logger.info('%s: %s', prefix, load_path)
self.load_extension(load_path)
# keep track of a list of extensions to load
self._exts_to_load = list(self.extensions.keys()).copy()
评论列表
文章目录