Ejemplo n.º 1
0
    def test_python_protobuf(self) -> None:
        self.create_file(
            "src/protobuf/dir/f.proto",
            dedent("""\
                syntax = "proto2";

                package dir;
                """),
        )
        self.add_to_build_file("src/protobuf/dir", "protobuf_library()")
        targets = [ProtobufLibrary({}, address=Address("src/protobuf/dir"))]
        backend_args = [
            "--backend-packages=pants.backend.codegen.protobuf.python"
        ]

        stripped_result = self.get_stripped_sources(
            targets, source_roots=["src/protobuf"], extra_args=backend_args)
        assert stripped_result.stripped_source_files.snapshot.files == (
            "dir/f_pb2.py", )

        unstripped_result = self.get_unstripped_sources(
            targets, source_roots=["src/protobuf"], extra_args=backend_args)
        assert unstripped_result.source_files.snapshot.files == (
            "src/protobuf/dir/f_pb2.py", )
        assert unstripped_result.source_roots == ("src/protobuf", )
Ejemplo n.º 2
0
def test_python_protobuf(rule_runner: RuleRunner) -> None:
    rule_runner.create_file(
        "src/protobuf/dir/f.proto",
        dedent("""\
            syntax = "proto2";

            package dir;
            """),
    )
    rule_runner.create_file(
        "src/protobuf/other_dir/f.proto",
        dedent("""\
            syntax = "proto2";

            package other_dir;
            """),
    )
    rule_runner.add_to_build_file("src/protobuf/dir", "protobuf_library()")
    rule_runner.add_to_build_file(
        "src/protobuf/other_dir",
        "protobuf_library(python_source_root='src/python')")
    targets = [
        ProtobufLibrary({}, address=Address("src/protobuf/dir")),
        ProtobufLibrary({}, address=Address("src/protobuf/other_dir")),
    ]
    backend_args = ["--backend-packages=pants.backend.codegen.protobuf.python"]

    stripped_result = get_stripped_sources(
        rule_runner,
        targets,
        source_roots=["src/protobuf", "src/python"],
        extra_args=backend_args)
    assert stripped_result.stripped_source_files.snapshot.files == (
        "dir/f_pb2.py",
        "other_dir/f_pb2.py",
    )

    unstripped_result = get_unstripped_sources(
        rule_runner,
        targets,
        source_roots=["src/protobuf", "src/python"],
        extra_args=backend_args)
    assert unstripped_result.source_files.snapshot.files == (
        "src/protobuf/dir/f_pb2.py",
        "src/python/other_dir/f_pb2.py",
    )
    assert unstripped_result.source_roots == ("src/protobuf", "src/python")
Ejemplo n.º 3
0
def rules():
    return [
        ProtobufLibrary.register_plugin_field(
            ProtobufPythonInterpreterCompatibility),
        ProtobufLibrary.register_plugin_field(PythonSourceRootField),
    ]
Ejemplo n.º 4
0
def rules():
    return [
        ProtobufLibrary.register_plugin_field(
            ProtobufPythonInterpreterConstraints),
        ProtobufLibrary.register_plugin_field(PythonSourceRootField),
    ]