Exemple #1
0
def demoteCompiledModuleToBytecode(module):
    """ Demote a compiled module to uncompiled (bytecode).

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

    source_code = readSourceCodeFromFilename(full_name, filename)

    source_code = Plugins.onFrozenModuleSourceCode(module_name=full_name,
                                                   is_package=False,
                                                   source_code=source_code)

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

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

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

    replaceImportedModule(old=module, new=uncompiled_module)

    replaceRootModule(old=module, new=uncompiled_module)

    assert module.constraint_collection is not None
    uncompiled_module.setUsedModules(
        module.constraint_collection.getUsedModules())
Exemple #2
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)
Exemple #3
0
def demoteCompiledModuleToBytecode(module):
    """ Demote a compiled module to uncompiled (bytecode).

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

    source_code = readSourceCodeFromFilename(full_name, filename)

    source_code = Plugins.onFrozenModuleSourceCode(
        module_name = full_name,
        is_package  = False,
        source_code = source_code
    )

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

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

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

    replaceImportedModule(
        old = module,
        new = uncompiled_module
    )

    replaceRootModule(
        old = module,
        new = uncompiled_module
    )

    assert module.constraint_collection is not None
    uncompiled_module.setUsedModules(module.constraint_collection.getUsedModules())
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)