Exemple #1
0
def render_code_block(code_block: CodeBlock) -> str:
    logging.info("Rendering code block: %s", code_block.template_name)

    return render_template(
        template_name=f"code_blocks/{code_block.template_name}",
        **code_block.template_params,
    )
def render_class_block(class_block: ClassBlock) -> str:
    logging.info("Rendering class block: %s", class_block.name)

    method_blocks = [
        render_method_block(block) for block in class_block.methods_blocks
    ]

    ctor_method_block = next(
        (block
         for block in class_block.methods_blocks if block.name == "__init__"),
        None,
    )

    ctor_method_args_docstring = ([
        value for key, value in ctor_method_block.args.items()
        if key not in ("*args", "**kwargs")
    ] if ctor_method_block else None)

    return render_template(
        template_name="class_block.py.tpl",
        name=class_block.name,
        extend_class=class_block.extend_class,
        ctor_method=ctor_method_block,
        ctor_method_args_docstring=ctor_method_args_docstring,
        method_blocks=method_blocks,
    )
def render_single_test(operator: Operator, package_name: str) -> str:
    return render_template(
        "discovery/test_operator_class.tpl",
        {
            "operator": operator,
            "package_name": package_name
        },
    )
def render_integration_rst(operators: List[Operator],
                           integration: DiscoveryIntegration) -> str:
    logging.info("Rendering integration.rst file")
    content = render_template(
        "discovery/integration.rst.tpl",
        {
            "operators": operators,
            "integration": integration
        },
    )
    return content
def render_examples(operators: List[Operator],
                    integration: DiscoveryIntegration) -> str:
    examples = [render_single_example_op(op) for op in operators]
    return render_template(
        "discovery/example_file.tpl",
        {
            "examples": examples,
            "integration": integration,
            "operators": operators
        },
    )
def render_hook(integration: DiscoveryIntegration, operators: List[Operator],
                endpoint: Endpoint) -> str:
    hook_methods = [render_single_hook_method(op) for op in operators]
    content = render_template(
        "discovery/hook_class.tpl",
        {
            "methods": hook_methods,
            "integration": integration,
            "endpoint": endpoint
        },
    )
    return content
def render_tests(operators: List[Operator], package_name) -> str:
    logging.info("Rendering tests file")
    tests = [render_single_test(op, package_name) for op in operators]
    content = render_template(
        "discovery/test_operator_file.tpl",
        {
            "operators": operators,
            "tests": tests,
            "package_name": package_name
        },
    )
    return content
def render_operators(integration: DiscoveryIntegration,
                     operators: List[Operator]) -> str:
    operators_classes = [render_single_operator(op) for op in operators]
    content = render_template(
        "discovery/operator_file.tpl",
        {
            "operators": operators_classes,
            "integration": integration,
            "hook_class": operators[0].hook_class,
        },
    )
    return content
def render_hook_tests(integration: DiscoveryIntegration,
                      operators: List[Operator], package_name: str) -> str:
    tests = [render_single_hook_test(op, package_name) for op in operators]
    content = render_template(
        "discovery/test_hook_file.tpl",
        {
            "tests": tests,
            "integration": integration,
            "hook_class": operators[0].hook_class,
            "package_name": package_name,
        },
    )
    return content
Exemple #10
0
def render_file_block(file_block: FileBlock) -> str:
    logging.info("Rendering file block: %s", file_block.file_name)

    class_blocks = [
        render_class_block(block) for block in file_block.class_blocks
    ]

    return render_template(
        template_name="file_block.py.tpl",
        class_blocks=class_blocks,
        import_statement=file_block.import_statement,
        constants=file_block.constants,
    )
Exemple #11
0
def render_class_block(class_block: ClassBlock) -> str:
    logging.info("Rendering class block: %s", class_block.name)

    method_blocks = [
        render_method_block(block) for block in class_block.methods_blocks
    ]

    ctor_method_block = next(
        (block
         for block in class_block.methods_blocks if block.name == "__init__"),
        None,
    )

    return render_template(
        template_name="class_block.py.tpl",
        name=class_block.name,
        extend_class=class_block.extend_class,
        ctor_method=ctor_method_block,
        method_blocks=method_blocks,
    )
Exemple #12
0
def render_method_block(method_block: MethodBlock) -> str:
    logging.info("Rendering method block: %s", method_block.name)

    code_blocks = [
        render_code_block(block) for block in method_block.code_blocks
    ]
    decorator_blocks = [
        render_code_block(block) for block in method_block.decorator_blocks
    ]

    return render_template(
        template_name="method_block.py.tpl",
        name=method_block.name,
        desc=method_block.desc if method_block.name != "__init__" else None,
        args=method_block.args,
        return_kind=method_block.return_kind,
        return_desc=method_block.return_desc,
        code_blocks=code_blocks,
        decorator_blocks=decorator_blocks,
    )
def render_single_operator(operator: Operator) -> str:
    return render_template("discovery/operator_class.tpl",
                           {"operator": operator})
def render_single_hook_method(operator: Operator) -> str:
    return render_template("discovery/hook_method.tpl", {"operator": operator})
def render_howto(operators: List[Operator],
                 integration: DiscoveryIntegration) -> str:
    return render_template("discovery/howto.tpl", {
        "integration": integration,
        "operators": operators
    })
def render_system_test(integration: DiscoveryIntegration) -> str:
    key = "GCP_{}_KEY".format(integration.service_name.upper())
    return render_template("discovery/system_test.tpl", {
        "integration": integration,
        "key": key
    })
def render_single_example_op(operator: Operator) -> str:
    return render_template("discovery/example_operator.tpl",
                           {"operator": operator})