Coverage for sources / ictr / configuration.py: 100%

26 statements  

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

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Portions of configuration hierarchy. ''' 

22 

23 

24from . import __ 

25from . import flavors as _flavors 

26from . import textualizers as _texts 

27 

28 

29class FlavorConfiguration( __.immut.DataclassObject ): 

30 ''' Per-flavor configuration. ''' 

31 

32 compositor_factory: __.typx.Annotated[ 

33 __.typx.Optional[ _texts.CompositorFactory ], 

34 __.typx.Doc( 

35 ''' Factory which produces compositor callable. 

36 

37 Takes address and flavor as arguments. Returns compositor. 

38 

39 Default ``None`` inherits from cumulative configuration. 

40 ''' ), 

41 ] = None 

42 

43 

44FlavorsRegistry: __.typx.TypeAlias = ( 

45 __.immut.Dictionary[ _flavors.Flavor, FlavorConfiguration ] ) 

46FlavorsRegistryLiberal: __.typx.TypeAlias = ( 

47 __.cabc.Mapping[ _flavors.Flavor, FlavorConfiguration ] ) 

48 

49 

50def produce_flavors_default( ) -> FlavorsRegistry: 

51 ''' Produces registry of all standard flavors without customization. ''' 

52 flavors: FlavorsRegistryLiberal = { } 

53 for name, spec in _flavors.flavor_specifications_standard.items( ): 

54 tfactory = _texts.produce_compositor_factory_default( 

55 introducer = f"{spec.label}| ", trace_exceptions = spec.stack ) 

56 flavors[ name ] = FlavorConfiguration( 

57 compositor_factory = tfactory ) 

58 for alias, name in _flavors.flavor_aliases_standard.items( ): 

59 flavors[ alias ] = flavors[ name ] 

60 for level in range( 10 ): 

61 indent_i = ' ' * level 

62 indent_s = ' ' * ( level + 1 ) 

63 tfactory = _texts.produce_compositor_factory_default( 

64 introducer = f"TRACE{level}| ", 

65 line_prefix_initial = indent_i, 

66 line_prefix_subsequent = indent_s ) 

67 flavors[ level ] = FlavorConfiguration( 

68 compositor_factory = tfactory ) 

69 return __.immut.Dictionary( flavors ) 

70 

71 

72class AddressConfiguration( __.immut.DataclassObject ): 

73 ''' Per-address configuration. ''' 

74 

75 compositor_factory: __.typx.Annotated[ 

76 __.typx.Optional[ _texts.CompositorFactory ], 

77 __.typx.Doc( 

78 ''' Factory which produces compositor callable. 

79 

80 Takes address and flavor as arguments. Returns compositor. 

81 

82 Default ``None`` inherits from cumulative configuration. 

83 ''' ), 

84 ] = None 

85 flavors: __.typx.Annotated[ 

86 FlavorsRegistry, 

87 __.typx.Doc( 

88 ''' Registry of flavor identifiers to configurations. ''' ), 

89 ] = __.dcls.field( default_factory = FlavorsRegistry ) 

90 

91 

92class DispatcherConfiguration( __.immut.DataclassObject ): 

93 ''' Per-dispatcher configuration. ''' 

94 

95 compositor_factory: __.typx.Annotated[ 

96 _texts.CompositorFactory, 

97 __.typx.Doc( 

98 ''' Factory which produces compositor callable. 

99 

100 Takes address and flavor as arguments. Returns compositor. 

101 ''' ), 

102 ] = _texts.produce_compositor_factory_default( ) 

103 flavors: __.typx.Annotated[ 

104 FlavorsRegistry, 

105 __.typx.Doc( 

106 ''' Registry of flavor identifiers to configurations. ''' ), 

107 ] = __.dcls.field( default_factory = produce_flavors_default )