66def invokeConfig(func, *args, **kwargs):
67 from importlib import import_module
68
69 if not callable(func):
70 if isinstance(func, str):
71 m = CALLABLE_FORMAT.match(func)
72 if m and m.group("module"):
73 func = getattr(import_module(m.group("module")), m.group("callable"))
74 elif m and m.group("path"):
75 globals = {"__file__": m.group("path")}
76 exec(
77 compile(
78 open(m.group("path"), "rb").read(), m.group("path"), "exec"
79 ),
80 globals,
81 )
82 func = globals[m.group("callable")]
83 else:
84 raise ValueError("invalid callable id %r" % func)
85 else:
86 raise TypeError("expected either a callable or a string as first argument")
87 return _makeConfigDict(func(*args, **kwargs))