示例#1
0
def recurseTo(module_package, module_filename, module_relpath, module_kind,
              reason):
    from nuitka.tree import Building

    if not ImportCache.isImportedModuleByPath(module_relpath):
        module, source_ref, source_filename = Building.decideModuleTree(
            filename=module_filename,
            package=module_package,
            is_top=False,
            is_main=False,
            is_shlib=module_kind == "shlib")

        # Check if the module name is known. In order to avoid duplicates,
        # learn the new filename, and continue build if its not.
        if not ImportCache.isImportedModuleByName(module.getFullName()):
            debug("Recurse to import '%s' from %s. (%s)", module.getFullName(),
                  module_relpath, reason)

            if module_kind == "py" and source_filename is not None:
                try:
                    Building.createModuleTree(
                        module=module,
                        source_ref=source_ref,
                        source_code=readSourceCodeFromFilename(
                            source_filename),
                        is_main=False)
                except (SyntaxError, IndentationError) as e:
                    if module_filename not in Importing.warned_about:
                        Importing.warned_about.add(module_filename)

                        warning(
                            """\
Cannot recurse to import module '%s' (%s) because of '%s'""", module_relpath,
                            module_filename, e.__class__.__name__)

                    return None, False

            ImportCache.addImportedModule(module_relpath, module)

            is_added = True
        else:
            ImportCache.addImportedModule(
                module_relpath,
                ImportCache.getImportedModuleByName(module.getFullName()))

            module = ImportCache.getImportedModuleByName(module.getFullName())

            is_added = False

        assert not module_relpath.endswith("/__init__.py"), module

        return module, is_added
    else:
        return ImportCache.getImportedModuleByPath(module_relpath), False
示例#2
0
def optimizeUncompiledPythonModule(module):
    if _progress:
        info("Doing module dependency considerations for '{module_name}':".
             format(module_name=module.getFullName()))

    for used_module_name in module.getUsedModules():
        used_module = ImportCache.getImportedModuleByName(used_module_name)
        ModuleRegistry.addUsedModule(used_module)

    package_name = module.getPackage()

    if package_name is not None:
        used_module = ImportCache.getImportedModuleByName(package_name)
        ModuleRegistry.addUsedModule(used_module)
示例#3
0
def optimizeUncompiledPythonModule(module):
    full_name = module.getFullName()
    progress_logger.info(
        "Doing module dependency considerations for '{module_name}':".format(
            module_name=full_name
        )
    )

    for used_module_name, used_module_path in module.getUsedModules():
        used_module = ImportCache.getImportedModuleByNameAndPath(
            used_module_name, used_module_path
        )
        ModuleRegistry.addUsedModule(used_module)

    package_name = full_name.getPackageName()

    if package_name is not None:
        # TODO: It's unclear why, but some standard library modules on older Python3
        # seem to not have parent packages after the scan.
        try:
            used_module = ImportCache.getImportedModuleByName(package_name)
        except KeyError:
            pass
        else:
            ModuleRegistry.addUsedModule(used_module)

    Plugins.considerImplicitImports(module=module, signal_change=signalChange)
示例#4
0
def optimizeUncompiledPythonModule(module):
    if _progress:
        printLine(
            "Doing module dependency considerations for '{module_name}':".format(
                module_name = module.getFullName()
            )
        )

    for used_module_name in module.getUsedModules():
        used_module = ImportCache.getImportedModuleByName(used_module_name)
        ModuleRegistry.addUsedModule(used_module)

    package_name = module.getPackage()

    if package_name is not None:
        used_module = ImportCache.getImportedModuleByName(package_name)
        ModuleRegistry.addUsedModule(used_module)
示例#5
0
def optimizeUncompiledPythonModule(module):
    if _progress:
        info("Doing module dependency considerations for '{module_name}':".
             format(module_name=module.getFullName()))

    for used_module_name, used_module_path in module.getUsedModules():
        used_module = ImportCache.getImportedModuleByNameAndPath(
            used_module_name, used_module_path)
        ModuleRegistry.addUsedModule(used_module)

    package_name = module.getPackage()

    if package_name is not None:
        used_module = ImportCache.getImportedModuleByName(package_name)
        ModuleRegistry.addUsedModule(used_module)

    Plugins.considerImplicitImports(module=module, signal_change=signalChange)
示例#6
0
def optimizeUncompiledPythonModule(module):
    if _progress:
        info(
            "Doing module dependency considerations for '{module_name}':".format(
                module_name=module.getFullName()
            )
        )

    for used_module_name, used_module_path in module.getUsedModules():
        used_module = ImportCache.getImportedModuleByNameAndPath(
            used_module_name, used_module_path
        )
        ModuleRegistry.addUsedModule(used_module)

    package_name = module.getPackage()

    if package_name is not None:
        used_module = ImportCache.getImportedModuleByName(package_name)
        ModuleRegistry.addUsedModule(used_module)

    Plugins.considerImplicitImports(module=module, signal_change=signalChange)
示例#7
0
def _recurseTo(module_package, module_filename, module_relpath, module_kind,
               reason):
    from nuitka.tree import Building
    from nuitka.nodes.ModuleNodes import makeUncompiledPythonModule

    module, source_ref, source_filename = Building.decideModuleTree(
        filename=module_filename,
        package=module_package,
        is_top=False,
        is_main=False,
        is_shlib=module_kind == "shlib")

    # Check if the module name is known. In order to avoid duplicates,
    # learn the new filename, and continue build if its not.
    if not ImportCache.isImportedModuleByName(module.getFullName()):
        logRecursion("Recurse to import '%s' from '%s'. (%s)",
                     module.getFullName(), module_relpath, reason)

        if module_kind == "py" and source_filename is not None:
            try:
                source_code = readSourceCodeFromFilename(
                    module_name=module.getFullName(),
                    source_filename=source_filename)

                Building.createModuleTree(module=module,
                                          source_ref=source_ref,
                                          source_code=source_code,
                                          is_main=False)
            except (SyntaxError, IndentationError) as e:
                if module_filename not in Importing.warned_about:
                    Importing.warned_about.add(module_filename)

                    warning(
                        """\
Cannot recurse to import module '%s' (%s) because of '%s'""", module_relpath,
                        module_filename, e.__class__.__name__)

                return None, False
            except Building.CodeTooComplexCode:
                if module_filename not in Importing.warned_about:
                    Importing.warned_about.add(module_filename)

                    warning(
                        """\
Cannot recurse to import module '%s' (%s) because code is too complex.""",
                        module_relpath,
                        module_filename,
                    )

                    if Options.isStandaloneMode():
                        module = makeUncompiledPythonModule(
                            module_name=module.getFullName(),
                            filename=module_filename,
                            bytecode=marshal.dumps(
                                compile(source_code,
                                        module_filename,
                                        "exec",
                                        dont_inherit=True)),
                            is_package=module.isCompiledPythonPackage(),
                            user_provided=True,
                            technical=False)

                        ModuleRegistry.addUncompiledModule(module)

                return None, False

        ImportCache.addImportedModule(module)

        is_added = True
    else:
        module = ImportCache.getImportedModuleByName(module.getFullName())

        is_added = False

    return module, is_added
示例#8
0
def recurseTo(module_package, module_filename, module_relpath, module_kind,
             reason):
    from nuitka.tree import Building

    if not ImportCache.isImportedModuleByPath(module_relpath):
        module, source_ref, source_filename = Building.decideModuleTree(
            filename = module_filename,
            package  = module_package,
            is_top   = False,
            is_main  = False,
            is_shlib = module_kind == "shlib"
        )

        # Check if the module name is known. In order to avoid duplicates,
        # learn the new filename, and continue build if its not.
        if not ImportCache.isImportedModuleByName(module.getFullName()):
            debug(
                "Recurse to import '%s' from %s. (%s)",
                module.getFullName(),
                module_relpath,
                reason
            )

            if module_kind == "py" and source_filename is not None:
                try:
                    Building.createModuleTree(
                        module      = module,
                        source_ref  = source_ref,
                        source_code = readSourceCodeFromFilename(
                            module_name     = module.getFullName(),
                            source_filename = source_filename
                        ),
                        is_main     = False
                    )
                except (SyntaxError, IndentationError) as e:
                    if module_filename not in Importing.warned_about:
                        Importing.warned_about.add(module_filename)

                        warning(
                            """\
Cannot recurse to import module '%s' (%s) because of '%s'""",
                            module_relpath,
                            module_filename,
                            e.__class__.__name__
                        )

                    return None, False

            ImportCache.addImportedModule(
                module_relpath,
                module
            )

            is_added = True
        else:
            ImportCache.addImportedModule(
                module_relpath,
                ImportCache.getImportedModuleByName(module.getFullName())
            )

            module = ImportCache.getImportedModuleByName(
                module.getFullName()
            )

            is_added = False

        assert not module_relpath.endswith("/__init__.py"), module

        return module, is_added
    else:
        return ImportCache.getImportedModuleByPath(module_relpath), False
示例#9
0
def recurseTo(module_package, module_filename, module_relpath, module_kind,
             reason):
    from nuitka.tree import Building
    from nuitka.nodes.ModuleNodes import makeUncompiledPythonModule

    if not ImportCache.isImportedModuleByPath(module_relpath):
        module, source_ref, source_filename = Building.decideModuleTree(
            filename = module_filename,
            package  = module_package,
            is_top   = False,
            is_main  = False,
            is_shlib = module_kind == "shlib"
        )

        # Check if the module name is known. In order to avoid duplicates,
        # learn the new filename, and continue build if its not.
        if not ImportCache.isImportedModuleByName(module.getFullName()):
            debug(
                "Recurse to import '%s' from %s. (%s)",
                module.getFullName(),
                module_relpath,
                reason
            )

            if module_kind == "py" and source_filename is not None:
                try:
                    Building.createModuleTree(
                        module      = module,
                        source_ref  = source_ref,
                        source_code = readSourceCodeFromFilename(
                            module_name     = module.getFullName(),
                            source_filename = source_filename
                        ),
                        is_main     = False
                    )
                except (SyntaxError, IndentationError) as e:
                    if module_filename not in Importing.warned_about:
                        Importing.warned_about.add(module_filename)

                        warning(
                            """\
Cannot recurse to import module '%s' (%s) because of '%s'""",
                            module_relpath,
                            module_filename,
                            e.__class__.__name__
                        )

                    return None, False
                except Building.CodeTooComplexCode:
                    if module_filename not in Importing.warned_about:
                        Importing.warned_about.add(module_filename)

                        warning(
                            """\
Cannot recurse to import module '%s' (%s) because code is too complex.""",
                            module_relpath,
                            module_filename,
                        )


                        if Options.isStandaloneMode():
                            module = makeUncompiledPythonModule(
                                module_name   = module.getFullName(),
                                filename      = module_filename,
                                bytecode      = marshal.dumps(
                                    compile(
                                        readSourceCodeFromFilename(module.getFullName(), module_filename),
                                        module_filename,
                                        "exec"
                                    )
                                ),
                                is_package    = module.isCompiledPythonPackage(),
                                user_provided = True,
                                technical     = False
                            )

                            ModuleRegistry.addUncompiledModule(module)

                    return None, False

            ImportCache.addImportedModule(module)

            is_added = True
        else:
            module = ImportCache.getImportedModuleByName(
                module.getFullName()
            )

            is_added = False

        assert not module_relpath.endswith("/__init__.py"), module

        return module, is_added
    else:
        return ImportCache.getImportedModuleByPath(module_relpath), False