From 0a8c041a5897ee75b1c66292de583f88e71f543d Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Fri, 20 Dec 2024 17:03:25 +0000 Subject: [PATCH] Address review feedback from vchudnov-g --- gapic/schema/api.py | 43 ++++++++-------- gapic/schema/wrappers.py | 107 ++++++++++++++++++++------------------- 2 files changed, 75 insertions(+), 75 deletions(-) diff --git a/gapic/schema/api.py b/gapic/schema/api.py index 9bd74ff5c..d3eff80ee 100644 --- a/gapic/schema/api.py +++ b/gapic/schema/api.py @@ -237,12 +237,12 @@ def disambiguate(self, string: str) -> str: return self.disambiguate(f'_{string}') return string - def build_address_allowlist_for_selective_gapic(self, *, - method_names: Iterable[str], - address_allowlist: Set['metadata.Address'], - resource_messages: Dict[str, 'wrappers.MessageType'], - ) -> None: - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + method_allowlist: Iterable[str], + address_allowlist: Set['metadata.Address'], + resource_messages: Dict[str, 'wrappers.MessageType'], + ) -> None: + """Adds to the set of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. @@ -250,16 +250,16 @@ def build_address_allowlist_for_selective_gapic(self, *, for service in self.services.values(): # The method.operation_service for an extended LRO is not fully qualified, so we # truncate the service names accordingly so they can be found in - # method.build_address_allowlist_for_selective_gapic + # method.add_to_address_allowlist services_in_proto = { service.name: service for service in self.services.values() } - service.build_address_allowlist_for_selective_gapic(method_names=method_names, - address_allowlist=address_allowlist, - resource_messages=resource_messages, - services_in_proto=services_in_proto) + service.add_to_address_allowlist(method_allowlist=method_allowlist, + address_allowlist=address_allowlist, + resource_messages=resource_messages, + services_in_proto=services_in_proto) - def prune_messages_for_selective_gapic(self, *, + def prune_messages_for_selective_generation(self, *, address_allowlist: Set['metadata.Address']) -> Optional['Proto']: """Returns a truncated version of this Proto. @@ -269,15 +269,14 @@ def prune_messages_for_selective_gapic(self, *, return None. """ services = { - k: v.prune_messages_for_selective_gapic( + k: v.prune_messages_for_selective_generation( address_allowlist=address_allowlist) for k, v in self.services.items() if v.meta.address in address_allowlist } # For messages and enums we should only be pruning them from all_messages if they - # are proto plus types. This should apply to the Protos we are pruning from, but might - # not in the future. + # are proto plus types. This should apply to the Protos we are pruning from. all_messages = { k: v for k, v in self.all_messages.items() @@ -444,15 +443,15 @@ def disambiguate_keyword_sanitize_fname( *(proto.resource_messages for proto in protos.values()) ) - # Prepare a list of addresses to include in selective GAPIC, + # Prepare a list of addresses to include in selective generation, # then prune each Proto object. We look at metadata.Addresses, not objects, because # objects that refer to the same thing in the proto are different Python objects # in memory. address_allowlist: Set['metadata.Address'] = set([]) for proto in api.protos.values(): - proto.build_address_allowlist_for_selective_gapic(method_names=selective_gapic_methods, - address_allowlist=address_allowlist, - resource_messages=all_resource_messages) + proto.add_to_address_allowlist(method_allowlist=selective_gapic_methods, + address_allowlist=address_allowlist, + resource_messages=all_resource_messages) new_protos = {} @@ -461,10 +460,10 @@ def disambiguate_keyword_sanitize_fname( if name not in api.protos: new_protos[name] = proto else: - proto_to_generate = proto.prune_messages_for_selective_gapic( + proto_to_generate = proto.prune_messages_for_selective_generation( address_allowlist=address_allowlist) - if pruned_proto: - new_protos[name] = pruned_proto + if proto_to_generate: + new_protos[name] = proto_to_generate api = cls(naming=naming, all_protos=new_protos, diff --git a/gapic/schema/wrappers.py b/gapic/schema/wrappers.py index d65e425f3..6e7012054 100644 --- a/gapic/schema/wrappers.py +++ b/gapic/schema/wrappers.py @@ -389,29 +389,29 @@ def with_context( meta=self.meta.with_context(collisions=collisions), ) - def build_address_allowlist_for_selective_gapic(self, *, - address_allowlist: Set['metadata.Address'], - resource_messages: Dict[str, 'MessageType']) -> None: - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + address_allowlist: Set['metadata.Address'], + resource_messages: Dict[str, 'MessageType']) -> None: + """Adds to the set of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. """ if self.message: - self.message.build_address_allowlist_for_selective_gapic( + self.message.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) if self.enum: - self.enum.build_address_allowlist_for_selective_gapic( + self.enum.add_to_address_allowlist( address_allowlist=address_allowlist, ) if self.resource_reference and self.resource_reference in resource_messages: # The message types in resource_message are different objects, but should be # defined the same as the MessageTypes we're traversing here. - resource_messages[self.resource_reference].build_address_allowlist_for_selective_gapic( + resource_messages[self.resource_reference].add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) @@ -787,10 +787,10 @@ def with_context(self, *, meta=self.meta.with_context(collisions=collisions), ) - def build_address_allowlist_for_selective_gapic(self, *, - address_allowlist: Set['metadata.Address'], - resource_messages: Dict[str, 'MessageType']): - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + address_allowlist: Set['metadata.Address'], + resource_messages: Dict[str, 'MessageType']): + """Adds to the set of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. @@ -799,18 +799,18 @@ def build_address_allowlist_for_selective_gapic(self, *, address_allowlist.add(self.ident) for field in self.fields.values(): - field.build_address_allowlist_for_selective_gapic( + field.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages ) for enum in self.nested_enums.values(): - enum.build_address_allowlist_for_selective_gapic( + enum.add_to_address_allowlist( address_allowlist=address_allowlist, ) for message in self.nested_messages.values(): - message.build_address_allowlist_for_selective_gapic( + message.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) @@ -868,9 +868,9 @@ def with_context(self, *, collisions: Set[str]) -> 'EnumType': meta=self.meta.with_context(collisions=collisions), ) if collisions else self - def build_address_allowlist_for_selective_gapic(self, *, - address_allowlist: Set['metadata.Address']) -> None: - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + address_allowlist: Set['metadata.Address']) -> None: + """Adds to the set of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. @@ -981,20 +981,20 @@ def with_context(self, *, ), ) - def build_address_allowlist_for_selective_gapic(self, *, - address_allowlist: Set['metadata.Address'], - resource_messages: Dict[str, 'MessageType']) -> None: - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + address_allowlist: Set['metadata.Address'], + resource_messages: Dict[str, 'MessageType']) -> None: + """Adds to the set of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. """ - self.request_type.build_address_allowlist_for_selective_gapic( + self.request_type.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) - self.operation_type.build_address_allowlist_for_selective_gapic( + self.operation_type.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) @@ -1028,20 +1028,20 @@ def with_context(self, *, ), ) - def build_address_allowlist_for_selective_gapic(self, *, - address_allowlist: Set['metadata.Address'], - resource_messages: Dict[str, 'MessageType']) -> None: - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + address_allowlist: Set['metadata.Address'], + resource_messages: Dict[str, 'MessageType']) -> None: + """Adds to the set of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. """ - self.response_type.build_address_allowlist_for_selective_gapic( + self.response_type.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) - self.metadata_type.build_address_allowlist_for_selective_gapic( + self.metadata_type.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages ) @@ -1779,12 +1779,12 @@ def with_context(self, *, meta=self.meta.with_context(collisions=collisions), ) - def build_address_allowlist_for_selective_gapic(self, *, - address_allowlist: Set['metadata.Address'], - resource_messages: Dict[str, 'MessageType'], - services_in_proto: Dict[str, 'Service'], - ) -> None: - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + address_allowlist: Set['metadata.Address'], + resource_messages: Dict[str, 'MessageType'], + services_in_proto: Dict[str, 'Service'], + ) -> None: + """Adds to the allowlist of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. @@ -1793,33 +1793,34 @@ def build_address_allowlist_for_selective_gapic(self, *, address_allowlist.add(self.ident) if self.lro: - self.lro.build_address_allowlist_for_selective_gapic(address_allowlist=address_allowlist, - resource_messages=resource_messages) + self.lro.add_to_address_allowlist(address_allowlist=address_allowlist, + resource_messages=resource_messages) if self.extended_lro: # We need to add the service/method pointed to by self.operation_service to - # the allowlist, as it might not have been specified by selective_gapic_generation. + # the allowlist, as it might not have been specified by + # the methods under selective_gapic_generation. # We assume that the operation service lives in the same proto file as this one. operation_service = services_in_proto[ self.operation_service] # type: ignore address_allowlist.add(operation_service.meta.address) - operation_service.operation_polling_method.build_address_allowlist_for_selective_gapic( + operation_service.operation_polling_method.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, services_in_proto=services_in_proto, ) - self.extended_lro.build_address_allowlist_for_selective_gapic( + self.extended_lro.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) - self.input.build_address_allowlist_for_selective_gapic( + self.input.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) - self.output.build_address_allowlist_for_selective_gapic( + self.output.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, ) @@ -2140,30 +2141,30 @@ def with_context(self, *, meta=self.meta.with_context(collisions=collisions), ) - def build_address_allowlist_for_selective_gapic(self, *, - method_names: Iterable[str], - address_allowlist: Set['metadata.Address'], - resource_messages: Dict[str, 'MessageType'], - services_in_proto: Dict[str, 'Service'], - ) -> None: - """Builds a set of Addresses of wrapper objects to be included in selective GAPIC generation. + def add_to_address_allowlist(self, *, + method_allowlist: Iterable[str], + address_allowlist: Set['metadata.Address'], + resource_messages: Dict[str, 'MessageType'], + services_in_proto: Dict[str, 'Service'], + ) -> None: + """Adds to the allowlist of Addresses of wrapper objects to be included in selective GAPIC generation. This method is used to create an allowlist of addresses to be used to filter out unneeded services, methods, messages, and enums at a later step. """ for method in self.methods.values(): - if method.ident.proto in method_names: + if method.ident.proto in method_allowlist: # Include this service if there are any types/methods in selective gapic for this service. address_allowlist.add(self.meta.address) - method.build_address_allowlist_for_selective_gapic( + method.add_to_address_allowlist( address_allowlist=address_allowlist, resource_messages=resource_messages, services_in_proto=services_in_proto, ) - def prune_messages_for_selective_gapic(self, *, - address_allowlist: Set['metadata.Address']) -> 'Service': + def prune_messages_for_selective_generation(self, *, + address_allowlist: Set['metadata.Address']) -> 'Service': """Returns a truncated version of this Service. Only the methods, messages, and enums contained in the address allowlist