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 — fix: correct import for request message type by dizcology · Pull Request #1273 · googleapis/gapic-generator-python

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

Conversation

@dizcology

@dizcology dizcology commented Apr 11, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Fixes: #1263

The generated snippet where the request message type is external to the client library package now becomes:

from google.cloud import resourcemanager_v3
from google.iam.v1 import iam_policy_pb2  # type: ignore


def sample_get_iam_policy():
    # Create a client
    client = resourcemanager_v3.ProjectsClient()

    # Initialize request argument(s)
    request = iam_policy_pb2.GetIamPolicyRequest(
        resource="resource_value",
    )

    # Make the request
    response = client.get_iam_policy(request=request)

    # Handle the response
    print(response)

Additional changes:

  • pytest fixtures in tests/unit/samplegen/test_samplegen.py are refactored to make it easier to add new unit test code without duplicating much of the code.

Sorry, something went wrong.

Uh oh!

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

All reactions
@dizcology
fix: correct import for request message type
92d6db1
@dizcology dizcology added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 11, 2022
@dizcology
dizcology requested review from a team April 11, 2022 00:42
@dizcology
use existing imports field in template
10066cb
@dizcology
dizcology marked this pull request as draft April 11, 2022 01:06
dizcology added 4 commits April 10, 2022 18:35
@dizcology
add request_module_name to sample
7a0e7fa
@dizcology
fix tests/unit/samplegen/test_integration.py
bfde259
@dizcology
fix tests/unit/samplegen/test_samplegen.py
a2e0a5c
@dizcology
fix style
0e3dfff
@dizcology dizcology removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 11, 2022
@dizcology
dizcology marked this pull request as ready for review April 11, 2022 06:07
@parthea parthea self-assigned this Apr 11, 2022
parthea
parthea suggested changes Apr 11, 2022
View reviewed changes

@parthea parthea 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.

Thanks for fixing this! The changes look good. I noticed a formatting issue in the downstream repo where 2 import statements appear are on the same line. Please could you take a look?

+            from google.cloud import resourcemanager_v3from google.iam.v1 import iam_policy_pb2  # type: ignore

Steps to re-create the issue:

  1. Modify the WORKSPACE file here to use local_repository instead of http_archive and point to a clone of gapic generator python with this branch.
  2. Run bazel build //google/cloud/resourcemanager/v3:resourcemanager-v3-py in the root of googleapis where you modified the WORKSPACE file in step 1
  3. Run the following in a clone of https://github.com/googleapis/python-resource-manager
docker run --rm --user $(id -u):$(id -g)   -v $(pwd):/repo   -v $HOME/git/googleapis/bazel-bin:/bazel-bin   gcr.io/cloud-devrel-public-resources/owlbot-cli:latest copy-bazel-bin   --source-dir /bazel-bin --dest /repo
docker run --user $(id -u):$(id -g) --rm -v $(pwd):/repo -w /repo gcr.io/cloud-devrel-public-resources/owlbot-python:latest
  1. Check the diff

Sorry, something went wrong.

Uh oh!

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

All reactions
@parthea parthea assigned dizcology and unassigned parthea Apr 11, 2022
@dizcology

dizcology commented Apr 11, 2022

Copy link
Copy Markdown
Contributor Author

@parthea Thanks for catching that! I think that is caused by https://github.com/googleapis/gapic-generator-python/blob/main/gapic/samplegen_utils/snippet_index.py#L91, but from the original PR containing that strip call I did not see any discussion about why it was needed. Is there a different styling requirement for these snippets in client method docstrings to have only one blank line before function definition, while in the standalone sample.py file there should be two blank lines?

All reactions

Sorry, something went wrong.

Uh oh!

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

@parthea

parthea commented Apr 11, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@dizcology I only see the formatting issue with the imports when I apply the changes from this PR. I don't see the issue in the main branch. It could be that the changes in this PR exposed an underlying issue. I haven't debugged that part of the code yet. Would you be interested in adding a test to verify the output of the sample generator? I don't see changes to the golden files based on the changes in this PR so it's possible that we don't have any checks for the generated sample code.

All reactions

Sorry, something went wrong.

Uh oh!

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

@dizcology
remove strip
f3ae0b5
@dizcology

dizcology commented Apr 12, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Looks like there is some magic in client method docstring rendering that suppresses multiple new lines in some cases, so that strip call was not needed after all. Updated generated code:

    def get_iam_policy(self,
            ...
            ) -> policy_pb2.Policy:
        r"""Returns the IAM access control policy for the
        specified project. Permission is denied if the policy or
        the resource do not exist.

        .. code-block:: python

            from google.cloud import resourcemanager_v3
            from google.iam.v1 import iam_policy_pb2  # type: ignore

            def sample_get_iam_policy():
                # Create a client
                client = resourcemanager_v3.ProjectsClient()

                # Initialize request argument(s)
                request = iam_policy_pb2.GetIamPolicyRequest(
                    resource="resource_value",
                )

                # Make the request
                response = client.get_iam_policy(request=request)

                # Handle the response
                print(response)
All reactions

Sorry, something went wrong.

Uh oh!

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

@dizcology
dizcology requested a review from parthea April 12, 2022 00:19
@dizcology
fix tests/unit/samplegen/test_snippet_index.py
35bb3e4
@parthea parthea assigned parthea and unassigned dizcology Apr 12, 2022
parthea
parthea approved these changes Apr 13, 2022
View reviewed changes
@parthea
parthea merged commit 3406d9e into googleapis:main Apr 13, 2022
@release-please release-please Bot mentioned this pull request Apr 13, 2022
chore(main): release 0.65.1 #1275
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@parthea parthea parthea approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

@parthea parthea

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

snippetgen: resourcemanager_v3.GetIamPolicyRequest type is not defined in the package but is described in the public doc example

Uh oh!

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

2 participants

@dizcology @parthea
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.