Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorboard/plugins/scalar/metadata.py: 44%
16 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Internal information about the scalar plugin."""
18from tensorboard.compat.proto import summary_pb2
19from tensorboard.plugins.scalar import plugin_data_pb2
21PLUGIN_NAME = "scalars"
23# The most recent value for the `version` field of the
24# `ScalarPluginData` proto.
25PROTO_VERSION = 0
28def create_summary_metadata(display_name, description):
29 """Create a `summary_pb2.SummaryMetadata` proto for scalar plugin data.
31 Returns:
32 A `summary_pb2.SummaryMetadata` protobuf object.
33 """
34 content = plugin_data_pb2.ScalarPluginData(version=PROTO_VERSION)
35 metadata = summary_pb2.SummaryMetadata(
36 display_name=display_name,
37 summary_description=description,
38 plugin_data=summary_pb2.SummaryMetadata.PluginData(
39 plugin_name=PLUGIN_NAME, content=content.SerializeToString()
40 ),
41 )
42 return metadata
45def parse_plugin_metadata(content):
46 """Parse summary metadata to a Python object.
48 Arguments:
49 content: The `content` field of a `SummaryMetadata` proto
50 corresponding to the scalar plugin.
52 Returns:
53 A `ScalarPluginData` protobuf object.
54 """
55 if not isinstance(content, bytes):
56 raise TypeError("Content type must be bytes")
57 result = plugin_data_pb2.ScalarPluginData.FromString(content)
58 if result.version == 0:
59 return result
60 # No other versions known at this time, so no migrations to do.
61 return result