GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: generate snippet metadata by busunkim96 · Pull Request #1129 · googleapis/gapic-generator-python
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
Conversation
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # output_files[manifest_fname] = CodeGeneratorResponse.File( | ||
| # content=manifest_doc.render(), name=manifest_fname | ||
| # ) | ||
| if len(index.metadata_index.snippets) > 0: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit:
if index.metadata_index.snippets:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # NOTE(busunkim): Not all fields are yet populated in the snippet metadata. | ||
| # Expected filename: snippet_metadata_{metadata_schema_version}_{apishortname}_{apiversion}.json | ||
| snippet_metadata_path = str(pathlib.Path( | ||
| out_dir) / f"snippet_metadata_v1_{api_schema.naming.name}_{api_schema.naming.version}.json").lower() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
To clarify: the v1 here is about the snippet metadata itself, correct?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes! Amanda left a note below saying the metadata will not be versioned for now though, so I'll go ahead and remove it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # NOTE(busunkim): Not all fields are yet populated in the snippet metadata. | ||
| # Expected filename: snippet_metadata_{metadata_schema_version}_{apishortname}_{apiversion}.json |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is this comment still relevant, or is it cruft?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yep still relevant, there's a lot of fields that are not yet filled out.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| opts: Options, | ||
| api_schema=api.API, | ||
| **context: Mapping, | ||
| api_schema: api.API, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Doh! Good catch.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| raise types.InvalidConfig( | ||
| "Sample config is invalid", valid) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Outside the scope of the review, but taking a second look, this isn't very helpful. Do you think it would be better to include the config or the filepath tothe config here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Modified the error message to look like this:
if not valid: raise types.InvalidConfig( "Sample config in '{}' is invalid\n\n{}".format(config_fpath, cfg), valid)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| def generate_sample(sample, api_schema, sample_template: jinja2.Template) -> str: | ||
| def generate_sample(sample, api_schema, sample_template: jinja2.Template) -> Tuple[str, Any]: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why use Any as the type of the second second element instead of the real type? Is it related to the # type: ignore a few lines down?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, since the type is ignored I cannot use it in an annotation. I learned about mypy-protobuf from a PR with Tres though, so I'll open a separate PR to start type checking all the protobuf types.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| {% endif %} | ||
| r"""{{ method.meta.doc|rst(width=72, indent=8) }} | ||
|
|
||
| .. code-block:: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should the .. code-block:: be inside the if statement a few lines below?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ahh good catch, this would have created a lot of noise in the regen PRs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
| .. code-block:: | ||
| from google.cloud import asset_v1 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This indentation is a little unfortunate, but we can probably ignore it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hrrm I didn't notice this earlier, I'll try poking at the template to see where this is coming from.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of comments on the generated metadata file, but it looks good!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,1048 @@ | |||
| { | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For the time beeing, we dropped versioning of the metadata scheam so you can drop the first v1 here.
Also, we are doing, where possible, snippet_metadata_{protopackage}.json, although the real important part is snippet_metadata*.json as the rest of the name is not going to be used to identify anything automatically.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "clientMethod": { | ||
| "async": true, | ||
| "method": { | ||
| "fullName": "AnalyzeIamPolicyLongrunning", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fullName shuld be the RPC method name qualified by the proto package and the service name
This looks more like shortName.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ack, I'll switch this out for shortName.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| "method": { | ||
| "fullName": "AnalyzeIamPolicyLongrunning", | ||
| "service": { | ||
| "shortName": "AssetService" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
And fullName would be the service name qualified by the proto package.
Fine if this is one the ones you are adding later.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| } | ||
| }, | ||
| "file": "samples/generated_samples/cloudasset_generated_asset_v1_asset_service_analyze_iam_policy_longrunning_async.py", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This path should be relative to the location of this metadata file. Just double checking that's the case.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ah it's currently relative to the library root. I'll remove the samples/generated_samples since the metadata sits in the same directory as the snippets.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.