Resolve an OmegaConf variable path to its value.
(variable_path: str)
| 14 | |
| 15 | |
| 16 | def resolve_omegaconf_variable(variable_path: str) -> Any: |
| 17 | """Resolve an OmegaConf variable path to its value.""" |
| 18 | # split the string into parts using the dot separator |
| 19 | parts = variable_path.rsplit(".", 1) |
| 20 | |
| 21 | # get the module name from the first part of the path |
| 22 | module_name = parts[0] |
| 23 | |
| 24 | # dynamically import the module using the module name |
| 25 | try: |
| 26 | module = importlib.import_module(module_name) |
| 27 | # use the imported module to get the requested attribute value |
| 28 | attribute = getattr(module, parts[1]) |
| 29 | except Exception: |
| 30 | module = importlib.import_module(".".join(module_name.split(".")[:-1])) |
| 31 | inner_module = ".".join(module_name.split(".")[-1:]) |
| 32 | # use the imported module to get the requested attribute value |
| 33 | attribute = getattr(getattr(module, inner_module), parts[1]) |
| 34 | |
| 35 | return attribute |
| 36 | |
| 37 | |
| 38 | def resolve_dataset_path_dirname(dataset: str) -> str: |
no test coverage detected