Пример #1
0
    def emit_class_imports(self, ctx, imports):
        """Emits code corresponding to a set of python class imports.

        :param ctx: Generation context information.
        :param imports: Imports being parsed.
        :type ctx: pyesdoc_mp.generators.generator.GeneratorContext
        :type imports: list

        """
        code = ''
        tmpl = 'from py{0}.{1} import {2}'

        for package, type in imports:
            pkg_path = get_package_path(ctx.ontology, 'types', package)
            type_name = get_class_name(type)
            type_import_name = get_class_import_name(type)
            code += tmpl.format(pkg_path, type_import_name, type_name)
            code += emit_line_return()

        return code
Пример #2
0
    def emit_imports_for_sub_package(self, ctx, pkg=None):
        """Emits code corresponding to a set of sub package imports.

        :param ctx: Generation context information.
        :type ctx: pyesdoc_mp.generators.generator.GeneratorContext

        """
        code = ''

        pkg = pkg if pkg is not None else ctx.pkg
        for cls in pkg.classes:
            code += 'from py{0}.v{1}.types.{2}.{3} import {4}{5}'.format(
                get_ontology_name(ctx.ontology),
                get_ontology_version(ctx.ontology),
                get_package_name(pkg),
                get_class_import_name(cls),
                get_class_name(cls),
                emit_line_return())
                
        return code