diff --git a/.flake8 b/.flake8 index a6f727b8d..723cf00f2 100644 --- a/.flake8 +++ b/.flake8 @@ -1,2 +1,3 @@ [flake8] ignore = E501, W503 +exclude = *_pb2.py diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 000000000..8b2783981 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,7 @@ +[mypy] +python_version = 3.6 +ignore_missing_imports = True + + +[mypy-synthtool.protos.*] +ignore_errors = True diff --git a/noxfile.py b/noxfile.py index b0d7b8579..9ea94356b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -27,7 +27,7 @@ def lint(session): session.run('pip', 'install', '-e', '.') session.run('black', '--check', 'synthtool', 'tests') session.run('flake8', 'synthtool', 'tests') - session.run('mypy', '--ignore-missing-imports', 'synthtool') + session.run('mypy', 'synthtool') @nox.session(python='3.6') @@ -35,3 +35,10 @@ def test(session): session.install('pytest') session.run('pip', 'install', '-e', '.') session.run('pytest', 'tests', *session.posargs) + + +@nox.session(python='3.6') +def generate_protos(session): + session.install("grpcio-tools") + session.run( + "python", "-m", "grpc_tools.protoc", "-Isynthtool/protos", "--python_out=synthtool/protos", "synthtool/protos/metadata.proto") diff --git a/setup.py b/setup.py index 612489124..a688b0aef 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ "jinja2", "packaging", "requests", + "protobuf", ] packages = setuptools.find_packages() diff --git a/synthtool/protos/__init__.py b/synthtool/protos/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/synthtool/protos/metadata.proto b/synthtool/protos/metadata.proto new file mode 100644 index 000000000..e79feaf86 --- /dev/null +++ b/synthtool/protos/metadata.proto @@ -0,0 +1,75 @@ +// Copyright 2018 Google LLC +// +// 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 +// +// https://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"; + +package yoshi.synth.metadata; + +import "google/protobuf/timestamp.proto"; + + +message Metadata { + google.protobuf.Timestamp update_time = 1; + + repeated Source sources = 2; + repeated Destination destinations = 3; +} + +message Source { + oneof source { + GitSource git = 1; + GeneratorSource generator = 2; + TemplateSource template = 3; + } +} + +message GitSource { + string name = 1; + string remote = 2; + string sha = 3; + + // If this Git is a mirror of an internal repository, such as google3 or + // Git-on-Borg, you can include an internal ref to it here. + string internal_ref = 4; +} + +message GeneratorSource { + string name = 1; + string version = 2; +} + +message TemplateSource { + string name = 1; + string origin = 2; + string version = 3; +} + +message Destination { + oneof Destination { + ClientDestination client = 1; + FileSetDestination fileset = 2; + } +} + +message ClientDestination { + string api_name = 1; + string api_version = 2; + string generator = 3; + string source = 4; +} + +message FileSetDestination { + string source = 1; + repeated string files = 2; +} diff --git a/synthtool/protos/metadata_pb2.py b/synthtool/protos/metadata_pb2.py new file mode 100644 index 000000000..129f5281e --- /dev/null +++ b/synthtool/protos/metadata_pb2.py @@ -0,0 +1,756 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: metadata.proto + +import sys + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database + +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name="metadata.proto", + package="yoshi.synth.metadata", + syntax="proto3", + serialized_options=None, + serialized_pb=_b( + '\n\x0emetadata.proto\x12\x14yoshi.synth.metadata\x1a\x1fgoogle/protobuf/timestamp.proto"\xa3\x01\n\x08Metadata\x12/\n\x0bupdate_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12-\n\x07sources\x18\x02 \x03(\x0b\x32\x1c.yoshi.synth.metadata.Source\x12\x37\n\x0c\x64\x65stinations\x18\x03 \x03(\x0b\x32!.yoshi.synth.metadata.Destination"\xb8\x01\n\x06Source\x12.\n\x03git\x18\x01 \x01(\x0b\x32\x1f.yoshi.synth.metadata.GitSourceH\x00\x12:\n\tgenerator\x18\x02 \x01(\x0b\x32%.yoshi.synth.metadata.GeneratorSourceH\x00\x12\x38\n\x08template\x18\x03 \x01(\x0b\x32$.yoshi.synth.metadata.TemplateSourceH\x00\x42\x08\n\x06source"L\n\tGitSource\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06remote\x18\x02 \x01(\t\x12\x0b\n\x03sha\x18\x03 \x01(\t\x12\x14\n\x0cinternal_ref\x18\x04 \x01(\t"0\n\x0fGeneratorSource\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\t"?\n\x0eTemplateSource\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06origin\x18\x02 \x01(\t\x12\x0f\n\x07version\x18\x03 \x01(\t"\x94\x01\n\x0b\x44\x65stination\x12\x39\n\x06\x63lient\x18\x01 \x01(\x0b\x32\'.yoshi.synth.metadata.ClientDestinationH\x00\x12;\n\x07\x66ileset\x18\x02 \x01(\x0b\x32(.yoshi.synth.metadata.FileSetDestinationH\x00\x42\r\n\x0b\x44\x65stination"]\n\x11\x43lientDestination\x12\x10\n\x08\x61pi_name\x18\x01 \x01(\t\x12\x13\n\x0b\x61pi_version\x18\x02 \x01(\t\x12\x11\n\tgenerator\x18\x03 \x01(\t\x12\x0e\n\x06source\x18\x04 \x01(\t"3\n\x12\x46ileSetDestination\x12\x0e\n\x06source\x18\x01 \x01(\t\x12\r\n\x05\x66iles\x18\x02 \x03(\tb\x06proto3' + ), + dependencies=[google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR], +) + + +_METADATA = _descriptor.Descriptor( + name="Metadata", + full_name="yoshi.synth.metadata.Metadata", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="update_time", + full_name="yoshi.synth.metadata.Metadata.update_time", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="sources", + full_name="yoshi.synth.metadata.Metadata.sources", + index=1, + number=2, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="destinations", + full_name="yoshi.synth.metadata.Metadata.destinations", + index=2, + number=3, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=74, + serialized_end=237, +) + + +_SOURCE = _descriptor.Descriptor( + name="Source", + full_name="yoshi.synth.metadata.Source", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="git", + full_name="yoshi.synth.metadata.Source.git", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="generator", + full_name="yoshi.synth.metadata.Source.generator", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="template", + full_name="yoshi.synth.metadata.Source.template", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name="source", + full_name="yoshi.synth.metadata.Source.source", + index=0, + containing_type=None, + fields=[], + ) + ], + serialized_start=240, + serialized_end=424, +) + + +_GITSOURCE = _descriptor.Descriptor( + name="GitSource", + full_name="yoshi.synth.metadata.GitSource", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="name", + full_name="yoshi.synth.metadata.GitSource.name", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="remote", + full_name="yoshi.synth.metadata.GitSource.remote", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="sha", + full_name="yoshi.synth.metadata.GitSource.sha", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="internal_ref", + full_name="yoshi.synth.metadata.GitSource.internal_ref", + index=3, + number=4, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=426, + serialized_end=502, +) + + +_GENERATORSOURCE = _descriptor.Descriptor( + name="GeneratorSource", + full_name="yoshi.synth.metadata.GeneratorSource", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="name", + full_name="yoshi.synth.metadata.GeneratorSource.name", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="version", + full_name="yoshi.synth.metadata.GeneratorSource.version", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=504, + serialized_end=552, +) + + +_TEMPLATESOURCE = _descriptor.Descriptor( + name="TemplateSource", + full_name="yoshi.synth.metadata.TemplateSource", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="name", + full_name="yoshi.synth.metadata.TemplateSource.name", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="origin", + full_name="yoshi.synth.metadata.TemplateSource.origin", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="version", + full_name="yoshi.synth.metadata.TemplateSource.version", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=554, + serialized_end=617, +) + + +_DESTINATION = _descriptor.Descriptor( + name="Destination", + full_name="yoshi.synth.metadata.Destination", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="client", + full_name="yoshi.synth.metadata.Destination.client", + index=0, + number=1, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="fileset", + full_name="yoshi.synth.metadata.Destination.fileset", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name="Destination", + full_name="yoshi.synth.metadata.Destination.Destination", + index=0, + containing_type=None, + fields=[], + ) + ], + serialized_start=620, + serialized_end=768, +) + + +_CLIENTDESTINATION = _descriptor.Descriptor( + name="ClientDestination", + full_name="yoshi.synth.metadata.ClientDestination", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="api_name", + full_name="yoshi.synth.metadata.ClientDestination.api_name", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="api_version", + full_name="yoshi.synth.metadata.ClientDestination.api_version", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="generator", + full_name="yoshi.synth.metadata.ClientDestination.generator", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="source", + full_name="yoshi.synth.metadata.ClientDestination.source", + index=3, + number=4, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=770, + serialized_end=863, +) + + +_FILESETDESTINATION = _descriptor.Descriptor( + name="FileSetDestination", + full_name="yoshi.synth.metadata.FileSetDestination", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="source", + full_name="yoshi.synth.metadata.FileSetDestination.source", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="files", + full_name="yoshi.synth.metadata.FileSetDestination.files", + index=1, + number=2, + type=9, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=865, + serialized_end=916, +) + +_METADATA.fields_by_name[ + "update_time" +].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +_METADATA.fields_by_name["sources"].message_type = _SOURCE +_METADATA.fields_by_name["destinations"].message_type = _DESTINATION +_SOURCE.fields_by_name["git"].message_type = _GITSOURCE +_SOURCE.fields_by_name["generator"].message_type = _GENERATORSOURCE +_SOURCE.fields_by_name["template"].message_type = _TEMPLATESOURCE +_SOURCE.oneofs_by_name["source"].fields.append(_SOURCE.fields_by_name["git"]) +_SOURCE.fields_by_name["git"].containing_oneof = _SOURCE.oneofs_by_name["source"] +_SOURCE.oneofs_by_name["source"].fields.append(_SOURCE.fields_by_name["generator"]) +_SOURCE.fields_by_name["generator"].containing_oneof = _SOURCE.oneofs_by_name["source"] +_SOURCE.oneofs_by_name["source"].fields.append(_SOURCE.fields_by_name["template"]) +_SOURCE.fields_by_name["template"].containing_oneof = _SOURCE.oneofs_by_name["source"] +_DESTINATION.fields_by_name["client"].message_type = _CLIENTDESTINATION +_DESTINATION.fields_by_name["fileset"].message_type = _FILESETDESTINATION +_DESTINATION.oneofs_by_name["Destination"].fields.append( + _DESTINATION.fields_by_name["client"] +) +_DESTINATION.fields_by_name["client"].containing_oneof = _DESTINATION.oneofs_by_name[ + "Destination" +] +_DESTINATION.oneofs_by_name["Destination"].fields.append( + _DESTINATION.fields_by_name["fileset"] +) +_DESTINATION.fields_by_name["fileset"].containing_oneof = _DESTINATION.oneofs_by_name[ + "Destination" +] +DESCRIPTOR.message_types_by_name["Metadata"] = _METADATA +DESCRIPTOR.message_types_by_name["Source"] = _SOURCE +DESCRIPTOR.message_types_by_name["GitSource"] = _GITSOURCE +DESCRIPTOR.message_types_by_name["GeneratorSource"] = _GENERATORSOURCE +DESCRIPTOR.message_types_by_name["TemplateSource"] = _TEMPLATESOURCE +DESCRIPTOR.message_types_by_name["Destination"] = _DESTINATION +DESCRIPTOR.message_types_by_name["ClientDestination"] = _CLIENTDESTINATION +DESCRIPTOR.message_types_by_name["FileSetDestination"] = _FILESETDESTINATION +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +Metadata = _reflection.GeneratedProtocolMessageType( + "Metadata", + (_message.Message,), + dict( + DESCRIPTOR=_METADATA, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.Metadata) + ), +) +_sym_db.RegisterMessage(Metadata) + +Source = _reflection.GeneratedProtocolMessageType( + "Source", + (_message.Message,), + dict( + DESCRIPTOR=_SOURCE, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.Source) + ), +) +_sym_db.RegisterMessage(Source) + +GitSource = _reflection.GeneratedProtocolMessageType( + "GitSource", + (_message.Message,), + dict( + DESCRIPTOR=_GITSOURCE, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.GitSource) + ), +) +_sym_db.RegisterMessage(GitSource) + +GeneratorSource = _reflection.GeneratedProtocolMessageType( + "GeneratorSource", + (_message.Message,), + dict( + DESCRIPTOR=_GENERATORSOURCE, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.GeneratorSource) + ), +) +_sym_db.RegisterMessage(GeneratorSource) + +TemplateSource = _reflection.GeneratedProtocolMessageType( + "TemplateSource", + (_message.Message,), + dict( + DESCRIPTOR=_TEMPLATESOURCE, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.TemplateSource) + ), +) +_sym_db.RegisterMessage(TemplateSource) + +Destination = _reflection.GeneratedProtocolMessageType( + "Destination", + (_message.Message,), + dict( + DESCRIPTOR=_DESTINATION, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.Destination) + ), +) +_sym_db.RegisterMessage(Destination) + +ClientDestination = _reflection.GeneratedProtocolMessageType( + "ClientDestination", + (_message.Message,), + dict( + DESCRIPTOR=_CLIENTDESTINATION, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.ClientDestination) + ), +) +_sym_db.RegisterMessage(ClientDestination) + +FileSetDestination = _reflection.GeneratedProtocolMessageType( + "FileSetDestination", + (_message.Message,), + dict( + DESCRIPTOR=_FILESETDESTINATION, + __module__="metadata_pb2" + # @@protoc_insertion_point(class_scope:yoshi.synth.metadata.FileSetDestination) + ), +) +_sym_db.RegisterMessage(FileSetDestination) + + +# @@protoc_insertion_point(module_scope) diff --git a/tests/test_metadata_protos.py b/tests/test_metadata_protos.py new file mode 100644 index 000000000..3e8d19dfd --- /dev/null +++ b/tests/test_metadata_protos.py @@ -0,0 +1,57 @@ +# Copyright 2018 Google LLC +# +# 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 +# +# https://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. + +import google.protobuf.json_format + +from synthtool.protos import metadata_pb2 + + +def test_basic_operation(): + metadata = metadata_pb2.Metadata() + metadata.sources.add( + git=metadata_pb2.GitSource( + name="test name", remote="test remote", sha="test sha" + ) + ) + + assert metadata.sources[0].git.name == "test name" + + +def test_to_json(): + metadata = metadata_pb2.Metadata() + metadata.sources.add( + git=metadata_pb2.GitSource( + name="test name", remote="test remote", sha="test sha" + ) + ) + + jsonified = google.protobuf.json_format.MessageToJson(metadata) + + assert ( + jsonified + == """\ +{ + "sources": [ + { + "git": { + "name": "test name", + "remote": "test remote", + "sha": "test sha" + } + } + ] +}""" + ) + + print(jsonified)