def _reportImplicitImports(implicit_imports, signal_change): from nuitka.importing import Recursion from nuitka.importing.Importing import getModuleNameAndKindFromFilename for full_name, module_filename in implicit_imports: _module_name2, module_kind = getModuleNameAndKindFromFilename( module_filename) # This will get back to all other plugins allowing them to inhibit it though. decision, reason = Recursion.decideRecursion( module_filename=module_filename, module_name=full_name, module_kind=module_kind, ) if decision: imported_module, added_flag = Recursion.recurseTo( module_package=full_name.getPackageName(), module_filename=module_filename, module_relpath=relpath(module_filename), module_kind=module_kind, reason=reason, ) addUsedModule(imported_module) if added_flag: signal_change( "new_code", imported_module.getSourceReference(), "Recursed to module.", )
def _reportImplicitImports(plugin, module, implicit_imports, signal_change): from nuitka.importing import Recursion from nuitka.importing.Importing import getModuleNameAndKindFromFilename for full_name, module_filename in implicit_imports: _module_name2, module_kind = getModuleNameAndKindFromFilename( module_filename) # This will get back to all other plugins allowing them to inhibit it though. decision, reason = Recursion.decideRecursion( module_filename=module_filename, module_name=full_name, module_kind=module_kind, ) if decision: imported_module = Recursion.recurseTo( signal_change=signal_change, module_name=full_name, module_filename=module_filename, module_kind=module_kind, reason=reason, ) addUsedModule( module=imported_module, using_module=module, usage_tag="plugin:" + plugin.plugin_name, reason=reason, source_ref=module.source_ref, )
def createNodeTree(filename): """ Create a node tree. Turn that source code into a node tree structure. If recursion into imported modules is available, more trees will be available during optimization, or immediately through recursed directory paths. """ # First, build the raw node tree from the source code. main_module = Building.buildModuleTree( filename = filename, package = None, is_top = True, is_main = not Options.shallMakeModule() ) ModuleRegistry.addRootModule(main_module) # First remove old object files and old generated files, old binary or # module, and standalone mode program directory if any, they can only do # harm. source_dir = getSourceDirectoryPath(main_module) if not Options.shallOnlyExecCppCall(): cleanSourceDirectory(source_dir) # Prepare the ".dist" directory, throwing away what was there before. if Options.isStandaloneMode(): standalone_dir = getStandaloneDirectoryPath(main_module) shutil.rmtree(standalone_dir, ignore_errors = True) Utils.makePath(standalone_dir) Utils.deleteFile( path = getResultFullpath(main_module), must_exist = False ) # Second, do it for the directories given. for plugin_filename in Options.getShallFollowExtra(): Recursion.checkPluginPath( plugin_filename = plugin_filename, module_package = None ) for pattern in Options.getShallFollowExtraFilePatterns(): Recursion.checkPluginFilenamePattern( pattern = pattern ) # Then optimize the tree and potentially recursed modules. Optimization.optimize() return main_module
def createNodeTree(filename): """ Create a node tree. Turn that source code into a node tree structure. If recursion into imported modules is available, more trees will be available during optimization, or immediately through recursed directory paths. """ # First, build the raw node tree from the source code. main_module = Building.buildModuleTree( filename=filename, package=None, is_top=True, is_main=not Options.shallMakeModule()) ModuleRegistry.addRootModule(main_module) # First remove old object files and old generated files, old binary or # module, and standalone mode program directory if any, they can only do # harm. source_dir = getSourceDirectoryPath(main_module) if not Options.shallOnlyExecCppCall(): cleanSourceDirectory(source_dir) # Prepare the ".dist" directory, throwing away what was there before. if Options.isStandaloneMode(): standalone_dir = getStandaloneDirectoryPath(main_module) shutil.rmtree(standalone_dir, ignore_errors=True) Utils.makePath(standalone_dir) Utils.deleteFile(path=getResultFullpath(main_module), must_exist=False) # Second, do it for the directories given. for plugin_filename in Options.getShallFollowExtra(): Recursion.checkPluginPath(plugin_filename=plugin_filename, module_package=None) for pattern in Options.getShallFollowExtraFilePatterns(): Recursion.checkPluginFilenamePattern(pattern=pattern) # Then optimize the tree and potentially recursed modules. Optimization.optimize() if Options.isExperimental(): for module in ModuleRegistry.getRootModules(): if module.isMainModule(): return module assert False else: # Main module might change behind our back, look it up again. return main_module
def decideRecursion(module_filename, module_name, module_package, module_kind): from nuitka.importing import Recursion decision, reason = Recursion.decideRecursion( module_filename=module_filename, module_name=module_name, module_package=module_package, module_kind=module_kind) return decision, reason
def decideRecursion(module_filename, module_name, module_package, module_kind): from nuitka.importing import Recursion decision, reason = Recursion.decideRecursion( module_filename=module_filename, module_name=module_name, module_package=module_package, module_kind=module_kind, ) return decision, reason
def recurseTo(module_package, module_filename, module_kind, reason, signal_change): from nuitka.importing import Recursion imported_module, added_flag = Recursion.recurseTo( module_package=module_package, module_filename=module_filename, module_relpath=Utils.relpath(module_filename), module_kind=module_kind, reason=reason, ) addUsedModule(imported_module) if added_flag: signal_change("new_code", imported_module.getSourceReference(), "Recursed to module.")
def recurseTo(module_package, module_filename, module_kind, reason, signal_change): from nuitka.importing import Recursion imported_module, added_flag = Recursion.recurseTo( module_package=module_package, module_filename=module_filename, module_relpath=relpath(module_filename), module_kind=module_kind, reason=reason) addUsedModule(imported_module) if added_flag: signal_change("new_code", imported_module.getSourceReference(), "Recursed to module.")
def attemptRecursion(self): # Make sure the package is recursed to. from nuitka.importing import Recursion # Return the list of newly added modules. result = [] if self.package_name is not None and self.package is None: package_package, package_filename, _finding = \ Importing.findModule( source_ref = self.getSourceReference(), module_name = self.package_name, parent_package = None, level = 1, warn = Utils.python_version < 330 ) # TODO: Temporary, if we can't find the package for Python3.3 that # is semi-OK, maybe. if Utils.python_version >= 330 and not package_filename: return [] imported_module, is_added = Recursion.recurseTo( module_package = package_package, module_filename = package_filename, module_relpath = Utils.relpath(package_filename), module_kind = "py", reason = "Containing package of recursed module.", ) self.package = imported_module if is_added: result.append(imported_module) if self.package: from nuitka.ModuleRegistry import addUsedModule addUsedModule(self.package) # print "Recursed to package", self.package_name result.extend(self.package.attemptRecursion()) return result
def attemptRecursion(self): # Make sure the package is recursed to. from nuitka.importing import Recursion # Return the list of newly added modules. result = [] if self.package_name is not None and self.package is None: package_package, package_filename, _finding = \ Importing.findModule( source_ref = self.getSourceReference(), module_name = self.package_name, parent_package = None, level = 1, warn = Utils.python_version < 330 ) # TODO: Temporary, if we can't find the package for Python3.3 that # is semi-OK, maybe. if Utils.python_version >= 330 and not package_filename: return [] imported_module, is_added = Recursion.recurseTo( module_package=package_package, module_filename=package_filename, module_relpath=Utils.relpath(package_filename), module_kind="py", reason="Containing package of recursed module.", ) self.package = imported_module if is_added: result.append(imported_module) if self.package: from nuitka.ModuleRegistry import addUsedModule addUsedModule(self.package) # print "Recursed to package", self.package_name result.extend(self.package.attemptRecursion()) return result
def decideRecursion(module_filename, module_name, module_kind): """Decide whether Nuitka should recurse down to a given module. Args: module_filename: filename module_name: full module name module_kind: one of "py" or "shlib" (shared library) Returns: (decision, reason) where decision is either a bool or None, and reason is a string message. """ from nuitka.importing import Recursion decision, reason = Recursion.decideRecursion( module_filename=module_filename, module_name=module_name, module_kind=module_kind, ) return decision, reason
def createNodeTree(filename): """ Create a node tree. Turn that source code into a node tree structure. If recursion into imported modules is available, more trees will be available during optimization, or immediately through recursed directory paths. """ # First, build the raw node tree from the source code. main_module = Building.buildModuleTree( filename = filename, package = None, is_top = True, is_main = not Options.shallMakeModule() ) ModuleRegistry.addRootModule(main_module) # First remove old object files and old generated files, old binary or # module, and standalone mode program directory if any, they can only do # harm. source_dir = getSourceDirectoryPath(main_module) if not Options.shallOnlyExecCCompilerCall(): cleanSourceDirectory(source_dir) # Prepare the ".dist" directory, throwing away what was there before. if Options.isStandaloneMode(): standalone_dir = getStandaloneDirectoryPath(main_module) removeDirectory( path = standalone_dir, ignore_errors = True ) makePath(standalone_dir) deleteFile( path = getResultFullpath(main_module), must_exist = False ) # Second, do it for the directories given. for plugin_filename in Options.getShallFollowExtra(): Recursion.checkPluginPath( plugin_filename = plugin_filename, module_package = None ) for pattern in Options.getShallFollowExtraFilePatterns(): Recursion.checkPluginFilenamePattern( pattern = pattern ) for package_name in Options.getMustIncludePackages(): package_package, package_directory, kind = Importing.findModule( importing = None, module_name = package_name, parent_package = None, level = 0, warn = False ) if kind != "absolute": sys.exit("Error, failed to locate package %r." % package_name) Recursion.checkPluginPath( plugin_filename = package_directory, module_package = package_package ) for module_name in Options.getMustIncludeModules(): module_package, module_filename, kind = Importing.findModule( importing = None, module_name = module_name, parent_package = None, level = 0, warn = False ) if kind != "absolute": sys.exit("Error, failed to locate module %r." % module_name) Recursion.checkPluginSinglePath( plugin_filename = module_filename, module_package = module_package ) # Then optimize the tree and potentially recursed modules. Optimization.optimize(main_module.getOutputFilename()) if Options.isExperimental("check_xml_persistence"): for module in ModuleRegistry.getRootModules(): if module.isMainModule(): return module assert False else: # Main module might change behind our back, look it up again. return main_module
def _createNodeTree(filename): """Create a node tree. Turn that source code into a node tree structure. If recursion into imported modules is available, more trees will be available during optimization, or immediately through recursed directory paths. """ # Many cases to deal with, pylint: disable=too-many-branches # First, build the raw node tree from the source code. main_module = Building.buildMainModuleTree( filename=filename, is_main=not Options.shallMakeModule(), ) # First remove old object files and old generated files, old binary or # module, and standalone mode program directory if any, they can only do # harm. source_dir = OutputDirectories.getSourceDirectoryPath() if not Options.shallOnlyExecCCompilerCall(): SconsInterface.cleanSconsDirectory(source_dir) # Prepare the ".dist" directory, throwing away what was there before. if Options.isStandaloneMode(): standalone_dir = OutputDirectories.getStandaloneDirectoryPath(bundle=False) removeDirectory(path=standalone_dir, ignore_errors=True) if Options.shallCreateAppBundle(): removeDirectory( path=changeFilenameExtension(standalone_dir, ".app"), ignore_errors=True ) # Delete result file, to avoid confusion with previous build and to # avoid locking issues after the build. deleteFile( path=OutputDirectories.getResultFullpath(onefile=False), must_exist=False ) if Options.isOnefileMode(): deleteFile( path=OutputDirectories.getResultFullpath(onefile=True), must_exist=False ) # Second, do it for the directories given. for plugin_filename in Options.getShallFollowExtra(): Recursion.checkPluginPath(plugin_filename=plugin_filename, module_package=None) for pattern in Options.getShallFollowExtraFilePatterns(): Recursion.checkPluginFilenamePattern(pattern=pattern) for package_name in Options.getMustIncludePackages(): package_name, package_directory, kind = Importing.locateModule( module_name=ModuleName(package_name), parent_package=None, level=0, ) if kind != "absolute": inclusion_logger.sysexit( "Error, failed to locate package %r you asked to include." % package_name.asString() ) Recursion.checkPluginPath( plugin_filename=package_directory, module_package=package_name.getPackageName(), ) for module_name in Options.getMustIncludeModules(): module_name, module_filename, kind = Importing.locateModule( module_name=ModuleName(module_name), parent_package=None, level=0, ) if kind != "absolute": inclusion_logger.sysexit( "Error, failed to locate module '%s' you asked to include." % module_name.asString() ) Recursion.checkPluginSinglePath( plugin_filename=module_filename, module_package=module_name.getPackageName() ) # Allow plugins to add more modules based on the initial set being complete. Plugins.onModuleInitialSet() # Then optimize the tree and potentially recursed modules. optimizeModules(main_module.getOutputFilename()) # Allow plugins to comment on final module set. Plugins.onModuleCompleteSet() if Options.isExperimental("check_xml_persistence"): for module in ModuleRegistry.getRootModules(): if module.isMainModule(): return module assert False else: # Main module might change behind our back, look it up again. return main_module
def createNodeTree(filename): """ Create a node tree. Turn that source code into a node tree structure. If recursion into imported modules is available, more trees will be available during optimization, or immediately through recursed directory paths. """ # First, build the raw node tree from the source code. main_module = Building.buildModuleTree( filename=filename, package=None, is_top=True, is_main=not Options.shallMakeModule(), ) ModuleRegistry.addRootModule(main_module) # First remove old object files and old generated files, old binary or # module, and standalone mode program directory if any, they can only do # harm. source_dir = getSourceDirectoryPath(main_module) if not Options.shallOnlyExecCCompilerCall(): cleanSourceDirectory(source_dir) # Prepare the ".dist" directory, throwing away what was there before. if Options.isStandaloneMode(): standalone_dir = getStandaloneDirectoryPath(main_module) removeDirectory(path=standalone_dir, ignore_errors=True) makePath(standalone_dir) deleteFile(path=getResultFullpath(main_module), must_exist=False) # Second, do it for the directories given. for plugin_filename in Options.getShallFollowExtra(): Recursion.checkPluginPath(plugin_filename=plugin_filename, module_package=None) for pattern in Options.getShallFollowExtraFilePatterns(): Recursion.checkPluginFilenamePattern(pattern=pattern) for package_name in Options.getMustIncludePackages(): package_package, package_directory, kind = Importing.findModule( importing=None, module_name=package_name, parent_package=None, level=0, warn=False, ) if kind != "absolute": sys.exit("Error, failed to locate package %r." % package_name) Recursion.checkPluginPath( plugin_filename=package_directory, module_package=package_package ) for module_name in Options.getMustIncludeModules(): module_package, module_filename, kind = Importing.findModule( importing=None, module_name=module_name, parent_package=None, level=0, warn=False, ) if kind != "absolute": sys.exit("Error, failed to locate module %r." % module_name) Recursion.checkPluginSinglePath( plugin_filename=module_filename, module_package=module_package ) # Then optimize the tree and potentially recursed modules. Optimization.optimize(main_module.getOutputFilename()) if Options.isExperimental("check_xml_persistence"): for module in ModuleRegistry.getRootModules(): if module.isMainModule(): return module assert False else: # Main module might change behind our back, look it up again. return main_module