Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(workflows): refactor sample 'workflows_api_quickstart' to comply with the Samples Style Guide and fix tests #13261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

eapl-gemugami
Copy link
Contributor

@eapl-gemugami eapl-gemugami commented Mar 28, 2025

Description

Fixes Internal: b/391200147

  • Cleanup the code inside the region tags, to make it easier for the developer to follow the quickstart
  • Add _id suffix to project and workflow, to make more explicit what value is expected
  • Take out unnecessary os.getenvs and the return from the region tags
  • Move workflow creation to its own fixture, and create a conftest.py which will be reused for new samples in the same folder
  • Update to latest dependencies
  • Add exponential backoff as suggested in AUTHORING_GUIDE.md#retry-rpcs
  • As the __main__ entry points have been requested by 'glasnt' to stay in the scripts, but the Style guide suggests not to include them in the sample, it was adjusted accordingly

Checklist

- Take out unneccesary `os.getenv`s and the return from the sample
- As the `__main__` entry point is requested to stay in the script, but not in the sample, it was adjusted accordingly
@product-auto-label product-auto-label bot added api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples. labels Mar 28, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @eapl-gemugami, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request refactors the sample 'workflows_api_quickstart' to comply with the Samples Style Guide. The changes include cleaning up the code inside the region tags, removing unnecessary os.getenvs and returns from the region tags, and adjusting the placement of the __main__ entry point to align with the style guide's recommendations.

Highlights

  • Code Cleanup: The code within the region tags has been cleaned up to improve readability and ease of understanding for developers using the quickstart guide.
  • Environment Variables: Unnecessary os.getenvs calls have been removed to simplify the code and reduce dependencies.
  • main Entry Point: The placement of the __main__ entry point has been adjusted to comply with the Samples Style Guide while still retaining it in the script as requested.

Changelog

  • workflows/cloud-client/main.py
    • Removed unused imports and environment variable assignments at the beginning of the file.
    • Modified the execute_workflow function signature to accept project_id, location, and workflow_id as arguments.
    • Moved the import statements and TODO comments inside the execute_workflow function and within the region tag.
    • Updated the workflows_client.workflow_path call to use the new function arguments.
    • Moved the return execution statement inside the else block.
    • Moved the [END workflows_api_quickstart] tag to after the [END workflows_api_quickstart_execution] tag.
    • Moved the __main__ block to the end of the file and hardcoded the location and workflow id.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is the purpose of region tags in Google Cloud documentation samples?

Click here for the answer
Region tags are used to mark specific sections of code in documentation samples. These tags allow automated systems to extract and test these code snippets, ensuring the samples remain up-to-date and functional.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request aims to refactor the 'workflows_api_quickstart' sample to comply with the Samples Style Guide. The changes involve cleaning up the code inside region tags, removing unnecessary os.getenvs and returns, and adjusting the placement of the __main__ entry point. Overall, the changes improve the readability and maintainability of the sample code.

Summary of Findings

  • Hardcoded values: The script uses hardcoded values for location and workflow_id in the __main__ block. It's better to use environment variables or command-line arguments to configure these values for flexibility.
  • Missing error handling: The code lacks explicit error handling for API calls. Adding error handling would make the sample more robust and informative.

Merge Readiness

The pull request is almost ready for merging. Addressing the hardcoded values and adding error handling would further improve the quality of the sample. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.

workflows/cloud-client/main.py Show resolved Hide resolved
@eapl-gemugami eapl-gemugami added the snippet-bot:force-run Force snippet-bot runs its logic label Mar 28, 2025
@snippet-bot snippet-bot bot removed the snippet-bot:force-run Force snippet-bot runs its logic label Mar 28, 2025
Copy link

snippet-bot bot commented Mar 28, 2025

Here is the summary of changes.

You are about to add 1 region tag.
You are about to delete 1 region 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

@eapl-gemugami
Copy link
Contributor Author

eapl-gemugami commented Mar 28, 2025

I'm noticing that the Python 3.9 Test is failing, see log. Possibly due to temporary unavailability of the external API. This will be fixed by adding exponential backoff to the test.

The test SHOULD recreate the workflow (to apply the latest changes in the YAML definition), and delete the workflow after it was used.

The workflow creation will be fixed and moved to the conftest.py file.

@eapl-gemugami eapl-gemugami changed the title fix(workflows): refactor sample 'workflows_api_quickstart' to comply with the Samples Style Guide fix(workflows): refactor sample 'workflows_api_quickstart' to comply with the Samples Style Guide and fix tests Mar 28, 2025
@eapl-gemugami
Copy link
Contributor Author

@iennae I would like to have feedback from @davidcavazos or @glasnt on this refactor.
It's a follow-up for b/390011565 and b/391200147.

cc @OremGLG, I'm aware you are working on a related sample for Go, so the learning here could help you.

@iennae iennae requested review from glasnt and davidcavazos March 28, 2025 18:51
# [END workflows_api_quickstart_execution]
# [END workflows_api_quickstart]
return execution


if __name__ == "__main__":
Copy link
Contributor

Choose a reason for hiding this comment

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

As the main entry points have been requested by 'glasnt' to stay in the scripts, but the Style guide suggests not to include them in the sample, it was adjusted accordingly

Can you link to where you're reading this in the style guide?

As you can see in this example, the main method is included within the region tags, so we have an example of how to invoke the function. If the styleguide needs addressing, please raise this out of band.

Copy link
Contributor Author

@eapl-gemugami eapl-gemugami Mar 31, 2025

Choose a reason for hiding this comment

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

I couldn't fit a full explanation in a short sentence, @iennae we could discuss it internally.


  1. "Methods should avoid a return type whenever possible."
    samples-style-guide/#result

Python examples in the Style Guide don't show any return. For example: samples-style-guide/#pattern

Removing returns creates a conflict for samples developers, as returned values help with testing. See a previous review by 'davidcavazos' here.

I've seen a pattern in the repo, which I followed, where the returned object is outside of the sample region tags (so it won't be shown in the documentation).

But if I do that, the function definition shows a type hint of a returned object, when the sample doesn't have any (it should be a None then). What I find that complies with all above is not including the function definition part, as it's in this PR. That is the reason for my decision on the region tags positions.
For instance, my samples in View the access policy of a dataset and view_dataset_access_policy.py#L19

I see 'grayside' has addressed a related matter in Issue #169


  1. The style guide for Python doesn't show the use of if __name__ == "__main__":
    Only Java and PHP show something similar in Language-specific practices

Please check a previous review by 'davidcavazos' here and samples-style-guide/#no-cli
Review: "Supporting a CLI entry point means additional maintenance."
Guide: "Do not include CLIs for running your sample. [...] Previous practice shows that CLIs are expensive to maintain and detract from the purpose of the snippet."

In addition to external tools and CLIs such as glogin, I understand this part as running the sample from the Terminal by using python3 sample.py as well.

I see this has not been addressed as an Issue in the samples-style-guide repo.

@glasnt
Copy link
Contributor

glasnt commented Mar 30, 2025

PR still in draft, but it seems generally okay. Will wait for PR to come out of draft before detailed review.

update the copyright year
line 31: change "The Google Cloud project id" to "The ID of the Google Cloud project"
line 33: add a period
line 50: add one more space before the line comment per https://google.github.io/styleguide/pyguide#385-block-and-inline-comments
line 51: add a line comment (# For example: myFirstWorkflow)
@eapl-gemugami eapl-gemugami added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 31, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 31, 2025
@eapl-gemugami eapl-gemugami marked this pull request as ready for review March 31, 2025 17:15
@eapl-gemugami eapl-gemugami requested review from a team as code owners March 31, 2025 17:15
@eapl-gemugami eapl-gemugami requested a review from glasnt April 2, 2025 14:44
@eapl-gemugami
Copy link
Contributor Author

Hi! I have submitted changes requested by Camie, this PR is ready to be reviewed again.

I plan to use the approved style for this sample workflows_api_quickstart (in main.py), as a template for the next one I'm working on, Pass a runtime arg in a Workflows execution request. So your feedback will be really appreciated.

@glasnt glasnt merged commit ac3e8be into GoogleCloudPlatform:main Apr 4, 2025
11 checks passed
@eapl-gemugami eapl-gemugami deleted the paradalicea/fix/workflows/refactor-sample/api-quickstart/b-391200147 branch April 4, 2025 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.