Coverage for sources/dynadoc/factories.py: 100%
11 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-05-25 22:29 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-05-25 22:29 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
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#============================================================================#
21''' Factories and registries. '''
22# TODO? Registry for deferred decoration.
25from . import __
26from . import xtnsapi as _xtnsapi
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 ), ) )
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.Annotation: return fragment.strip( )
43 case _xtnsapi.FragmentSources.Renderer: return fragment.strip( )
44 case _: return __.inspect.cleandoc( fragment ).rstrip( )
47def produce_context( # noqa: PLR0913
48 invoker_globals: _xtnsapi.InvokerGlobalsArgument = None,
49 resolver_globals: _xtnsapi.ResolverGlobalsArgument = None,
50 resolver_locals: _xtnsapi.ResolverLocalsArgument = None,
51 notifier: _xtnsapi.NotifierArgument = notify,
52 fragment_rectifier: _xtnsapi.FragmentRectifierArgument = (
53 rectify_fragment ),
54 visibility_decider: _xtnsapi.VisibilityDeciderArgument = (
55 _xtnsapi.is_attribute_visible ),
56 fragments_name: _xtnsapi.FragmentsNameArgument = (
57 _xtnsapi.fragments_name_default ),
58 introspection_limit_name: _xtnsapi.IntrospectionLimitNameArgument = (
59 _xtnsapi.introspection_limit_name_default ),
60) -> _xtnsapi.Context:
61 ''' Produces context data transfer object.
63 Reasonable defaults are used for arguments that are not supplied.
64 '''
65 return _xtnsapi.Context(
66 notifier = notifier,
67 fragment_rectifier = fragment_rectifier,
68 visibility_decider = visibility_decider,
69 invoker_globals = invoker_globals,
70 resolver_globals = resolver_globals,
71 resolver_locals = resolver_locals )