3636 Set ,
3737 Tuple ,
3838)
39- import yaml
4039
40+ import grpc # type: ignore
41+ import yaml
42+ from gapic .schema import metadata , mixins , wrappers
43+ from gapic .schema import naming as api_naming
44+ from gapic .utils import RESERVED_NAMES , Options , cached_property , nth , to_snake_case
45+ from google .api import (
46+ annotations_pb2 , # type: ignore
47+ client_pb2 , # type: ignore
48+ http_pb2 , # type: ignore
49+ resource_pb2 , # type: ignore
50+ service_pb2 , # type: ignore
51+ )
4152from google .api_core import exceptions
42- from google .api import client_pb2 # type: ignore
43- from google .api import http_pb2 # type: ignore
44- from google .api import resource_pb2 # type: ignore
45- from google .api import service_pb2 # type: ignore
4653from google .cloud import extended_operations_pb2 as ex_ops_pb2 # type: ignore
54+ from google .cloud .location import locations_pb2 # type: ignore
4755from google .gapic .metadata import gapic_metadata_pb2 # type: ignore
48- from google .longrunning import operations_pb2 # type: ignore
4956from google .iam .v1 import iam_policy_pb2 # type: ignore
50- from google .cloud . location import locations_pb2 # type: ignore
57+ from google .longrunning import operations_pb2 # type: ignore
5158from google .protobuf import descriptor_pb2 # type: ignore
52- from google .protobuf .json_format import MessageToJson
53- from google .protobuf .json_format import ParseDict
5459from google .protobuf .descriptor import ServiceDescriptor
55- import grpc # type: ignore
5660from google .protobuf .descriptor_pb2 import MethodDescriptorProto
57- from google .api import annotations_pb2 # type: ignore
58- from gapic .schema import metadata
59- from gapic .schema import mixins
60- from gapic .schema import wrappers
61- from gapic .schema import naming as api_naming
62- from gapic .utils import cached_property
63- from gapic .utils import nth
64- from gapic .utils import Options
65- from gapic .utils import to_snake_case
66- from gapic .utils import RESERVED_NAMES
67-
61+ from google .protobuf .json_format import MessageToJson , ParseDict
6862
6963TRANSPORT_GRPC = "grpc"
7064TRANSPORT_GRPC_ASYNC = "grpc-async"
@@ -160,7 +154,12 @@ def messages(self) -> Mapping[str, wrappers.MessageType]:
160154 def resource_messages (self ) -> Mapping [str , wrappers .MessageType ]:
161155 """Return the file level resources of the proto."""
162156 file_resource_messages = (
163- (res .type , wrappers .CommonResource .build (res , aliases = self .resource_name_aliases ).message_type )
157+ (
158+ res .type ,
159+ wrappers .CommonResource .build (
160+ res , aliases = self .resource_name_aliases
161+ ).message_type ,
162+ )
164163 for res in self .file_pb2 .options .Extensions [
165164 resource_pb2 .resource_definition
166165 ]
@@ -179,7 +178,7 @@ def resource_messages(self) -> Mapping[str, wrappers.MessageType]:
179178 file_resource_messages ,
180179 resource_messages ,
181180 ),
182- key = lambda item : item [0 ]
181+ key = lambda item : item [0 ],
183182 )
184183 )
185184
@@ -319,7 +318,8 @@ def with_selective_generation(
319318 new_v = v .with_selective_generation (
320319 generate_omitted_as_internal = generate_omitted_as_internal ,
321320 public_methods = public_methods ,
322- excluded_addresses = excluded_addresses )
321+ excluded_addresses = excluded_addresses ,
322+ )
323323 if new_v :
324324 services [k ] = new_v
325325
@@ -331,7 +331,9 @@ def with_selective_generation(
331331 # This ensures that shared messages, messages not attached to any RPC,
332332 # and messages reachable via other paths (like LRO response types) are KEPT.
333333 all_messages = {
334- k : v for k , v in self .all_messages .items () if v .ident not in excluded_addresses
334+ k : v
335+ for k , v in self .all_messages .items ()
336+ if v .ident not in excluded_addresses
335337 }
336338
337339 all_enums = {
@@ -340,7 +342,12 @@ def with_selective_generation(
340342
341343 # If the proto becomes empty after pruning, we return None to signal
342344 # that it should be excluded from generation.
343- if not generate_omitted_as_internal and not services and not all_messages and not all_enums :
345+ if (
346+ not generate_omitted_as_internal
347+ and not services
348+ and not all_messages
349+ and not all_enums
350+ ):
344351 return None
345352
346353 return dataclasses .replace (
@@ -521,9 +528,14 @@ def disambiguate_keyword_sanitize_fname(
521528 excluded_addresses = set ([]),
522529 )
523530 else :
524- all_resource_messages = dict (collections .ChainMap (
525- * (proto .resource_messages for proto in api .all_protos .values ())
526- ))
531+ all_resource_messages = dict (
532+ collections .ChainMap (
533+ * (
534+ proto .resource_messages
535+ for proto in api .all_protos .values ()
536+ )
537+ )
538+ )
527539
528540 # Create a global map of services to support cross-proto lookup
529541 # for extended LROs.
@@ -550,19 +562,31 @@ def disambiguate_keyword_sanitize_fname(
550562 for method in service .methods .values ():
551563 if method .ident .proto not in selective_gapic_methods :
552564 # Candidate for exclusion: the method itself and its direct request/response types.
553- candidate_excluded_addresses .add (method .meta .address )
565+ candidate_excluded_addresses .add (
566+ method .meta .address
567+ )
554568 candidate_excluded_addresses .add (method .input .ident )
555- candidate_excluded_addresses .add (method .output .ident )
569+ candidate_excluded_addresses .add (
570+ method .output .ident
571+ )
556572
557573 # If this is an LRO, add its response and metadata types to candidates.
558574 if method .lro :
559- candidate_excluded_addresses .add (method .lro .response_type .ident )
560- candidate_excluded_addresses .add (method .lro .metadata_type .ident )
575+ candidate_excluded_addresses .add (
576+ method .lro .response_type .ident
577+ )
578+ candidate_excluded_addresses .add (
579+ method .lro .metadata_type .ident
580+ )
561581
562582 # If this is an extended LRO, add its request and operation types to candidates.
563583 if method .extended_lro :
564- candidate_excluded_addresses .add (method .extended_lro .request_type .ident )
565- candidate_excluded_addresses .add (method .extended_lro .operation_type .ident )
584+ candidate_excluded_addresses .add (
585+ method .extended_lro .request_type .ident
586+ )
587+ candidate_excluded_addresses .add (
588+ method .extended_lro .operation_type .ident
589+ )
566590
567591 # Calculate publicly reachable addresses (API-wide).
568592 # This includes all types reachable from the allowlisted (public) methods.
@@ -581,7 +605,9 @@ def disambiguate_keyword_sanitize_fname(
581605 # This set difference effectively "vets" the candidates. If a candidate
582606 # message is actually reachable from a public RPC, it's removed from
583607 # the exclusion list.
584- excluded_addresses = candidate_excluded_addresses - public_rpc_addresses
608+ excluded_addresses = (
609+ candidate_excluded_addresses - public_rpc_addresses
610+ )
585611
586612 for name , proto in api .protos .items ():
587613 proto_to_generate = proto .with_selective_generation (
0 commit comments