MCPcopy
hub / github.com/Nuitka/Nuitka / decideRecursion

Function decideRecursion

nuitka/importing/Recursion.py:159–224  ·  view source on GitHub ↗

Decide if we should recurse into a module. This function caches its results and handles the logic to decide if a module should be included in the compilation or not. It respects the user choices, plugins, and standard library rules. Args: using_module_name: The module name

(
    using_module_name, module_filename, module_name, module_kind, extra_recursion=False
)

Source from the content-addressed store, hash-verified

157
158
159def decideRecursion(
160 using_module_name, module_filename, module_name, module_kind, extra_recursion=False
161):
162 """Decide if we should recurse into a module.
163
164 This function caches its results and handles the logic to decide if a
165 module should be included in the compilation or not. It respects the
166 user choices, plugins, and standard library rules.
167
168 Args:
169 using_module_name: The module name that triggers this recursion.
170 module_filename: The filename of the module.
171 module_name: The name of the module.
172 module_kind: The kind of the module.
173 extra_recursion: If true, this is a forced recursion (e.g. plugin).
174
175 Returns:
176 A tuple (decision, reason) where decision is a boolean or None, and
177 reason is a string explaining the decision.
178 """
179 package_part, _remainder = module_name.splitModuleBasename()
180
181 if package_part is not None and package_part.getTopLevelPackageName() != "":
182 (
183 _package_part,
184 package_filename,
185 package_module_kind,
186 package_finding,
187 ) = locateModule(module_name=package_part, parent_package=None, level=0)
188 assert _package_part == package_part, (_package_part, package_part)
189
190 # For bad decisions, this may already not work.
191 if package_finding != "not-found":
192 package_decision, package_reason = decideRecursion(
193 using_module_name=using_module_name,
194 module_filename=package_filename,
195 module_name=package_part,
196 module_kind=package_module_kind,
197 extra_recursion=extra_recursion,
198 )
199
200 if package_decision is False:
201 return package_decision, package_reason
202
203 key = using_module_name, module_filename, module_name, module_kind, extra_recursion
204
205 if key not in _recursion_decision_cache:
206 _recursion_decision_cache[key] = _decideRecursion(
207 using_module_name,
208 module_filename,
209 module_name,
210 module_kind,
211 extra_recursion,
212 )
213
214 # If decided true, give the plugins a chance to e.g. add more hard
215 # module information, this indicates tentatively, that a module might
216 # get used, but it may also not happen at all.

Callers 6

__init__Method · 0.90
attemptRecursionMethod · 0.90
_lookAheadFunction · 0.90
scanPluginSinglePathFunction · 0.85
considerUsedModulesFunction · 0.85

Calls 5

onModuleUsageLookAheadFunction · 0.90
locateModuleFunction · 0.85
_decideRecursionFunction · 0.85
splitModuleBasenameMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…