def file_contains_pluggable(file_path, pluggable):
plugin_class = None
try:
with open(file_path, "r") as f:
syntax_tree = ast.parse(f.read())
except FileNotFoundError:
return [False, None]
for statement in ast.walk(syntax_tree):
if isinstance(statement, ast.ClassDef):
class_name = statement.name
bases = list(map(lambda b: b.id if isinstance(b, ast.Name) else b.attr, statement.bases))
if pluggable in bases:
plugin_class = class_name
return [plugin_class is not None, plugin_class]
评论列表
文章目录