Skip to content

Commit 71dde11

Browse files
authored
feat: add a static copy of legacy proto-based types (#1000)
* feat: add a static copy of legacy proto SQL types * Exclude legacy types from docs generation * Exclude legacy types from type checks * Exclude legacy types from test coverage * Emit warning if importing legacy types * Re-introduce proto-related dependencies * Expose legacy types in reference docs
1 parent b0cbfef commit 71dde11

17 files changed

+1949
-1
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ fail_under = 100
66
show_missing = True
77
omit =
88
google/cloud/bigquery/__init__.py
9+
google/cloud/bigquery_v2/* # Legacy proto-based types.
910
exclude_lines =
1011
# Re-enable the standard pragma
1112
pragma: NO COVER

UPGRADING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ See the License for the specific language governing permissions and
1111
limitations under the License.
1212
-->
1313

14+
# 3.0.0 Migration Guide
15+
16+
TODO
17+
1418

1519
# 2.0.0 Migration Guide
1620

@@ -56,4 +60,4 @@ distance_type = enums.Model.DistanceType.COSINE
5660
from google.cloud.bigquery_v2 import types
5761

5862
distance_type = types.Model.DistanceType.COSINE
59-
```
63+
```

docs/bigquery/legacy_proto_types.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Legacy proto-based Types for Google Cloud Bigquery v2 API
2+
=========================================================
3+
4+
.. warning::
5+
These types are provided for backward compatibility only, and are not maintained
6+
anymore. They might also differ from the types uspported on the backend. It is
7+
therefore strongly advised to migrate to the types found in :doc:`standard_sql`.
8+
9+
Also see the :doc:`3.0.0 Migration Guide<../UPGRADING>` for more information.
10+
11+
.. automodule:: google.cloud.bigquery_v2.types
12+
:members:
13+
:undoc-members:
14+
:show-inheritance:

docs/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
# List of patterns, relative to source directory, that match files and
110110
# directories to ignore when looking for source files.
111111
exclude_patterns = [
112+
"google/cloud/bigquery_v2/**", # Legacy proto-based types.
112113
"_build",
113114
"**/.nox/**/*",
114115
"samples/AUTHORING_GUIDE.md",
@@ -365,6 +366,8 @@
365366
"grpc": ("https://grpc.github.io/grpc/python/", None),
366367
"pandas": ("http://pandas.pydata.org/pandas-docs/stable/", None),
367368
"geopandas": ("https://geopandas.org/", None),
369+
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
370+
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
368371
}
369372

370373

docs/reference.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,18 @@ Helper SQL type classes.
204204
:maxdepth: 2
205205

206206
bigquery/standard_sql
207+
208+
209+
Legacy proto-based Types (deprecated)
210+
=====================================
211+
212+
The legacy type classes based on protocol buffers.
213+
214+
.. deprecated:: 3.0.0
215+
These types are provided for backward compatibility only, and are not maintained
216+
anymore.
217+
218+
.. toctree::
219+
:maxdepth: 2
220+
221+
bigquery/legacy_proto_types

google/cloud/bigquery_v2/__init__.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
import warnings
18+
19+
from .types.encryption_config import EncryptionConfiguration
20+
from .types.model import DeleteModelRequest
21+
from .types.model import GetModelRequest
22+
from .types.model import ListModelsRequest
23+
from .types.model import ListModelsResponse
24+
from .types.model import Model
25+
from .types.model import PatchModelRequest
26+
from .types.model_reference import ModelReference
27+
from .types.standard_sql import StandardSqlDataType
28+
from .types.standard_sql import StandardSqlField
29+
from .types.standard_sql import StandardSqlStructType
30+
from .types.standard_sql import StandardSqlTableType
31+
from .types.table_reference import TableReference
32+
33+
34+
_LEGACY_MSG = (
35+
"Legacy proto-based types from bigquery_v2 are not maintained anymore, "
36+
"use types defined in google.cloud.bigquery instead."
37+
)
38+
39+
warnings.warn(_LEGACY_MSG, category=DeprecationWarning)
40+
41+
42+
__all__ = (
43+
"DeleteModelRequest",
44+
"EncryptionConfiguration",
45+
"GetModelRequest",
46+
"ListModelsRequest",
47+
"ListModelsResponse",
48+
"Model",
49+
"ModelReference",
50+
"PatchModelRequest",
51+
"StandardSqlDataType",
52+
"StandardSqlField",
53+
"StandardSqlStructType",
54+
"StandardSqlTableType",
55+
"TableReference",
56+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
from .encryption_config import EncryptionConfiguration
17+
from .model import (
18+
DeleteModelRequest,
19+
GetModelRequest,
20+
ListModelsRequest,
21+
ListModelsResponse,
22+
Model,
23+
PatchModelRequest,
24+
)
25+
from .model_reference import ModelReference
26+
from .standard_sql import (
27+
StandardSqlDataType,
28+
StandardSqlField,
29+
StandardSqlStructType,
30+
StandardSqlTableType,
31+
)
32+
from .table_reference import TableReference
33+
34+
__all__ = (
35+
"EncryptionConfiguration",
36+
"DeleteModelRequest",
37+
"GetModelRequest",
38+
"ListModelsRequest",
39+
"ListModelsResponse",
40+
"Model",
41+
"PatchModelRequest",
42+
"ModelReference",
43+
"StandardSqlDataType",
44+
"StandardSqlField",
45+
"StandardSqlStructType",
46+
"StandardSqlTableType",
47+
"TableReference",
48+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
import proto # type: ignore
17+
18+
from google.protobuf import wrappers_pb2 # type: ignore
19+
20+
21+
__protobuf__ = proto.module(
22+
package="google.cloud.bigquery.v2", manifest={"EncryptionConfiguration",},
23+
)
24+
25+
26+
class EncryptionConfiguration(proto.Message):
27+
r"""
28+
Attributes:
29+
kms_key_name (google.protobuf.wrappers_pb2.StringValue):
30+
Optional. Describes the Cloud KMS encryption
31+
key that will be used to protect destination
32+
BigQuery table. The BigQuery Service Account
33+
associated with your project requires access to
34+
this encryption key.
35+
"""
36+
37+
kms_key_name = proto.Field(
38+
proto.MESSAGE, number=1, message=wrappers_pb2.StringValue,
39+
)
40+
41+
42+
__all__ = tuple(sorted(__protobuf__.manifest))

0 commit comments

Comments
 (0)