Coverage for heritrace/component_options.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-26 08:34 +0000

1# SPDX-FileCopyrightText: 2026 Arcangelo Massari <arcangelo.massari@unibo.it> 

2# 

3# SPDX-License-Identifier: ISC 

4 

5import json 

6import os 

7from typing import cast 

8 

9 

10def load_component_options(environment_variable: str) -> dict[str, object]: 

11 if environment_variable not in os.environ: 

12 return {} 

13 

14 try: 

15 options: object = json.loads(os.environ[environment_variable]) 

16 except json.JSONDecodeError as error: 

17 msg = f"{environment_variable} must contain a valid JSON object" 

18 raise ValueError(msg) from error 

19 

20 if not isinstance(options, dict): 

21 msg = f"{environment_variable} must contain a JSON object" 

22 raise TypeError(msg) 

23 

24 return cast("dict[str, object]", options)