GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add snippet index by busunkim96 · Pull Request #1121 · googleapis/gapic-generator-python

This repository was archived by the owner on Aug 25, 2026. It is now read-only.

Conversation

@busunkim96

@busunkim96 busunkim96 commented Jan 5, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR adds snippet_metadata.proto and another samplegen utils class to store the snippets so that they can be looked up by library template code.

PRs to begin generating metadata and add the samples to the library docstrings will follow (I originally planned it for one PR, but the changeset was a bit too big).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@busunkim96
feat: add snippet index
4e39389
@snippet-bot

snippet-bot Bot commented Jan 5, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 2 region tags.
  • tests/unit/samplegen/test_snippet_index.py:27, tag mollusc_classify_sync
  • tests/unit/samplegen/test_snippet_index.py:81, tag ...

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

busunkim96 added 2 commits January 5, 2022 16:46
@busunkim96
chore: undo changes to common_types
ffe81b7
@busunkim96
chore: delete extra init
1279dc5
software-dov
software-dov reviewed Jan 5, 2022
View reviewed changes

@software-dov software-dov left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job and nice tests.
I'm a little unclear about the dataflow here, please correct me if this is wrong.

  1. A snippet is generated, either manually or by snippetgen
  2. We send the snippet text into snippet_index.Snippet, which parses it and adds line number tags to particular sections.
  3. (TODO) We update the generated documentation (and documentation generation code) to point to these particular regions as in-text assistance.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/samplegen_utils/snippet_index.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/samplegen_utils/snippet_index.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/samplegen_utils/snippet_index.py Outdated
Comment on lines +100 to +101
# This will be need to be re-structured when one method can have
# more than one sample variant

@software-dov software-dov Jan 5, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a little bit on what this would look like? Is the method dictionary going to have more keys with more descriptive names? It seems like this would have a fairly large effect on add_snippet and get_snippet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@busunkim96 busunkim96 Jan 5, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, there will be "configured" samples (2+ variants that set different parameters on the request). Right now we're still in the exploratory phase for config based snippets so I punted on creating something more complex and went with a dictionary. I imagine a different data structure (and a re-write of methods in this class) might be needed once there's more knobs.

It seems like this would have a fairly large effect on add_snippet and get_snippet.

Yep, agreed, my hope is that jinja template code can stay relatively stable and rely on get_snippet(...) to collect whatever variant of the sample it needs.

I'll update the comment in the code to elaborate a bit more as well!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/samplegen_utils/snippet_metadata.proto Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/samplegen/test_snippet_index.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

busunkim96 added 2 commits January 6, 2022 20:21
@busunkim96
fix: apply review suggestions, edit comments
477ed85
@busunkim96
chore: fix spacing
b2db90b
@busunkim96
busunkim96 marked this pull request as ready for review January 6, 2022 20:39
@busunkim96
busunkim96 requested review from a team and amanda-tarafa January 6, 2022 20:39
busunkim96 added 4 commits January 6, 2022 21:55
@busunkim96
chore: undo premature change to common_types.py
7eb7eb6
@busunkim96
chore: update docstrings
779bd89
@busunkim96
chore: format
7fb25d3
@busunkim96
fix: re-add change to common_types
2eb5179
software-dov
software-dov approved these changes Jan 6, 2022
View reviewed changes

@software-dov software-dov left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one ongoing question and two test concatenations.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/samplegen_utils/snippet_metadata.proto Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/samplegen_utils/snippet_metadata.proto Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/samplegen/test_snippet_index.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

amanda-tarafa
amanda-tarafa approved these changes Jan 7, 2022
View reviewed changes

@amanda-tarafa amanda-tarafa left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/samplegen_utils/snippet_metadata.proto Resolved

Uh oh!

There was an error while loading. Please reload this page.

software-dov
software-dov approved these changes Jan 7, 2022
View reviewed changes
@busunkim96

busunkim96 commented Jan 10, 2022

Copy link
Copy Markdown
Contributor Author
  1. A snippet is generated, either manually or by snippetgen
  2. We send the snippet text into snippet_index.Snippet, which parses it and adds line number tags to particular sections.
  3. (TODO) We update the generated documentation (and documentation generation code) to point to these particular regions as in-text assistance.

I realized I didn't see this earlier, but yes, this is the planned flow! The library docstrings will use the "full snippet" (snippet minus region tags), but other tools consuming the snippets might use a different combination of sections.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@busunkim96
test: combine get and add snippet tests
ae35cd3
@busunkim96
busunkim96 merged commit 55d2bc6 into master Jan 10, 2022
@busunkim96
busunkim96 deleted the generate-snippet-index branch January 10, 2022 15:56
@busunkim96 busunkim96 mentioned this pull request Jan 11, 2022
feat: generate snippet metadata #1129
Merged
@release-please release-please Bot mentioned this pull request Jan 18, 2022
chore(master): release reverted #1133
Merged
busunkim96 added a commit that referenced this pull request Jan 18, 2022
@busunkim96
feat: generate snippet metadata (#1129)
9e46031
Follow up to #1121.

**Main changes:**
* When snippets are generated, snippet metadata is also generated.
* If a method has a snippet, that snippet is included in the method docstring.

**Other changes:**
* Removed the method docstring in the code snippet file (line right below the method definition) since the same text is already in the comment block at the top of the file.
* Removed the concept of a "standalone" sample. All generated samples are expected to be standalone. When someone wants a smaller portion of the sample (e.g., request initialization only) they should fetch it from the file by looking up the line numbers in the snippet metadata file.

Other Notes:
* ~It doesn't look like it's possible to do type annotations with `_pb2` types, so those are annotated as `Any`.~ It is possible to do mypy checking with https://github.com/dropbox/mypy-protobuf, but I think it will be easier make that change in a separate PR.
* There are a lot of golden file updates, [this range of commits](https://github.com/googleapis/gapic-generator-python/pull/1129/files/872c156f5100f1de20631dd59d083206432db374) has _most_ of the generator and test changes.
This was referenced Jan 19, 2022
chore(master): release 0.40.0 #1138
Closed
chore(master): release 0.39.1 #1146
Closed
This was referenced Jan 26, 2022
chore(main): release 0.39.1 #1160
Closed
chore(main): release 0.39.1 #1162
Closed
chore(main): release 0.61.0 #1163
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@software-dov software-dov software-dov approved these changes
@amanda-tarafa amanda-tarafa amanda-tarafa approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@busunkim96 @software-dov @amanda-tarafa
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.