Skip to content
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

fix: add missing imports in __init__.py for autogenerated code #1049

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions google/cloud/spanner_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

# Copyright 2020 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,21 +13,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import absolute_import

from google.cloud.spanner_v1 import gapic_version as package_version

__version__: str = package_version.__version__
__version__ = package_version.__version__


from .services.spanner import SpannerClient
from .services.spanner import SpannerAsyncClient

from .types.commit_response import CommitResponse
from .types.keys import KeyRange as KeyRangePB
from .types.keys import KeySet as KeySetPB
from .types.mutation import Mutation
from .types.query_plan import PlanNode
from .types.query_plan import QueryPlan
from .types.result_set import PartialResultSet
from .types import RequestOptions
from .types.result_set import ResultSet
from .types.result_set import ResultSetMetadata
from .types.result_set import ResultSetStats
Expand All @@ -40,6 +39,7 @@
from .types.spanner import CommitRequest
from .types.spanner import CreateSessionRequest
from .types.spanner import DeleteSessionRequest
from .types.spanner import DirectedReadOptions
from .types.spanner import ExecuteBatchDmlRequest
from .types.spanner import ExecuteBatchDmlResponse
from .types.spanner import ExecuteSqlRequest
Expand All @@ -52,6 +52,7 @@
from .types.spanner import PartitionReadRequest
from .types.spanner import PartitionResponse
from .types.spanner import ReadRequest
from .types.spanner import RequestOptions
from .types.spanner import RollbackRequest
from .types.spanner import Session
from .types.transaction import Transaction
Expand Down Expand Up @@ -87,6 +88,8 @@
"param_types",
# google.cloud.spanner_v1.client
"Client",
# google.cloud.spanner_v1.data_types
"JsonObject",
# google.cloud.spanner_v1.keyset
"KeyRange",
"KeySet",
Expand All @@ -99,6 +102,7 @@
# local
"COMMIT_TIMESTAMP",
# google.cloud.spanner_v1.types
"SpannerAsyncClient",
"BatchCreateSessionsRequest",
"BatchCreateSessionsResponse",
"BatchWriteRequest",
Expand All @@ -108,6 +112,7 @@
"CommitResponse",
"CreateSessionRequest",
"DeleteSessionRequest",
"DirectedReadOptions",
"ExecuteBatchDmlRequest",
"ExecuteBatchDmlResponse",
"ExecuteSqlRequest",
Expand All @@ -132,15 +137,12 @@
"ResultSetStats",
"RollbackRequest",
"Session",
"SpannerClient",
"StructType",
"Transaction",
"TransactionOptions",
"TransactionSelector",
"Type",
"TypeAnnotationCode",
"TypeCode",
# Custom spanner related data types
"JsonObject",
# google.cloud.spanner_v1.services
"SpannerClient",
)
75 changes: 64 additions & 11 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,77 @@ def get_staging_dirs(
if clean_up_generated_samples:
shutil.rmtree("samples/generated_samples", ignore_errors=True)
clean_up_generated_samples = False
# Avoid import of `KeyRange` and `KeySet` in __init__ due to naming conflict in handwritten layer
num_replacements = s.replace(
library / "google/cloud/spanner_v1/__init__.py",
"""from .types.keys import KeyRange
from .types.keys import KeySet""",
"""from .types.keys import KeyRange as KeyRangePB
from .types.keys import KeySet as KeySetPB""")
assert num_replacements == 1

num_replacements = s.replace(
library / "google/cloud/spanner_v1/__init__.py",
"""'KeyRange',\n'KeySet',""",
""""KeyRangePB",
"KeySetPB",""")
assert num_replacements == 1

# Integrate handwritten code
num_replacements = s.replace(
library / "google/cloud/spanner_v1/__init__.py",
"""from .types.type import TypeCode\n\n__all__ = \(""",
"""from .types.type import TypeCode
from .data_types import JsonObject

from google.cloud.spanner_v1 import param_types
from google.cloud.spanner_v1.client import Client
from google.cloud.spanner_v1.keyset import KeyRange
from google.cloud.spanner_v1.keyset import KeySet
from google.cloud.spanner_v1.pool import AbstractSessionPool
from google.cloud.spanner_v1.pool import BurstyPool
from google.cloud.spanner_v1.pool import FixedSizePool
from google.cloud.spanner_v1.pool import PingingPool
from google.cloud.spanner_v1.pool import TransactionPingingPool


COMMIT_TIMESTAMP = "spanner.commit_timestamp()"
\"\"\"Placeholder be used to store commit timestamp of a transaction in a column.
This value can only be used for timestamp columns that have set the option
``(allow_commit_timestamp=true)`` in the schema.
\"\"\"


__all__ = (
# google.cloud.spanner_v1
"__version__",
"param_types",
# google.cloud.spanner_v1.client
"Client",
# google.cloud.spanner_v1.data_types
"JsonObject",
# google.cloud.spanner_v1.keyset
"KeyRange",
"KeySet",
# google.cloud.spanner_v1.pool
"AbstractSessionPool",
"BurstyPool",
"FixedSizePool",
"PingingPool",
"TransactionPingingPool",
# local
"COMMIT_TIMESTAMP",
# google.cloud.spanner_v1.types
"""
)
assert num_replacements == 1

s.move(
library,
excludes=[
"google/cloud/spanner/**",
"*.*",
"docs/index.rst",
"google/cloud/spanner_v1/__init__.py",
"**/gapic_version.py",
"testing/constraints-3.7.txt",
],
Expand All @@ -95,11 +158,6 @@ def get_staging_dirs(
for library in get_staging_dirs(
spanner_admin_instance_default_version, "spanner_admin_instance"
):
s.replace(
library / "google/cloud/spanner_admin_instance_v*/__init__.py",
"from google.cloud.spanner_admin_instance import gapic_version as package_version",
f"from google.cloud.spanner_admin_instance_{library.name} import gapic_version as package_version",
)
s.move(
library,
excludes=["google/cloud/spanner_admin_instance/**", "*.*", "docs/index.rst", "**/gapic_version.py", "testing/constraints-3.7.txt",],
Expand All @@ -108,11 +166,6 @@ def get_staging_dirs(
for library in get_staging_dirs(
spanner_admin_database_default_version, "spanner_admin_database"
):
s.replace(
library / "google/cloud/spanner_admin_database_v*/__init__.py",
"from google.cloud.spanner_admin_database import gapic_version as package_version",
f"from google.cloud.spanner_admin_database_{library.name} import gapic_version as package_version",
)
s.move(
library,
excludes=["google/cloud/spanner_admin_database/**", "*.*", "docs/index.rst", "**/gapic_version.py", "testing/constraints-3.7.txt",],
Expand Down