-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: restore messages not attached to rpc in selective_gapic_generation #16951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
parthea
wants to merge
3
commits into
main
Choose a base branch
from
selective-gapic-restore-messages-not-attached-to-any-rpc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2014,7 +2014,6 @@ def add_to_address_allowlist( | |
| objects to add to. Only the addresses of the allowlisted methods, the services | ||
| containing these methods, and messages/enums those methods use will be part of the | ||
| final address_allowlist. The set may be modified during this call. | ||
| method_allowlist (Set[str]): An allowlist of fully-qualified method names. | ||
| resource_messages (Dict[str, wrappers.MessageType]): A dictionary mapping the unified | ||
| resource type name of a resource message to the corresponding MessageType object | ||
| representing that resource message. Only resources with a message representation | ||
|
|
@@ -2061,26 +2060,28 @@ def add_to_address_allowlist( | |
| resource_messages=resource_messages, | ||
| ) | ||
|
|
||
| def with_internal_methods(self, *, public_methods: Set[str]) -> "Method": | ||
| """Returns a version of this ``Method`` marked as internal | ||
|
|
||
| The methods not in the public_methods set will be marked as internal and | ||
| this ``Service`` will as well by extension (see :meth:`Service.is_internal`). | ||
| def with_selective_generation( | ||
| self, | ||
| *, | ||
| generate_omitted_as_internal: bool, | ||
| public_methods: Set[str], | ||
| excluded_addresses: Set["metadata.Address"], | ||
| ) -> "Method": | ||
|
|
||
| Args: | ||
| public_methods (Set[str]): An allowlist of fully-qualified method names. | ||
| Methods not in this allowlist will be marked as internal. | ||
| Returns: | ||
| Service: A version of this `Service` with `Method` objects corresponding to methods | ||
| not in `public_methods` marked as internal. | ||
| """ | ||
| if self.ident.proto in public_methods: | ||
| return self | ||
|
|
||
| return dataclasses.replace( | ||
| self, | ||
| is_internal=True, | ||
| ) | ||
| # Not public. | ||
| # We mark it as internal if either generate_omitted_as_internal is set, | ||
| # or if the method is reachable from some public method (e.g. as a polling method). | ||
| if generate_omitted_as_internal or self.meta.address not in excluded_addresses: | ||
| return dataclasses.replace( | ||
| self, | ||
| is_internal=True, | ||
| ) | ||
| else: | ||
| return None | ||
|
|
||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True) | ||
|
|
@@ -2467,45 +2468,24 @@ def add_to_address_allowlist( | |
| services_in_proto=services_in_proto, | ||
| ) | ||
|
|
||
| def prune_messages_for_selective_generation( | ||
| self, *, address_allowlist: Set["metadata.Address"] | ||
| def with_selective_generation( | ||
| self, | ||
| *, | ||
| generate_omitted_as_internal: bool, | ||
| public_methods: Set[str], | ||
| excluded_addresses: Set["metadata.Address"], | ||
| ) -> "Service": | ||
| """Returns a truncated version of this Service. | ||
|
|
||
| Only the methods, messages, and enums contained in the address allowlist | ||
| are included in the returned object. | ||
|
|
||
| Args: | ||
| address_allowlist (Set[metadata.Address]): A set of allowlisted metadata.Address | ||
| objects to filter against. Objects with addresses not the allowlist will be | ||
| removed from the returned Proto. | ||
| Returns: | ||
| Service: A truncated version of this proto. | ||
| """ | ||
| return dataclasses.replace( | ||
| self, | ||
| methods={ | ||
| k: v for k, v in self.methods.items() if v.ident in address_allowlist | ||
| }, | ||
| ) | ||
|
|
||
| def with_internal_methods(self, *, public_methods: Set[str]) -> "Service": | ||
| """Returns a version of this ``Service`` with some Methods marked as internal. | ||
| methods = {} | ||
| for k, v in self.methods.items(): | ||
| new_v = v.with_selective_generation( | ||
| generate_omitted_as_internal=generate_omitted_as_internal, | ||
| public_methods=public_methods, | ||
| excluded_addresses=excluded_addresses) | ||
| if new_v: | ||
| methods[k] = new_v | ||
|
|
||
| The methods not in the public_methods set will be marked as internal and | ||
| this ``Service`` will as well by extension (see :meth:`Service.is_internal`). | ||
| if not generate_omitted_as_internal and not methods: | ||
| return None | ||
|
|
||
| Args: | ||
| public_methods (Set[str]): An allowlist of fully-qualified method names. | ||
| Methods not in this allowlist will be marked as internal. | ||
| Returns: | ||
| Service: A version of this `Service` with `Method` objects corresponding to methods | ||
| not in `public_methods` marked as internal. | ||
| """ | ||
| return dataclasses.replace( | ||
| self, | ||
| methods={ | ||
| k: v.with_internal_methods(public_methods=public_methods) | ||
| for k, v in self.methods.items() | ||
| }, | ||
| ) | ||
| return dataclasses.replace(self, methods=methods) | ||
|
Comment on lines
+2471
to
+2491
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The def with_selective_generation(
self,
*,
generate_omitted_as_internal: bool,
public_methods: Set[str],
) -> Optional["Service"]:
"""Returns a version of this Service for selective generation.
Args:
generate_omitted_as_internal (bool): Whether to mark omitted methods as internal.
public_methods (Set[str]): The set of fully-qualified method names to keep as public.
Returns:
Optional[Service]: The service with filtered methods, or None if it should be removed.
"""
methods = {}
for k, v in self.methods.items():
new_v = v.with_selective_generation(
generate_omitted_as_internal=generate_omitted_as_internal,
public_methods=public_methods)
if new_v:
methods[k] = new_v
if not generate_omitted_as_internal and not methods:
return None
return dataclasses.replace(self, methods=methods)References
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
with_selective_generationmethod is missing a docstring and the return type hint should beOptional["Method"]since it returnsNonewhen a method is omitted and not marked as internal.References