MCPcopy Index your code
hub / github.com/pathwaycom/pathway / import_object

Function import_object

python/pathway/internals/yaml_loader.py:46–71  ·  view source on GitHub ↗
(path: str)

Source from the content-addressed store, hash-verified

44
45
46def 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
74class PathwayYamlLoader(yaml.Loader):

Callers 1

Calls 4

startswithMethod · 0.80
removeprefixMethod · 0.80
splitMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected