gapic-generator-python
gapic-generator-python copied to clipboard
Unable to generate client if it has a proto-plus dependency with a modified namespace
The test //google/cloud/policytroubleshooter/iam/v3:iam_py_gapic_test is failing once I add google.iam.v2 as a proto-plus dependency.
Steps to reproduce the issue:
- Update the
google/cloud/policytroubleshooter/iam/v3/BUILD.bazelfile with the following code:
load(
"@com_google_googleapis_imports//:imports.bzl",
"py_gapic_assembly_pkg",
"py_gapic_library",
"py_import",
"py_test"
)
py_import(
name="iam_v2",
srcs = [
"//google/iam/v2:iam_py_gapic",
],
)
py_gapic_library(
name = "iam_py_gapic",
srcs = [":iam_proto"],
grpc_service_config = "policytroubleshooter_v3_grpc_service_config.json",
rest_numeric_enums = True,
service_yaml = "policytroubleshooter_v3.yaml",
transport = "grpc+rest",
deps = [
":iam_v2",
"//google/iam/v1:iam_policy_py_proto",
],
opt_args = [
"python-gapic-namespace=google.cloud",
"python-gapic-name=policytroubleshooter_iam",
"proto-plus-deps=google.iam.v2"
],
)
Run the test:
bazel run //google/cloud/policytroubleshooter/iam/v3:iam_py_gapic_test
Error message:
==================================== ERRORS ====================================
_ ERROR collecting tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py _
ImportError while importing test module '/usr/local/google/home/omairn/.cache/bazel/_bazel_omairn/9febfd2a38daa3aed258879a45f94c15/execroot/com_google_googleapis/bazel-out/k8-fastbuild/bin/google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_test.runfiles/com_google_googleapis/google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../../../../../../../../../../external/python39_x86_64-unknown-linux-gnu/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py:46: in <module>
from google.cloud.policytroubleshooter_iam_v3.services.policy_troubleshooter import PolicyTroubleshooterAsyncClient
google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/google/cloud/policytroubleshooter_iam_v3/__init__.py:21: in <module>
from .services.policy_troubleshooter import PolicyTroubleshooterClient
google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/__init__.py:16: in <module>
from .client import PolicyTroubleshooterClient
google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/google/cloud/policytroubleshooter_iam_v3/services/policy_troubleshooter/client.py:38: in <module>
from google.cloud.policytroubleshooter_iam_v3.types import troubleshooter
google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/google/cloud/policytroubleshooter_iam_v3/types/__init__.py:16: in <module>
from .troubleshooter import (
google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/google/cloud/policytroubleshooter_iam_v3/types/troubleshooter.py:23: in <module>
from google.iam_v2.types import policy as giv_policy
E ModuleNotFoundError: No module named 'google.iam_v2'
=========================== short test summary info ============================
ERROR google/cloud/policytroubleshooter/iam/v3/iam_py_gapic_srcjar.py/tests/unit/gapic/policytroubleshooter_iam_v3/test_policy_troubleshooter.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
8 warnings, 1 error in 1.57s
It seems like the test is complaining about the missing module google.iam_v2 which is correct. We need to investigate why the generator is not looking for the correct namespace mentioned in google/iam/v2/BUILD.bazel i.e. "python-gapic-namespace=google.cloud" and the module that it needs to look for should be google.cloud.iam_v2.