本文整理汇总了Python中importlib.machinery.SourceFileLoader.make_struct方法的典型用法代码示例。如果您正苦于以下问题:Python SourceFileLoader.make_struct方法的具体用法?Python SourceFileLoader.make_struct怎么用?Python SourceFileLoader.make_struct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类importlib.machinery.SourceFileLoader
的用法示例。
在下文中一共展示了SourceFileLoader.make_struct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from importlib.machinery import SourceFileLoader [as 别名]
# 或者: from importlib.machinery.SourceFileLoader import make_struct [as 别名]
def load(path):
path = pathlib.Path(path) # I hate lines like this so much.
name = path.stem
logging.debug("Loading '%s' definition from %s", name, path)
with path.open() as f:
specs = list(csv.DictReader(f, delimiter="\t"))
base = define_struct(name, specs)
modpath = path.parent.joinpath(name + '.py')
logging.debug("Looking for make_struct hook in %s", modpath)
try:
module = SourceFileLoader(name, str(modpath)).load_module()
except FileNotFoundError:
msg = "Nothing at %s, skipping"
logging.debug(msg, modpath)
return base
if not hasattr(module, "make_struct"):
msg = "%s doesn't contain make_struct, skipping"
logging.debug(msg, modpath)
return base
msg = "Processing hook %s.make_struct for '%s' in %s"
logging.debug(msg, module.__name__, name, path)
newbase = module.make_struct(base)
if not isinstance(newbase, type) or not issubclass(newbase, base):
msg = ("{}.make_struct() in {} failed to return subclass of {}; "
"actually returned: {}")
msg = msg.format(module.__name__, path, base.__name__, newbase)
raise Exception(msg)
return newbase