22import os
33from collections import defaultdict
44
5- import jinja2
6-
75from config_helper import (
86 CLASSES_TO_INCLUDE ,
97 # CLASSES_TO_EXCLUDE, # Not currently being used.
108 METHODS_TO_INCLUDE ,
119 METHODS_TO_EXCLUDE ,
1210)
11+ from template_utils import load_template
1312
1413# Constants
1514BASE_DIR = "google/cloud/bigquery_v2/services"
@@ -112,27 +111,7 @@ def generate_client_class_source(data):
112111 for the BigQueryClient class.
113112 """
114113
115- # TODO: move template strings to a separate file.
116- class_template_string = """\
117- class BigQueryClient:
118- def __init__(self):
119- self._clients = {}
120-
121- {% for method in methods %}
122- def {{ method.name }}({{ method.args_for_def }}):
123- \" \" \" A generated method to call the BigQuery API.\" \" \"
124-
125- if "{{ method.class_name }}" not in self._clients:
126- from google.cloud.bigquery_v2 import {{ method.class_name }}
127- self._clients["{{ method.class_name }}"] = {{ method.class_name }}()
128-
129- client = self._clients["{{ method.class_name }}"]
130- from google.cloud.bigquery_v2 import types
131- request = types.{{ method.request_class_name }}({{ method.args_for_call }})
132- return client.{{ method.name }}(request=request)
133-
134- {% endfor %}
135- """
114+ template = load_template ("bigqueryclient.py.j2" )
136115
137116 # Prepare the context for the template.
138117 # We transform the input data into a flat list of methods
@@ -151,8 +130,7 @@ def {{ method.name }}({{ method.args_for_def }}):
151130 }
152131 )
153132
154- # Create a Jinja2 Template object and render it with the context.
155- template = jinja2 .Template (class_template_string , trim_blocks = True )
133+ # Render the template with the context.
156134 generated_code = template .render (methods = methods_context )
157135
158136 return generated_code
0 commit comments