Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tensorboard/defs/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package(default_visibility = ["//tensorboard:internal"])

load("//tensorboard/defs:protos.bzl", "tb_proto_library")

licenses(["notice"]) # Apache 2.0

filegroup(
Expand All @@ -13,4 +15,33 @@ filegroup(
visibility = ["//visibility:public"],
)

py_test(
name = "tb_proto_library_test",
srcs = ["tb_proto_library_test.py"],
deps = [
":test_base_py_pb2",
":test_base_py_pb2_grpc",
":test_downstream_py_pb2",
":test_downstream_py_pb2_grpc",
"//tensorboard:test",
],
)

tb_proto_library(
name = "test_base",
srcs = ["test_base.proto"],
has_services = True,
testonly = True,
)

tb_proto_library(
name = "test_downstream",
srcs = ["test_downstream.proto"],
deps = [
":test_base",
],
has_services = True,
testonly = True,
)

exports_files(["web_test_python_stub.template.py"])
15 changes: 8 additions & 7 deletions tensorboard/defs/protos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ load("@com_google_protobuf//:protobuf.bzl", "proto_gen")
def tb_proto_library(
name,
srcs = None,
deps = [],
visibility = None,
testonly = None,
has_services = False):
outs_proto = _PyOuts(srcs, grpc = False)
outs_grpc = _PyOuts(srcs, grpc = True) if has_services else []
outs_all = outs_proto + outs_grpc

runtime = "@com_google_protobuf//:protobuf_python"

proto_gen(
name = name + "_py_pb2_genproto",
name = name + "_genproto",
srcs = srcs,
deps = ["@com_google_protobuf//:protobuf_python_genproto"],
deps = [s + "_genproto" for s in deps] + [runtime + "_genproto"],
includes = [],
protoc = "@com_google_protobuf//:protoc",
gen_py = True,
Expand All @@ -37,12 +40,13 @@ def tb_proto_library(
plugin_language = "grpc",
)

py_deps = [s + "_py_pb2" for s in deps] + [runtime]
native.py_library(
name = name + "_py_pb2",
srcs = outs_proto,
imports = [],
srcs_version = "PY2AND3",
deps = ["@com_google_protobuf//:protobuf_python"],
deps = py_deps,
testonly = testonly,
visibility = visibility,
)
Expand All @@ -52,10 +56,7 @@ def tb_proto_library(
srcs = outs_grpc,
imports = [],
srcs_version = "PY2AND3",
deps = [
name + "_py_pb2",
"@com_google_protobuf//:protobuf_python",
],
deps = [name + "_py_pb2"] + py_deps,
testonly = testonly,
visibility = visibility,
)
Expand Down
44 changes: 44 additions & 0 deletions tensorboard/defs/tb_proto_library_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for the `tb_proto_library` build macro."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorboard import test as tb_test
from tensorboard.defs import test_base_pb2
from tensorboard.defs import test_base_pb2_grpc
from tensorboard.defs import test_downstream_pb2
from tensorboard.defs import test_downstream_pb2_grpc


class TbProtoLibraryTest(tb_test.TestCase):
"""Tests for `tb_proto_library`."""

def tests_with_deps(self):
foo = test_base_pb2.Foo()
foo.foo = 1
bar = test_downstream_pb2.Bar()
bar.foo.foo = 1
self.assertEqual(foo, bar.foo)

def test_service_deps(self):
self.assertIsInstance(test_base_pb2_grpc.FooServiceServicer, type)
self.assertIsInstance(test_downstream_pb2_grpc.BarServiceServicer, type)


if __name__ == "__main__":
tb_test.main()
33 changes: 33 additions & 0 deletions tensorboard/defs/test_base.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

syntax = "proto3";

message Foo {
int32 foo = 1;
}

service FooService {
// Loads some objects.
rpc GetFoo(GetFooRequest) returns (GetFooResponse);
}

message GetFooRequest {
int32 count = 1;
}

message GetFooResponse {
repeated Foo foo = 1;
}
36 changes: 36 additions & 0 deletions tensorboard/defs/test_downstream.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

syntax = "proto3";

import "tensorboard/defs/test_base.proto";

message Bar {
Foo foo = 1;
int32 bar = 2;
}

service BarService {
// Loads some objects.
rpc GetBar(GetBarRequest) returns (GetBarResponse);
}

message GetBarRequest {
int32 count = 1;
}

message GetBarResponse {
repeated Bar bar = 1;
}