Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 5a9a4c6

Browse files
authored
feat: microgen - adds two partial templates for creating method signatures (#2288)
* chore: removes old proof of concept * removes old __init__.py * Adds two utility files to handle basic tasks * Adds a configuration file for the microgenerator * Removes unused comment * chore: adds noxfile.py for the microgenerator * feat: microgen - adds two init file templates * feat: adds _helpers.py.js template * Updates with two usage examples * feat: adds two partial templates for creating method signatures * feat: microgen - adds _helpers.py.j2 template (#2287) * feat: adds _helpers.py.js template * Updates with two usage examples * updates the license header * feat: Add microgenerator __init__.py (#2291) Migrates the empty __init__.py file to the microgenerator package. * adds comment explaining source of *Request names * adds comment regarding request_id_args
1 parent a0b16ff commit 5a9a4c6

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

scripts/microgenerator/__init__.py

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
def {{ method.name }}(
2+
self,
3+
{# Assumes the primary resource ID is the last arg in request_id_args #}
4+
{{ method.request_id_args[-1] }}: Optional[str] = None,
5+
*,
6+
{# Assumes the request class is a nested type within the service, e.g., bigquery_v2.types.dataset.GetDatasetRequest #}
7+
request: Optional[{{ '.'.join(method.request_class_full_name.split('.')[-2:]) }}] = None,
8+
retry: OptionalRetry = DEFAULT_RETRY,
9+
timeout: Union[float, object] = DEFAULT_TIMEOUT,
10+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = DEFAULT_METADATA,
11+
) -> "{{ method.return_type }}":
12+
"""
13+
TODO: Docstring is purposefully blank. microgenerator will add automatically.
14+
"""
15+
if request and {{ method.request_id_args[-1] }} is not None:
16+
raise ValueError("Cannot provide both request and {{ method.request_id_args[-1] }}.")
17+
18+
if request:
19+
final_request = request
20+
else:
21+
path_identifier = {{ method.request_id_args[-1] }}
22+
if path_identifier is None:
23+
if len({{ method.request_id_args }}) == 1:
24+
path_identifier = self.project
25+
else:
26+
raise ValueError("Either request or {{ method.request_id_args[-1] }} must be provided.")
27+
28+
if path_identifier is None:
29+
raise ValueError("Could not determine a path identifier.")
30+
31+
request_class = {{ '.'.join(method.request_class_full_name.split('.')[-2:]) }}
32+
33+
final_request = _helpers._create_request(
34+
request_class=request_class,
35+
path_identifier=path_identifier,
36+
expected_args={{ method.request_id_args }},
37+
default_project_id=self.project,
38+
)
39+
40+
return self.{{ class_to_instance_map[method.class_name] }}.{{ method.name }}(
41+
request=final_request,
42+
retry=retry,
43+
timeout=timeout,
44+
metadata=metadata,
45+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def {{ method.name }}(
2+
self,
3+
*,
4+
request: Optional[dict] = None,
5+
retry: OptionalRetry = DEFAULT_RETRY,
6+
timeout: Union[float, object] = DEFAULT_TIMEOUT,
7+
metadata: Sequence[Tuple[str, Union[str, bytes]]] = DEFAULT_METADATA,
8+
) -> "{{ method.return_type }}":
9+
"""
10+
TODO: Docstring is purposefully blank. microgenerator will add automatically.
11+
"""
12+
13+
return self.{{ class_to_instance_map[method.class_name] }}.{{ method.name }}(
14+
request=request,
15+
retry=retry,
16+
timeout=timeout,
17+
metadata=metadata,
18+
)

0 commit comments

Comments
 (0)