Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorboard/plugins/text/metadata.py: 39%

18 statements  

« 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 text plugin.""" 

16 

17 

18from tensorboard.compat.proto import summary_pb2 

19from tensorboard.plugins.text import plugin_data_pb2 

20 

21PLUGIN_NAME = "text" 

22 

23# The most recent value for the `version` field of the 

24# `TextPluginData` proto. 

25PROTO_VERSION = 0 

26 

27 

28def create_summary_metadata(display_name, description): 

29 """Create a `summary_pb2.SummaryMetadata` proto for text plugin data. 

30 

31 Returns: 

32 A `summary_pb2.SummaryMetadata` protobuf object. 

33 """ 

34 content = plugin_data_pb2.TextPluginData(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 

43 

44 

45def parse_plugin_metadata(content): 

46 """Parse summary metadata to a Python object. 

47 

48 Arguments: 

49 content: The `content` field of a `SummaryMetadata` proto corresponding to 

50 the text plugin. 

51 Returns: 

52 A `TextPluginData` protobuf object. 

53 """ 

54 if not isinstance(content, bytes): 

55 raise TypeError("Content type must be bytes") 

56 if content == b"{}": 

57 # Old-style JSON format. Equivalent to an all-default proto. 

58 return plugin_data_pb2.TextPluginData() 

59 result = plugin_data_pb2.TextPluginData.FromString(content) 

60 if result.version == 0: 

61 return result 

62 # No other versions known at this time, so no migrations to do. 

63 return result