(path: str)
| 44 | |
| 45 | |
| 46 | def import_object(path: str) -> object: |
| 47 | if path.startswith("pw.") or path.startswith("pw:"): |
| 48 | path = "pathway" + path.removeprefix("pw") |
| 49 | |
| 50 | module_path, colon, attribute_path = path.partition(":") |
| 51 | |
| 52 | attributes = attribute_path.split(".") if attribute_path else [] |
| 53 | |
| 54 | module = builtins |
| 55 | if not colon: |
| 56 | names = module_path.split(".") if module_path else [] |
| 57 | for index, name in enumerate(names): |
| 58 | prefix = ".".join(names[: index + 1]) |
| 59 | try: |
| 60 | module = importlib.import_module(prefix) |
| 61 | except ModuleNotFoundError: |
| 62 | attributes = names[index:] |
| 63 | break |
| 64 | elif module_path: |
| 65 | module = importlib.import_module(module_path) |
| 66 | |
| 67 | res = module |
| 68 | for attribute in attributes: |
| 69 | res = getattr(res, attribute) |
| 70 | |
| 71 | return res |
| 72 | |
| 73 | |
| 74 | class PathwayYamlLoader(yaml.Loader): |
no test coverage detected