Coverage for sources/classcore/standard/dynadoc.py: 100%
24 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-05 22:50 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-05 22:50 +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''' Dynadoc integration. '''
24from .. import utilities as _utilities
25from . import __
26from . import nomina as _nomina
29dynadoc_context = __.dynadoc.produce_context( )
30dynadoc_class_introspection_control = (
31 __.dynadoc.ClassIntrospectionControl(
32 inheritance = True,
33 introspectors = (
34 __.dynadoc.introspection.introspect_special_classes, ) ) )
35dynadoc_module_introspection_control = (
36 __.dynadoc.ModuleIntrospectionControl( ) )
39def dynadoc_avoid_immutables(
40 objct: object,
41 introspection: __.dynadoc.IntrospectionControl,
42 attributes_namer: _nomina.AttributesNamer,
43) -> __.dynadoc.IntrospectionControl:
44 ''' Disables introspection of immutable objects. '''
45 if __.inspect.isclass( objct ):
46 behaviors_name = attributes_namer( 'class', 'behaviors' )
47 behaviors = _utilities.getattr0( objct, behaviors_name, frozenset( ) )
48 if _nomina.immutability_label in behaviors:
49 return introspection.with_limit(
50 __.dynadoc.IntrospectionLimit( disable = True ) )
51 return introspection
54def produce_dynadoc_introspection_limiter(
55 attributes_namer: _nomina.AttributesNamer = __.calculate_attrname,
56) -> __.dynadoc.IntrospectionLimiter:
57 ''' Produces introspection limiter which avoids immutable objects. '''
58 return __.funct.partial(
59 dynadoc_avoid_immutables, attributes_namer = attributes_namer )
61dynadoc_introspection_limiter = produce_dynadoc_introspection_limiter( )
64def produce_dynadoc_introspection_control(
65 enable: bool = True,
66 class_control: __.dynadoc.ClassIntrospectionControl = (
67 dynadoc_class_introspection_control ),
68 module_control: __.dynadoc.ModuleIntrospectionControl = (
69 dynadoc_module_introspection_control ),
70 limiters: __.dynadoc.IntrospectionLimiters = (
71 dynadoc_introspection_limiter, ),
72 targets: __.dynadoc.IntrospectionTargets = (
73 __.dynadoc.IntrospectionTargetsSansModule ),
74) -> __.dynadoc.IntrospectionControl:
75 ''' Produces compatible Dynadoc introspection control. '''
76 return __.dynadoc.IntrospectionControl(
77 enable = enable,
78 class_control = class_control,
79 module_control = module_control,
80 limiters = limiters,
81 targets = targets )
83dynadoc_introspection_on_class = produce_dynadoc_introspection_control( )
84dynadoc_introspection_on_package = (
85 produce_dynadoc_introspection_control(
86 targets = __.dynadoc.IntrospectionTargetsOmni ) )
89def assign_module_docstring( # noqa: PLR0913
90 module: str | __.types.ModuleType, /,
91 *fragments: __.dynadoc.interfaces.Fragment,
92 context: _nomina.DynadocContextArgument = dynadoc_context,
93 introspection: _nomina.DynadocIntrospectionArgument = (
94 dynadoc_introspection_on_package ),
95 preserve: _nomina.DynadocPreserveArgument = True,
96 renderer: __.dynadoc.xtnsapi.Renderer = (
97 __.dynadoc.assembly.renderer_default ),
98 table: _nomina.DynadocTableArgument = __.dictproxy_empty,
99) -> None:
100 ''' Updates module docstring based on introspection.
102 By default, recursively updates docstrings of all module members
103 which have docstrings.
105 By default, ignores previously-decorated immutable classes.
106 '''
107 __.dynadoc.assign_module_docstring(
108 module,
109 *fragments,
110 context = context,
111 introspection = introspection,
112 preserve = preserve,
113 renderer = renderer,
114 table = table )
117def produce_dynadoc_configuration(
118 context: _nomina.DynadocContextArgument = dynadoc_context,
119 introspection: _nomina.DynadocIntrospectionArgument = (
120 dynadoc_introspection_on_class ),
121 preserve: _nomina.DynadocPreserveArgument = True,
122 table: _nomina.DynadocTableArgument = __.dictproxy_empty,
123) -> _nomina.ProduceDynadocConfigurationReturn:
124 ''' Produces compatible Dynadoc configuration. '''
125 return __.types.MappingProxyType( dict(
126 context = context,
127 introspection = introspection,
128 preserve = preserve,
129 table = table ) )