Skip to content

Commit c7747d2

Browse files
authored
chore: add ConfiguredSnippet.filename (#1523)
* chore: add ConfiguredSnippet.filename * add inflection to dependency * set upperbound on dependencies in setup.py
1 parent f3def5e commit c7747d2

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

packages/gapic-generator/gapic/configurable_snippetgen/configured_snippet.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import dataclasses
1616

17+
import inflection
1718
import libcst
1819

1920
from gapic.configurable_snippetgen import snippet_config_language_pb2
@@ -58,8 +59,22 @@ def sample_function_name(self) -> str:
5859
"""The sample function's name.
5960
6061
For example:
61-
"sample_create_custom_class_basic"
62+
"sample_create_custom_class_Basic"
6263
"""
6364
snippet_method_name = self.config.signature.snippet_method_name
6465
config_id = self.config.metadata.config_id
6566
return f"sample_{snippet_method_name}_{config_id}"
67+
68+
@property
69+
def filename(self) -> str:
70+
"""The snippet's file name.
71+
72+
For example:
73+
"speech_v1_generated_Adaptation_create_custom_class_Basic_async.py"
74+
"""
75+
module_name = self.config.rpc.proto_package.split(".")[-1]
76+
service_name = self.config.rpc.service_name
77+
snake_case_rpc_name = inflection.underscore(self.config.rpc.rpc_name)
78+
config_id = self.config.metadata.config_id
79+
sync_or_async = "sync" if self.is_sync else "async"
80+
return f"{module_name}_{self.api_version}_generated_{service_name}_{snake_case_rpc_name}_{config_id}_{sync_or_async}.py"

packages/gapic-generator/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ setuptools==65.6.3
1010
grpc-google-iam-v1==0.12.4
1111
proto-plus==1.22.1
1212
pytest-asyncio==0.20.2
13-
libcst==0.4.9
13+
libcst==0.4.9
14+
inflection==0.5.1

packages/gapic-generator/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"pypandoc >= 1.4",
3535
"PyYAML >= 5.1.1",
3636
"grpc-google-iam-v1 >= 0.12.4, < 1.0.0dev",
37-
"libcst >= 0.4.9",
37+
"libcst >= 0.4.9, < 1.0.0dev",
38+
"inflection >= 0.5.1, < 1.0.0dev",
3839
]
3940

4041
package_root = os.path.abspath(os.path.dirname(__file__))

packages/gapic-generator/tests/unit/configurable_snippetgen/test_configured_snippet.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,36 +76,31 @@ def _make_configured_snippet(
7676
)
7777

7878

79-
def test_region_tag():
80-
snippet = _make_configured_snippet(
79+
@pytest.fixture
80+
def snippet():
81+
return _make_configured_snippet(
8182
SPEECH_V1_REQUEST_PATH,
8283
CONFIG_JSON_PATH,
8384
api_version="v1",
8485
is_sync=True)
8586

87+
88+
def test_region_tag(snippet):
8689
assert (
8790
snippet.region_tag
8891
== "speech_v1_config_Adaptation_CreateCustomClass_Basic_sync"
8992
)
9093

9194

92-
def test_sample_function_name():
93-
snippet = _make_configured_snippet(
94-
SPEECH_V1_REQUEST_PATH,
95-
CONFIG_JSON_PATH,
96-
api_version="v1",
97-
is_sync=True)
98-
95+
def test_sample_function_name(snippet):
9996
assert snippet.sample_function_name == "sample_create_custom_class_Basic"
10097

10198

102-
def test_code():
103-
snippet = _make_configured_snippet(
104-
SPEECH_V1_REQUEST_PATH,
105-
CONFIG_JSON_PATH,
106-
api_version="v1",
107-
is_sync=True)
99+
def test_filename(snippet):
100+
assert snippet.filename == "speech_v1_generated_Adaptation_create_custom_class_Basic_sync.py"
101+
108102

103+
def test_code(snippet):
109104
# https://github.com/googleapis/gapic-generator-python/issues/1522
110105
# Placeholder code. We will gradually add to the ConfiguredSnippet class
111106
# until the generated code is the same as that of the golden file.

0 commit comments

Comments
 (0)