Skip to content

Commit fc1ec0a

Browse files
committed
chore(generator): add compatability layer templates
1 parent eceea95 commit fc1ec0a

19 files changed

Lines changed: 269 additions & 3 deletions

File tree

packages/gapic-generator/gapic/generator/generator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
from google.protobuf.compiler.plugin_pb2 import CodeGeneratorResponse
3838

3939

40+
ALLOWED_PRIVATE_TEMPLATES = (
41+
"__init__.py.j2",
42+
"_compat.py.j2",
43+
)
44+
45+
4046
class Generator:
4147
"""A protoc code generator for client libraries.
4248
@@ -118,9 +124,9 @@ def get_response(self, api_schema: api.API, opts: Options) -> CodeGeneratorRespo
118124
# and instead of iterating over it/them, we iterate over samples
119125
# and plug those into the template.
120126
for template_name in client_templates:
121-
# Quick check: Skip "private" templates.
127+
# Quick check: Skip "private" templates except explicitly allowed ones.
122128
filename = template_name.split("/")[-1]
123-
if filename.startswith("_") and filename != "__init__.py.j2":
129+
if filename.startswith("_") and filename not in ALLOWED_PRIVATE_TEMPLATES:
124130
continue
125131

126132
# Append to the output files dictionary.
@@ -413,7 +419,7 @@ def _get_file(
413419

414420
# Quick check: Do not render empty files.
415421
if utils.empty(cgr_file.content) and not fn.endswith(
416-
("py.typed", "__init__.py")
422+
("py.typed", "__init__.py", "_compat.py")
417423
):
418424
return {}
419425

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# {% include '_license.j2' %}
2+
3+
"""A compatibility module for older versions of google-api-core."""
4+
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17813):
5+
Clean up this file/functions when the minimum supported version of
6+
google-api-core has the functions in `_compat.py.j2`. #}
7+
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17884):
8+
Add conditional logic to check if static code exists in google-api-core and use it from there,
9+
falling back to the local implementation if not present. #}
10+
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17883):
11+
Backfill compatibility functions being removed from the client layer. #}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# {% include '_license.j2' %}
2+
3+
"""Tests for the compatibility module for older versions of google-api-core."""
4+
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17813):
5+
Clean up this file/tests when the minimum supported version of
6+
google-api-core has the functions in `_compat.py.j2`. #}
7+
{# TODO(https://github.com/googleapis/google-cloud-python/issues/17883):
8+
Backfill compatibility functions tests being removed from the client layer. #}
9+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# # Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""A compatibility module for older versions of google-api-core."""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# # Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""Tests for the compatibility module for older versions of google-api-core."""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# # Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""A compatibility module for older versions of google-api-core."""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# # Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""Tests for the compatibility module for older versions of google-api-core."""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# # Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""A compatibility module for older versions of google-api-core."""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# # Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""Tests for the compatibility module for older versions of google-api-core."""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# # Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""A compatibility module for older versions of google-api-core."""

0 commit comments

Comments
 (0)