Skip to content

Commit 679a056

Browse files
Merge branch 'autogen' into test/collection-of-imports-and-from-imports
2 parents b70334a + eca20c6 commit 679a056

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 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+
# Imports
18+
import os
19+
20+
from typing import (
21+
Any,
22+
Dict,
23+
List,
24+
Optional,
25+
Sequence,
26+
Tuple,
27+
Union,
28+
)
29+
30+
# Service Client Imports
31+
{% for imp in service_imports %}{{ imp }}{% endfor %}
32+
33+
# Helper Imports
34+
from . import _helpers
35+
36+
# Type Imports
37+
{% for imp in type_imports %}{{ imp }}{% endfor %}
38+
39+
from google.api_core import client_options as client_options_lib
40+
from google.api_core import gapic_v1
41+
from google.api_core import retry as retries
42+
from google.auth import credentials as auth_credentials
43+
import google.auth
44+
45+
# Create type aliases
46+
try:
47+
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
48+
except AttributeError: # pragma: NO COVER
49+
OptionalRetry = Union[retries.Retry, object, None] # type: ignore
50+
51+
DEFAULT_RETRY: OptionalRetry = gapic_v1.method.DEFAULT
52+
DEFAULT_TIMEOUT: Union[float, object] = gapic_v1.method.DEFAULT
53+
DEFAULT_METADATA: Sequence[Tuple[str, Union[str, bytes]]] = ()
54+
55+
{#- Create a mapping from the ServiceClient class name to its property name on the main client.
56+
e.g., {'DatasetServiceClient': 'dataset_service_client'}
57+
-#}
58+
{% set class_to_instance_map = {} %}
59+
{% for service in services %}
60+
{% set _ = class_to_instance_map.update({service.service_client_class: service.property_name}) %}
61+
{% endfor %}
62+
63+
64+
class BigQueryClient:
65+
def __init__(
66+
self,
67+
project: Optional[str] = None,
68+
credentials: Optional[auth_credentials.Credentials] = None,
69+
client_options: Optional[client_options_lib.ClientOptions] = None,
70+
):
71+
if credentials is None:
72+
credentials, project_id = google.auth.default()
73+
else:
74+
project_id = None # project_id is not available from non-default credentials
75+
76+
if project is None:
77+
project = project_id
78+
79+
self.project = project
80+
self._credentials = credentials
81+
self._client_options = client_options
82+
self._clients: Dict[str, Any] = {}
83+
84+
# --- *METHOD SECTION ---
85+
86+
{% for method in methods %}
87+
{% if method.request_id_args is not none and method.request_id_args|length > 0 %}
88+
{% filter indent(4, True) %}
89+
{% include 'partials/_method_with_request_builder.j2' %}
90+
{% endfilter %}
91+
{% else %}
92+
{% filter indent(4, True) %}
93+
{% include 'partials/_simple_passthrough_method.j2' %}
94+
{% endfilter %}
95+
{% endif %}
96+
97+
98+
{% endfor %}
99+
100+
{#- *ServiceClient Properties Section: methods to get/set service clients -#}
101+
# --- *SERVICECLIENT PROPERTIES ---
102+
{% for service in services %}
103+
@property
104+
def {{ service.property_name }}(self):
105+
if "{{ service.service_name }}" not in self._clients:
106+
self._clients["{{ service.service_name }}"] = {{ service.service_module_name }}.{{ service.service_client_class }}(
107+
credentials=self._credentials, client_options=self._client_options
108+
)
109+
return self._clients["{{ service.service_name }}"]
110+
111+
@{{ service.property_name }}.setter
112+
def {{ service.property_name }}(self, value):
113+
if not isinstance(value, {{ service.service_module_name }}.{{ service.service_client_class }}):
114+
raise TypeError(
115+
"Expected an instance of {{ service.service_client_class }}."
116+
)
117+
self._clients["{{ service.service_name }}"] = value
118+
119+
{% endfor %}
120+
121+
{#- Helper Section: methods included from partial template -#}
122+
{#- include "partials/_client_helpers.j2" #}

0 commit comments

Comments
 (0)