Coverage for sources/ictr/standard/flavors.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-26 12:43 +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''' Standard flavors, flavor aliases, etc.... ''' 

22 

23 

24from . import __ 

25from . import compositors as _compositors 

26from . import introducers as _intros 

27 

28 

29def produce_flavors( 

30 introducercfg: _intros.IntroducerConfiguration = ( 

31 _intros.INTRODUCER_CONFIGURATION_DEFAULT ), 

32 compositorcfg: _compositors.CompositorConfiguration = ( 

33 _compositors.COMPOSITOR_CONFIGURATION_DEFAULT ), 

34) -> __.FlavorsRegistry: 

35 ''' Produces registry of all standard flavors. 

36 

37 Customization of introducers and compositors is possible. 

38 ''' 

39 flavors: __.FlavorsRegistryLiberal = { } 

40 introducer = _intros.Introducer( configuration = introducercfg ) 

41 compositor = _compositors.Compositor( 

42 configuration = compositorcfg, introducer = introducer ) 

43 for name, spec in __.flavor_specifications_standard.items( ): 

44 ccfg = compositorcfg 

45 if spec.stack: 

46 lcfg = ccfg.linearizercfg 

47 ecfg = __.dcls.replace( 

48 lcfg.exceptionscfg, 

49 enable_discovery = True, 

50 enable_stacktraces = True ) 

51 lcfg = __.dcls.replace( lcfg, exceptionscfg = ecfg ) 

52 ccfg = __.dcls.replace( ccfg, linearizercfg = lcfg ) 

53 compositor = _compositors.Compositor( 

54 configuration = ccfg, introducer = introducer ) 

55 flavors[ name ] = __.FlavorConfiguration( 

56 compositor_factory = _produce_compositor_factory( compositor ) ) 

57 for alias, name in __.flavor_aliases_standard.items( ): 

58 flavors[ alias ] = flavors[ name ] 

59 for level in range( 10 ): 

60 indent_i = ' ' * level 

61 indent_s = ' ' * ( level + 1 ) 

62 ccfg = __.dcls.replace( 

63 compositorcfg, 

64 line_prefix_initial = indent_i, 

65 line_prefix_subsequent = indent_s ) 

66 compositor = _compositors.Compositor( 

67 configuration = ccfg, introducer = introducer ) 

68 flavors[ level ] = __.FlavorConfiguration( 

69 compositor_factory = _produce_compositor_factory( compositor ) ) 

70 return __.immut.Dictionary( flavors ) 

71 

72 

73def _produce_compositor_factory( 

74 compositor: _compositors.Compositor 

75) -> __.CompositorFactory: 

76 return lambda address, flavor: compositor