Coverage for sources/dynadoc/factories.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-02 23:49 +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''' Factories and registries. ''' 

22# TODO? Registry for deferred decoration. 

23 

24 

25from . import __ 

26from . import xtnsapi as _xtnsapi 

27 

28 

29# _package_location = __.Path( __file__ ).parent 

30def notify( level: _xtnsapi.NotificationLevels, message: str ) -> None: 

31 # TODO: Python 3.12: Use 'skip_file_prefixes' option. 

32 ''' Issues warning message. ''' 

33 __.warnings.warn( message, category = RuntimeWarning, stacklevel = 2 ) 

34 # skip_file_prefixes = ( str( _package_location ), ) ) 

35 

36 

37def rectify_fragment( 

38 fragment: str, source: _xtnsapi.FragmentSources 

39) -> str: 

40 ''' Cleans and normalizes fragment according to source. ''' 

41 match source: 

42 case _xtnsapi.FragmentSources.Renderer: return fragment.strip( ) 

43 case _: return __.inspect.cleandoc( fragment ).rstrip( ) 

44 

45 

46def produce_context( # noqa: PLR0913 

47 invoker_globals: _xtnsapi.InvokerGlobalsArgument = None, 

48 resolver_globals: _xtnsapi.ResolverGlobalsArgument = None, 

49 resolver_locals: _xtnsapi.ResolverLocalsArgument = None, 

50 notifier: _xtnsapi.NotifierArgument = notify, 

51 fragment_rectifier: _xtnsapi.FragmentRectifierArgument = ( 

52 rectify_fragment ), 

53 visibility_decider: _xtnsapi.VisibilityDeciderArgument = ( 

54 _xtnsapi.is_attribute_visible ), 

55 fragments_name: _xtnsapi.FragmentsNameArgument = ( 

56 _xtnsapi.fragments_name_default ), 

57 introspection_limit_name: _xtnsapi.IntrospectionLimitNameArgument = ( 

58 _xtnsapi.introspection_limit_name_default ), 

59) -> _xtnsapi.Context: 

60 ''' Produces context data transfer object. 

61 

62 Reasonable defaults are used for arguments that are not supplied. 

63 ''' 

64 return _xtnsapi.Context( 

65 notifier = notifier, 

66 fragment_rectifier = fragment_rectifier, 

67 visibility_decider = visibility_decider, 

68 invoker_globals = invoker_globals, 

69 resolver_globals = resolver_globals, 

70 resolver_locals = resolver_locals )