Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

docs(samples): Adding template samples #136

Merged
merged 20 commits into from Nov 17, 2021
Merged

docs(samples): Adding template samples #136

merged 20 commits into from Nov 17, 2021

Conversation

m-strzelczyk
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label bot added the api: compute Issues related to the googleapis/python-compute API. label Oct 19, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 19, 2021
@m-strzelczyk m-strzelczyk changed the title Samples templates chore(docs): Adding template samples Oct 19, 2021
@m-strzelczyk m-strzelczyk added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 19, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 19, 2021
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Oct 20, 2021
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
@m-strzelczyk m-strzelczyk marked this pull request as ready for review November 3, 2021 17:01
@m-strzelczyk m-strzelczyk requested a review from a team as a code owner November 3, 2021 17:01
samples/snippets/test_sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/sample_templates.py Show resolved Hide resolved
from google.cloud import compute_v1


def get_instance_template(project_id: str, template_name: str) -> compute_v1.InstanceTemplate:
Copy link
Contributor

Choose a reason for hiding this comment

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

generally the preferred style for newly written samples is one sample per file, as it allows for imports to be included in the region tags: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#region-tags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the guide you linked doesn't really state that there should be 1:1 ratio between files and samples and I've been doing multiple samples per file for some time now in this repo. See for example vm creation samples. This way imports are included in the samples just fine.

I've read the internal "Code Snippets 201" guide and figured that this is the best way to group the samples. I plan to reorganize the samples soon, to introduce more structure with folders for example. If there are reasons to introduce 1 sample = 1 file division, I'd like to know it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason is essentially enforcement/ease of use. With your samples, their is only one import so it's very complicated. However if a new import would be added for whatever reason, it should only apply to the sample using it, which becomes more complicated. Same with when an import needs to be removed - if it's no longer using it in the sample (but is in a different sample in the same file), flake8 can't catch that it's only being used in some region tags but not all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I see your point. I will reorganize those samples soon, as we were planning to do a bigger refactoring of how we keep the samples for the Compute documentation in multiple languages.

Could you just suggest what would be the best course of action, when there are rather big pieces of code repeating in multiple samples like in the vm creation samples? There, the create_with_disks method is used by 6 different samples. Can a region snap multiple files? If not, I will have to replicate this code multiple times...

Copy link
Contributor

Choose a reason for hiding this comment

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

It depends on how you arrange the samples on the page. If there really is a certain amount of boiler plate, you could create a different region tag for that section and have a different region tag that references. However, it's probably feasible to just integrate it as part of the main samples.

samples/snippets/test_sample_templates.py Outdated Show resolved Hide resolved
@parthea parthea assigned m-strzelczyk and unassigned kurtisvg Nov 8, 2021
@snippet-bot
Copy link

snippet-bot bot commented Nov 8, 2021

Here is the summary of changes.

You are about to add 13 region tags.

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

@parthea parthea assigned kurtisvg and unassigned m-strzelczyk Nov 9, 2021
@parthea parthea changed the title chore(docs): Adding template samples docs(samples): Adding template samples Nov 9, 2021
samples/snippets/test_sample_templates.py Outdated Show resolved Hide resolved
samples/snippets/test_sample_templates.py Outdated Show resolved Hide resolved
@parthea
Copy link
Contributor

parthea commented Nov 16, 2021

@kurtisvg Please could you review/approve?

from google.cloud import compute_v1


def get_instance_template(project_id: str, template_name: str) -> compute_v1.InstanceTemplate:
Copy link
Contributor

Choose a reason for hiding this comment

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

It depends on how you arrange the samples on the page. If there really is a certain amount of boiler plate, you could create a different region tag for that section and have a different region tag that references. However, it's probably feasible to just integrate it as part of the main samples.

@kurtisvg
Copy link
Contributor

Also as FYI, GitHub has a request review button that is good for flagging you're ready for another review:
image

@parthea
Copy link
Contributor

parthea commented Nov 16, 2021

@kurtisvg, sorry for the ping. I was having trouble with the request review button for @Xmasreturns. It's not working when I click it.

Copy link
Contributor

@kurtisvg kurtisvg left a comment

Choose a reason for hiding this comment

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

No worries 👍

@m-strzelczyk m-strzelczyk merged commit bc721a7 into main Nov 17, 2021
@m-strzelczyk m-strzelczyk deleted the samples-templates branch November 17, 2021 15:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: compute Issues related to the googleapis/python-compute API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants