- 
                Notifications
    You must be signed in to change notification settings 
- Fork 321
          Feat: microgen - adds _client_helpers.py.j2 template
          #2299
        
          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
Conversation
Migrates the empty __init__.py file to the microgenerator package.
Introduces the CodeAnalyzer class and helper functions for parsing Python code using the ast module. This provides the foundation for understanding service client structures.
    Implements functions to analyze Python source files, including:
    - Filtering classes and methods based on configuration.
    - Building a schema of request classes and their arguments.
    - Processing service client files to extract relevant information.
    …ke_case function in name_utils.py to correctly convert PascalCase names containing acronyms to snake_case.
…generating the BigQueryClient class.
…l template containing helper macros for the client generation.
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.
minor updates.
| #} | ||
|  | ||
| # --- HELPER METHODS --- | ||
| def _parse_dataset_path(self, dataset_path: str) -> Tuple[Optional[str], str]: | 
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.
Are these helper functions going to be included in every generated client or is the inclusion of each individual function done on a selective basis?
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.
Thanks for checking.
There is only one generated client and these three helper functions will be included one time via jinja templating imports in the file that the client class is placed in.
For context: The purpose of this microgenerator is to create code that will support customer transition from using a strictly handwritten BigQuery (BQ) library to using a GAPIC generated BQ library. Specifically it will allow the customer to use a single BigQueryClient instead of using seven very disparate *ServiceClients (e.g. JobServiceClient, TableServiceClient, ModelServiceClient) AND to do so in a way that feels very similar to how they use BigQuery now.
To help facilitate this, a proxy of certain attributes associated with each *ServiceClient will be added to new a centralized BigQueryClient and provide a passthrough so that users can use the attribute they want (e.g. JobServiceClient.list_jobs(), DatasetServiceClient.get_dataset(), TableServiceClient.update_table()) in the ServiceClient they want.
Our helpers are present so that customer can provide the BigQueryClient method calls with strings that can be parsed and passed successfully to the underlying attributes.
As an example, without the centralized BigQueryClient and the helpers:
To use TableServiceClient.list_tables(), the customer would need to instantiate a ListTableRequest() object which will require the customer to pass in info such as the project_id and dataset_id.
req = ListTableRequest(project="proj_id", dataset="dataset_id")
tableClient = TableServiceClient.list_tables(request=req)
For the past ten years, customers have not needed to do that extra step.
With the new BigQueryClient, the passthrough methods, and the helpers, the customer will have a user experience much closer to what they are used to, for example:
bqClient = BigQueryClient.list_tables("proj_id.dataset_id")
Our helpers take strings similar to proj_id.dataset_id and create an appropriate *Request object that is passed invisibly on behalf of the customer.
It may seem like a little thing, but it will hopefully ease the transition to using the new GAPIC generated library.
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.
@gkevinzheng see above.
| LGTM | 
client.py.j2template #2298 (should be merged after that PR is merged.)This PR adds a
_client_helpers.py.j2template to create helper capabilities.NOTE: This template supports an Alpha release version of a simple microgenerator. It is being merged into a development branch (
autogen) for testing and review purposes, not intomain.