def considerImplicitImports(self, module, signal_change): """Provide additional modules to import implicitly when encountering the module. Notes: Better do not overload this method. The standard plugin 'ImplicitImports.py' already contains MANY of these. If you do have a new candidate, consider a PR to get it included there. Args: module: the module object signal_change: bool Returns: None """ from nuitka.importing.Importing import getModuleNameAndKindFromFilename for full_name in self.getImplicitImports(module): if type(full_name) in (tuple, list): raise NuitkaPluginError( "Plugin %s needs to be change to only return modules names, not %r" % (self, full_name)) full_name = ModuleName(full_name) try: module_filename = self.locateModule(importing=module, module_name=full_name) except Exception: self.warning("Problem locating '%s' implicit imports '%s'." % (module.getFullName(), full_name)) raise if module_filename is None: if Options.isShowInclusion(): self.info( "Implicit module '%s' suggested by '%s' not found." % (full_name, module.getFullName())) continue _module_name2, module_kind = getModuleNameAndKindFromFilename( module_filename) # TODO: This should get back to plug-ins, they should be allowed to # preempt or override the decision. decision, reason = self.decideRecursion( module_filename=module_filename, module_name=full_name, module_kind=module_kind, ) if decision: self.recurseTo( module_package=full_name.getPackageName(), module_filename=module_filename, module_kind=module_kind, reason=reason, signal_change=signal_change, )
def _considerImplicitImports(plugin, module): from nuitka.importing import Importing result = [] for full_name in plugin.getImplicitImports(module): if type(full_name) in (tuple, list): raise NuitkaPluginError( "Plugin %r needs to be change to only return modules names, not %r" % (plugin, full_name) ) full_name = ModuleName(full_name) try: _module_package, module_filename, _finding = Importing.findModule( importing=module, module_name=full_name, parent_package=None, level=-1, warn=False, ) module_filename = plugin.locateModule( importing=module, module_name=full_name ) except Exception: plugin.warning( "Problem locating '%s' for implicit imports of '%s'." % (module.getFullName(), full_name) ) raise if module_filename is None: if Options.isShowInclusion(): plugin.info( "Implicit module '%s' suggested for '%s' not found." % (full_name, module.getFullName()) ) continue result.append((full_name, module_filename)) if result: plugin.info( "Implicit dependencies of module '%s' added '%s'." % (module.getFullName(), ",".join(r[0] for r in result)) ) return result