diff --git a/nuitka/plugins/Plugins.py b/nuitka/plugins/Plugins.py index 3661ac842b..277e2f010b 100644 --- a/nuitka/plugins/Plugins.py +++ b/nuitka/plugins/Plugins.py @@ -745,9 +745,10 @@ def _createTriggerLoadedModule(cls, module, trigger_name, code, flags): is_fake=module_name, hide_syntax_error=False, ) - except SyntaxError: + except SyntaxError as e: plugins_logger.sysexit( - "SyntaxError in plugin provided source code for '%s'." % module_name + "SyntaxError in plugin provided source code for '%s': %s." + % (module_name, e) ) if trigger_module.getCompilationMode() == "bytecode": @@ -758,7 +759,7 @@ def _createTriggerLoadedModule(cls, module, trigger_name, code, flags): @classmethod def onModuleDiscovered(cls, module): # We offer plugins many ways to provide extra stuff - # pylint: disable=too-many-branches,too-many-locals,too-many-statements + # pylint: disable=too-many-locals,too-many-statements full_name = module.getFullName() @@ -816,23 +817,41 @@ def _untangleFakeDesc(description): _untangleFakeDesc(description=plugin.createFakeModuleDependency(module)) ) - if pre_module_load_descriptions: - total_code = [] + def combineLoadCodes(module_load_descriptions, mode): + future_imports_code = [] + normal_code_code = [] total_flags = OrderedSet() reasons = [] - for plugin, pre_code, reason, flags in pre_module_load_descriptions: - if pre_code: + for plugin, code, reason, flags in module_load_descriptions: + if code: plugin.info( - "Injecting pre-module load code for module '%s':" % full_name + "Injecting %s-module load code for module '%s':" + % (mode, full_name) ) for line in reason.split("\n"): plugin.info(" " + line) - total_code.append(pre_code) + for line in code.splitlines(): + line = line + "\n" + + if line.startswith("from __future__"): + future_imports_code.append(line) + else: + normal_code_code.append(line) + total_flags.update(flags) reasons.append(reason) + total_code = future_imports_code + normal_code_code + + return total_code, reasons, total_flags + + if pre_module_load_descriptions: + total_code, reasons, total_flags = combineLoadCodes( + module_load_descriptions=pre_module_load_descriptions, mode="pre" + ) + if total_code: assert full_name not in pre_modules @@ -845,21 +864,9 @@ def _untangleFakeDesc(description): pre_modules_reasons[full_name] = tuple(reasons) if post_module_load_descriptions: - total_code = [] - total_flags = OrderedSet() - reasons = [] - - for plugin, post_code, reason, flags in post_module_load_descriptions: - if post_code: - plugin.info( - "Injecting post-module load code for module '%s':" % full_name - ) - for line in reason.split("\n"): - plugin.info(" " + line) - - total_code.append(post_code) - total_flags.update(flags) - reasons.append(reason) + total_code, reasons, total_flags = combineLoadCodes( + module_load_descriptions=post_module_load_descriptions, mode="post" + ) if total_code: assert full_name not in post_modules diff --git a/nuitka/plugins/standard/PySidePyQtPlugin.py b/nuitka/plugins/standard/PySidePyQtPlugin.py index aae4673f34..b15b8484e3 100644 --- a/nuitka/plugins/standard/PySidePyQtPlugin.py +++ b/nuitka/plugins/standard/PySidePyQtPlugin.py @@ -611,7 +611,6 @@ def createPostModuleLoadCode(self, module): os.path.dirname(__file__), "qml" ) - """ % { "package_name": full_name }