Esempio n. 1
0
    def onUsedModule(self, module_name):
        assert type(module_name) is str, module_name

        self.used_modules.add(module_name)

        if isImportedModuleByName(module_name):
            module = getImportedModuleByName(module_name)
            addUsedModule(module)
Esempio n. 2
0
    def onUsedModule(self, module_name):
        assert type(module_name) is str, module_name

        self.used_modules.add(module_name)

        if isImportedModuleByName(module_name):
            module = getImportedModuleByName(module_name)
            addUsedModule(module)
Esempio n. 3
0
def demoteCompiledModuleToBytecode(module):
    """ Demote a compiled module to uncompiled (bytecode).

    """

    full_name = module.getFullName()
    filename = module.getCompileTimeFilename()

    if Options.isShowProgress():
        info("Demoting module '%s' to bytecode from '%s'." %
             (full_name, filename))

    source_code = module.getSourceCode()

    # Second chance for plugins to modify source code just before turning it
    # to bytecode.
    source_code = Plugins.onFrozenModuleSourceCode(module_name=full_name,
                                                   is_package=False,
                                                   source_code=source_code)

    bytecode = compile(source_code, filename, "exec", dont_inherit=True)

    bytecode = Plugins.onFrozenModuleBytecode(module_name=full_name,
                                              is_package=False,
                                              bytecode=bytecode)

    uncompiled_module = makeUncompiledPythonModule(
        module_name=full_name,
        filename=filename,
        bytecode=marshal.dumps(bytecode),
        is_package=module.isCompiledPythonPackage(),
        user_provided=True,
        technical=False,
    )

    uncompiled_module.setUsedModules(module.getUsedModules())
    module.finalize()

    if isImportedModuleByName(full_name):
        replaceImportedModule(old=module, new=uncompiled_module)
    replaceRootModule(old=module, new=uncompiled_module)

    from nuitka.plugins.PluginBase import isTriggerModule, replaceTriggerModule

    if isTriggerModule(module):
        replaceTriggerModule(old=module, new=uncompiled_module)
Esempio n. 4
0
def demoteCompiledModuleToBytecode(module):
    """Demote a compiled module to uncompiled (bytecode)."""

    full_name = module.getFullName()
    filename = module.getCompileTimeFilename()

    if Options.isShowProgress():
        inclusion_logger.info("Demoting module %r to bytecode from %r." %
                              (full_name.asString(), filename))

    source_code = module.getSourceCode()

    bytecode = demoteSourceCodeToBytecode(module_name=full_name,
                                          source_code=source_code,
                                          filename=filename)

    uncompiled_module = makeUncompiledPythonModule(
        module_name=full_name,
        filename=filename,
        bytecode=bytecode,
        is_package=module.isCompiledPythonPackage(),
        user_provided=True,
        technical=False,
    )

    used_modules = module.getUsedModules()
    uncompiled_module.setUsedModules(used_modules)
    module.finalize()

    if isImportedModuleByName(full_name):
        replaceImportedModule(old=module, new=uncompiled_module)
    replaceRootModule(old=module, new=uncompiled_module)

    from nuitka.plugins.PluginBase import isTriggerModule, replaceTriggerModule

    if isTriggerModule(module):
        replaceTriggerModule(old=module, new=uncompiled_module)

    writeImportedModulesNamesToCache(module_name=full_name,
                                     source_code=source_code,
                                     used_modules=used_modules)
Esempio n. 5
0
    def onUsedModule(self, module_name):
        self.used_modules.add(module_name)

        if isImportedModuleByName(module_name):
            module = getImportedModuleByName(module_name)
            addUsedModule(module)
Esempio n. 6
0
    def onUsedModule(self, module_name):
        self.used_modules.add(module_name)

        if isImportedModuleByName(module_name):
            module = getImportedModuleByName(module_name)
            addUsedModule(module)