| 1256 | |
| 1257 | @attr.s(frozen=True) |
| 1258 | class CallableEntryPoint(object): |
| 1259 | module = attr.ib() # type: str |
| 1260 | attrs = attr.ib() # type: Tuple[str, ...] |
| 1261 | |
| 1262 | @attrs.validator |
| 1263 | def _validate_attrs(self, _, value): |
| 1264 | if not value: |
| 1265 | raise ValueError("A callable entry point must select a callable item from the module.") |
| 1266 | |
| 1267 | def resolve(self): |
| 1268 | # type: () -> Callable[[], Any] |
| 1269 | module = importlib.import_module(self.module) |
| 1270 | try: |
| 1271 | return cast("Callable[[], Any]", functools.reduce(getattr, self.attrs, module)) |
| 1272 | except AttributeError as e: |
| 1273 | raise ImportError( |
| 1274 | "Could not resolve {attrs} in {module}: {err}".format( |
| 1275 | attrs=".".join(self.attrs), module=module, err=e |
| 1276 | ) |
| 1277 | ) |
| 1278 | |
| 1279 | def __str__(self): |
| 1280 | # type: () -> str |
| 1281 | return "{module}:{attrs}".format(module=self.module, attrs=".".join(self.attrs)) |
| 1282 | |
| 1283 | |
| 1284 | def parse_entry_point(value): |
no outgoing calls