本文整理汇总了Python中google.protobuf.descriptor_pb2.FileDescriptorSet方法的典型用法代码示例。如果您正苦于以下问题:Python descriptor_pb2.FileDescriptorSet方法的具体用法?Python descriptor_pb2.FileDescriptorSet怎么用?Python descriptor_pb2.FileDescriptorSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.protobuf.descriptor_pb2
的用法示例。
在下文中一共展示了descriptor_pb2.FileDescriptorSet方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import FileDescriptorSet [as 别名]
def execute(self, descriptor_set):
desc_set = desc.FileDescriptorSet()
with open(descriptor_set, 'rb') as f:
desc_set.ParseFromString(f.read())
for file_descriptor_proto in desc_set.file:
if not file_descriptor_proto.source_code_info:
continue
for location in file_descriptor_proto.source_code_info.location:
location.leading_comments = md2rst(location.leading_comments)
location.trailing_comments = md2rst(location.trailing_comments)
detached = [md2rst(c) for c in location.leading_detached_comments]
del location.leading_detached_comments[:]
location.leading_detached_comments.extend(detached)
desc_file, desc_ext = os.path.splitext(descriptor_set)
new_descriptor_set = desc_file + '_updated_py_docs' + desc_ext
with open(new_descriptor_set, mode='wb') as f:
f.write(desc_set.SerializeToString())
return new_descriptor_set
示例2: test_valid_rst
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import FileDescriptorSet [as 别名]
def test_valid_rst(self):
descriptor_set = 'test/tasks/data/test_descriptor/descriptor_set'
task = descriptor_set_tasks.PythonDocsConvertionTask()
updated_descriptor = task.execute(descriptor_set)
desc_set = desc.FileDescriptorSet()
with open(updated_descriptor, 'rb') as f:
desc_set.ParseFromString(f.read())
lint_errors = []
comment_count = 0
for comment in gather_comments_from_descriptor_set(desc_set):
lint_errors.extend(restructuredtext_lint.lint(comment))
comment_count += 1
print(lint_errors)
assert len(lint_errors) == 0
assert comment_count == 1913
示例3: _get_descriptor_set
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import FileDescriptorSet [as 别名]
def _get_descriptor_set():
"""Returns a FileDescriptorSet proto to be used by tf.io.decode_proto."""
proto = pb.FileDescriptorSet()
# The FileDescriptor for tensorflow.ranking.internal.ExampleListWithContext.
file_proto = proto.file.add(
name=_FILE_NAME, package=_PACKAGE, syntax="proto3")
message_proto = file_proto.message_type.add(name=_MESSAGE_NAME)
message_proto.field.add(
name=_EXAMPLES_FIELD_NAME,
number=1,
type=pb.FieldDescriptorProto.TYPE_BYTES,
label=pb.FieldDescriptorProto.LABEL_REPEATED)
message_proto.field.add(
name=_CONTEXT_FIELD_NAME,
number=2,
type=pb.FieldDescriptorProto.TYPE_BYTES)
return proto
示例4: _GetDescriptorSetForTextInput
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import FileDescriptorSet [as 别名]
def _GetDescriptorSetForTextInput():
"""Returns a string for tf.io.decode_proto's descriptor_source."""
file_descriptor_set = descriptor_pb2.FileDescriptorSet()
text_input_pb2.DESCRIPTOR.CopyToProto(file_descriptor_set.file.add())
return b'bytes://' + file_descriptor_set.SerializeToString()
示例5: _maybe_annotate_vocab_metadata
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import FileDescriptorSet [as 别名]
def _maybe_annotate_vocab_metadata(vocab_filename, unfiltered_vocabulary_size):
"""Annotates a bucketized tensor with the boundaries that were applied.
Creates a deferred annotation for the specified tensor.
Args:
vocab_filename: The name of the vocabulary.
unfiltered_vocabulary_size: A tf.int32 tensor containing the unfiltered
vocab size.
"""
if not common.IS_ANNOTATIONS_PB_AVAILABLE:
return
from tensorflow_transform import annotations_pb2 # pylint: disable=g-import-not-at-top
message_type = annotations_pb2.VocabularyMetadata.DESCRIPTOR.full_name
unfiltered_vocabulary_size = tf.expand_dims(unfiltered_vocabulary_size, 0)
file_name = tf.convert_to_tensor([vocab_filename])
descriptor_source = descriptor_pb2.FileDescriptorSet()
annotations_pb2.VocabularyMetadata.DESCRIPTOR.file.CopyToProto(
descriptor_source.file.add())
descriptor_source_str = b'bytes://' + descriptor_source.SerializeToString()
message_proto = tf_utils._encode_proto( # pylint: disable=protected-access
{
'unfiltered_vocabulary_size': unfiltered_vocabulary_size,
'file_name': file_name,
}, message_type, descriptor_source=descriptor_source_str)
assert message_proto.shape == [1]
message_proto = message_proto[0]
# Note: we annotate globally here (tied to a vocabulary by filename) rather
# than attaching to a tensor, because this annotation is tied to an analysis
# output not a final tensor produced by a mapper.
type_url = os.path.join(common.ANNOTATION_PREFIX_URL, message_type)
schema_inference.annotate(type_url, message_proto)
示例6: test
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import FileDescriptorSet [as 别名]
def test(self):
serv = service.Discovery()
serv.add_service(TestService.DESCRIPTION)
res = serv.Describe(None, None)
self.assertEquals(res.services, ['discovery_test.TestService'])
for f in res.description.file:
self.assertTrue(f.HasField('source_code_info'))
f.ClearField('source_code_info')
expected_description = descriptor_pb2.FileDescriptorSet()
text_format.Merge(EXPECTED_DESCRIPTION, expected_description)
self.assertEqual(expected_description, res.description)
示例7: load_meta_descriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import FileDescriptorSet [as 别名]
def load_meta_descriptor(self):
"""
Load the protobuf version of descriptor.proto to use it in
decoding protobuf paths.
"""
fpath = os.path.abspath(os.path.join(os.path.dirname(__file__),
'descriptor.desc'))
with open(fpath, 'r') as f:
blob = f.read()
proto = descriptor_pb2.FileDescriptorSet()
proto.ParseFromString(blob)
assert len(proto.file) == 1
return proto.file[0]