Coverage for openhcs/config_framework/config.py: 80.0%

8 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-01 18:33 +0000

1""" 

2Framework configuration for pluggable base config type. 

3 

4This module provides the configuration interface for the lazy configuration framework, 

5allowing applications to specify their base configuration type. 

6 

7The framework uses pure MRO-based resolution. The dual-axis resolution works by: 

81. X-axis: Context flattening (Step → Pipeline → Global contexts merged) 

92. Y-axis: MRO traversal (most specific → least specific class in inheritance chain) 

10 

11You only need to call set_base_config_type() once at application startup. 

12""" 

13 

14from typing import Type, Optional 

15 

16 

17# Global framework configuration 

18_base_config_type: Optional[Type] = None 

19 

20 

21def set_base_config_type(config_type: Type) -> None: 

22 """ 

23 Set the base configuration type for the framework. 

24  

25 This type is used as the root of the configuration hierarchy and should be 

26 the top-level configuration dataclass for your application. 

27  

28 Args: 

29 config_type: The base configuration dataclass type 

30  

31 Example: 

32 >>> from myapp.config import GlobalConfig 

33 >>> from openhcs.config_framework.config import set_base_config_type 

34 >>> set_base_config_type(GlobalConfig) 

35 """ 

36 global _base_config_type 

37 _base_config_type = config_type 

38 

39 

40def get_base_config_type() -> Type: 

41 """ 

42 Get the base configuration type. 

43  

44 Returns: 

45 The base configuration type 

46  

47 Raises: 

48 RuntimeError: If base config type has not been set 

49 """ 

50 if _base_config_type is None: 50 ↛ 51line 50 didn't jump to line 51 because the condition on line 50 was never true

51 raise RuntimeError( 

52 "Base config type not set. Call set_base_config_type() during " 

53 "application initialization." 

54 ) 

55 return _base_config_type 

56 

57