Skip to content

Commit 75eb349

Browse files
feat: add gapic-version generator option (#2440)
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent a524fe0 commit 75eb349

File tree

18 files changed

+29
-20
lines changed

18 files changed

+29
-20
lines changed

gapic/samplegen_utils/snippet_index.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def __init__(self, api_schema: api.API):
119119
)
120120
self.metadata_index.client_library.language = snippet_metadata_pb2.Language.PYTHON # type: ignore
121121

122-
# This is just a placeholder. release-please is responsible for
123-
# updating the metadata file to the correct library version.
124-
self.metadata_index.client_library.version = "0.1.0"
122+
self.metadata_index.client_library.version = api_schema.gapic_version
125123

126124
self.metadata_index.client_library.apis.append(
127125
snippet_metadata_pb2.Api( # type: ignore

gapic/schema/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ class API:
378378
all_protos: Mapping[str, Proto]
379379
service_yaml_config: service_pb2.Service
380380
subpackage_view: Tuple[str, ...] = dataclasses.field(default_factory=tuple)
381+
gapic_version: str = "0.0.0"
381382

382383
@classmethod
383384
def build(
@@ -493,12 +494,16 @@ def disambiguate_keyword_sanitize_fname(
493494
ParseDict(
494495
opts.service_yaml_config, service_yaml_config, ignore_unknown_fields=True
495496
)
497+
gapic_version = opts.gapic_version
496498

497499
# Third pass for various selective GAPIC settings; these require
498500
# settings in the service.yaml and so we build the API object
499501
# before doing another pass.
500502
api = cls(
501-
naming=naming, all_protos=protos, service_yaml_config=service_yaml_config
503+
naming=naming,
504+
all_protos=protos,
505+
service_yaml_config=service_yaml_config,
506+
gapic_version=gapic_version,
502507
)
503508

504509
if package in api.all_library_settings:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends '_base.py.j2' %}
22
{% block content %}
33

4-
__version__ = "0.0.0" # {x-release-please-version}
4+
__version__ = "{{ api.gapic_version }}" # {x-release-please-version}
55
{% endblock %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends '_base.py.j2' %}
22
{% block content %}
33

4-
__version__ = "0.0.0" # {x-release-please-version}
4+
__version__ = "{{ api.gapic_version }}" # {x-release-please-version}
55
{% endblock %}

gapic/utils/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Options:
5050
service_yaml_config: Dict[str, Any] = dataclasses.field(default_factory=dict)
5151
rest_numeric_enums: bool = False
5252
proto_plus_deps: Tuple[str, ...] = dataclasses.field(default=("",))
53+
gapic_version: str = "0.0.0"
5354

5455
# Class constants
5556
PYTHON_GAPIC_PREFIX: str = "python-gapic-"
@@ -71,6 +72,7 @@ class Options:
7172
# proto plus dependencies delineated by '+'
7273
# For example, 'google.cloud.api.v1+google.cloud.anotherapi.v2'
7374
"proto-plus-deps",
75+
"gapic-version", # A version string following https://peps.python.org/pep-0440
7476
)
7577
)
7678

@@ -197,6 +199,7 @@ def tweak_path(p):
197199
service_yaml_config=service_yaml_config,
198200
rest_numeric_enums=bool(opts.pop("rest-numeric-enums", False)),
199201
proto_plus_deps=proto_plus_deps,
202+
gapic_version=opts.pop("gapic-version", ["0.0.0"]).pop(),
200203
)
201204

202205
# Note: if we ever need to recursively check directories for sample

tests/integration/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ py_gapic_library(
5555
grpc_service_config = "cloudasset_grpc_service_config.json",
5656
opt_args = [
5757
"autogen-snippets",
58+
"gapic-version=1.2.99",
5859
],
5960
service_yaml = "cloudasset_v1.yaml",
6061
transport = "grpc+rest",

tests/integration/goldens/asset/google/cloud/asset/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.0.0" # {x-release-please-version}
16+
__version__ = "1.2.99" # {x-release-please-version}

tests/integration/goldens/asset/google/cloud/asset_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.0.0" # {x-release-please-version}
16+
__version__ = "1.2.99" # {x-release-please-version}

tests/integration/goldens/asset/samples/generated_samples/snippet_metadata_google.cloud.asset.v1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-asset",
11-
"version": "0.1.0"
11+
"version": "1.2.99"
1212
},
1313
"snippets": [
1414
{

tests/integration/goldens/credentials/samples/generated_samples/snippet_metadata_google.iam.credentials.v1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-iam-credentials",
11-
"version": "0.1.0"
11+
"version": "0.0.0"
1212
},
1313
"snippets": [
1414
{

0 commit comments

Comments
 (0)