(self, path)
| 28 | self.loaded: Dict[str, Any] = dict() |
| 29 | |
| 30 | def load_from(self, path) -> Dict: |
| 31 | path = os.path.realpath(path) |
| 32 | if path in self.loading: |
| 33 | raise Exception("Circular import detected: {}".format(path)) |
| 34 | if path in self.loaded: |
| 35 | return deepcopy(self.loaded[path]) |
| 36 | if not os.path.exists(path): |
| 37 | raise Exception("File not found: {}".format(path)) |
| 38 | if path.endswith(".yaml") or path.endswith(".yml"): |
| 39 | with open(path) as f: |
| 40 | config = yaml.safe_load(f) |
| 41 | elif path.endswith(".json"): |
| 42 | with open(path) as f: |
| 43 | config = json.load(f) |
| 44 | else: |
| 45 | raise Exception("Unknown file type: {}".format(path)) |
| 46 | self.loading.add(path) |
| 47 | try: |
| 48 | config = self.parse_imports(os.path.dirname(path), config) |
| 49 | except Exception as e: |
| 50 | self.loading.remove(path) |
| 51 | raise e |
| 52 | self.loading.remove(path) |
| 53 | self.loaded[path] = config |
| 54 | return self.parse_default_and_overwrite(deepcopy(config)) |
| 55 | |
| 56 | def parse_imports(self, path, raw_config): |
| 57 | raw_config = deepcopy(raw_config) |
no test coverage detected