1
0
Fork 0
mirror of synced 2024-06-21 00:11:10 -04:00
dotbot/dotbot/util/module.py
Anish Athalye 81d4a434ef Drop support for Python 2 and Python < 3.6
This patch also deletes all of the compatibility code that we no longer
need.
2023-09-09 20:57:01 -04:00

34 lines
909 B
Python

import os
import sys
from dotbot.plugin import Plugin
# We keep references to loaded modules so they don't get garbage collected.
loaded_modules = []
def load(path):
basename = os.path.basename(path)
module_name, extension = os.path.splitext(basename)
loaded_module = load_module(module_name, path)
plugins = []
for name in dir(loaded_module):
possible_plugin = getattr(loaded_module, name)
try:
if issubclass(possible_plugin, Plugin) and possible_plugin is not Plugin:
plugins.append(possible_plugin)
except TypeError:
pass
loaded_modules.append(loaded_module)
return plugins
import importlib.util
def load_module(module_name, path):
spec = importlib.util.spec_from_file_location(module_name, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module