Skip to content

Commit

Permalink
Report gapic generation to metadata
Browse files Browse the repository at this point in the history
Metadata now looks like this:

```
{
  "sources": [
    {
      "generator": {
        "name": "artman",
        "version": "0.16.2",
        "dockerImage": "googleapis/artman@sha256:2f6b261ee7fe1aedf238991c93a20b3820de37a343d0cacf3e3e9555c2aaf2ea"
      }
    },
    {
      "template": {
        "name": "python_library",
        "origin": "synthtool.gcp",
        "version": "2018.11.28"
      }
    },
    {
      "git": {
        "name": "googleapis",
        "remote": "https://github.com/googleapis/googleapis.git",
        "sha": "58249308b9c7bd64ba18ce99100751397e5184a7",
        "internalRef": "223077517"
      }
    }
  ],
  "destinations": [
    {
      "client": {
        "source": "googleapis",
        "apiName": "vision",
        "apiVersion": "v1",
        "language": "python",
        "generator": "gapic",
        "config": "google/cloud/vision/artman_vision_v1.yaml"
      }
    }
  ]
}
```
  • Loading branch information
theacodes committed Nov 30, 2018
1 parent e9c0f04 commit 0b79ad3
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
10 changes: 10 additions & 0 deletions synthtool/gcp/gapic_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from synthtool import _tracked_paths
from synthtool import log
from synthtool import metadata
from synthtool.gcp import artman
from synthtool.sources import git

Expand Down Expand Up @@ -128,6 +129,15 @@ def _generate_code(

log.success(f"Generated code into {genfiles}.")

metadata.add_client_destination(
source="googleapis" if not private else "googleapis-private",
api_name=service,
api_version=version,
language=language,
generator="gapic",
config=str(config_path),
)

_tracked_paths.add(genfiles)
return genfiles

Expand Down
5 changes: 5 additions & 0 deletions synthtool/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def add_template_source(**kwargs) -> None:
_metadata.sources.add(template=metadata_pb2.TemplateSource(**kwargs))


def add_client_destination(**kwargs) -> None:
"""Adds a client library destination to the current metadata."""
_metadata.destinations.add(client=metadata_pb2.ClientDestination(**kwargs))


def write(outfile: str = "synth.metadata") -> None:
"""Writes out the metadata to a file."""
jsonified = google.protobuf.json_format.MessageToJson(_metadata)
Expand Down
13 changes: 9 additions & 4 deletions synthtool/protos/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ message Destination {
}

message ClientDestination {
string api_name = 1;
string api_version = 2;
string generator = 3;
string source = 4;
string source = 1;
string api_name = 2;
string api_version = 3;
string language = 4;
string generator = 5;
string config = 6;
}

// Currently unused as storing all file destination options will likely cause
// the metadata file to be too large and may cause autosynth trashing. We'll
// investigate using this in the future.
message FileSetDestination {
string source = 1;
repeated string files = 2;
Expand Down
60 changes: 48 additions & 12 deletions synthtool/protos/metadata_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,39 @@ def test_add_generator_source():
assert current.sources[0].generator.version == "1.2.3"


def test_add_template_source():
metadata.reset()

metadata.add_template_source(name="name", version="1.2.3")

current = metadata.get()

assert current.sources[0].template.name == "name"
assert current.sources[0].template.version == "1.2.3"


def test_add_client_destination():
metadata.reset()

metadata.add_client_destination(
source="source",
api_name="api",
api_version="v1",
language="py",
generator="gen",
config="config",
)

current = metadata.get()

assert current.destinations[0].client.source == "source"
assert current.destinations[0].client.api_name == "api"
assert current.destinations[0].client.api_version == "v1"
assert current.destinations[0].client.language == "py"
assert current.destinations[0].client.generator == "gen"
assert current.destinations[0].client.config == "config"


def test_write(tmpdir):
metadata.reset()

Expand Down

0 comments on commit 0b79ad3

Please sign in to comment.