Skip to content

Conversation

@chalmerlowe
Copy link
Collaborator

@chalmerlowe chalmerlowe commented Sep 12, 2025

This adds two templates used to generate two different types of __init__ files.

  • Simple __init__.py that defines the BigQueryClient within the services directory (and only the BigQueryClient)
  • More complex __init__.py that defines the entire BigQuery interface for the library. This lists all the public classes including the BigQueryClient.

@chalmerlowe chalmerlowe requested review from a team as code owners September 12, 2025 09:26
@chalmerlowe chalmerlowe requested review from Neenu1995 and removed request for a team September 12, 2025 09:26
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Sep 12, 2025
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Sep 12, 2025
@chalmerlowe chalmerlowe added this to the µgen PoC milestone Sep 12, 2025
Comment on lines +22 to +27
{{ import }}
{%- endfor %}

__all__ = (
{%- for item in all_list %}
"{{ item }}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without context for how this is used, I wonder if this is the right level of abstraction? Seems to me that this requires whoever uses this to keep two separate lists in sync. I might prefer to see something like this:

{% for module, obj, alias in imports %}
from {{ module }} import {{ obj }} as {{ alias }}
{%- endfor }}

__all__ = (
{%- for module, obj, alias in imports %}
"{{ alias }}",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tswast

This is a good question. In the absence of context, it makes total sense to suggest this.

It presupposes that we have discovered all the needed imports and then generate the file from scratch.
That isn't what is happening here. This is intended to quickly overwrite one GAPIC-generated file so that we can include two new lines. And to do so simply and easily.

We start with a file that looks similar to this:

from .services.dataset_service import DatasetServiceClient
from .services.job_service import JobServiceClient
...
from .types.biglake_config import BigLakeConfiguration
from .types.clustering import Clustering
...
from .types.dataset import Access
from .types.dataset import Dataset
...
from .types.dataset import DatasetAccessEntry
from .types.dataset import DatasetList
...
from .types.time_partitioning import TimePartitioning
from .types.udf_resource import UserDefinedFunctionResource

__all__ = (
    "Access",
    "AggregationThresholdPolicy",
    ...
    "BigtableColumn",
    "BigtableColumnFamily",
    ...
    "ColumnReference",
    "ConnectionProperty",
    ...
    "GetServiceAccountRequest",
    "GetServiceAccountResponse",
    ...
    "VectorSearchStatistics",
    "ViewDefinition",
)

And try to create a file that looks like this:

from .services.centralized_service import BigQueryClient  # NEW first line this alphabetical list
from .services.dataset_service import DatasetServiceClient
from .services.job_service import JobServiceClient
...
from .types.biglake_config import BigLakeConfiguration
from .types.clustering import Clustering
...
from .types.dataset import Access
from .types.dataset import Dataset
...
from .types.dataset import DatasetAccessEntry
from .types.dataset import DatasetList
...
from .types.time_partitioning import TimePartitioning
from .types.udf_resource import UserDefinedFunctionResource

__all__ = __all__ = (
    "Access",
    "AggregationThresholdPolicy",
    ...
    "BigQueryClient", # NEW line in the middle of this alphabetical list
    "BigtableColumn",
    "BigtableColumnFamily",
    ...
    "ColumnReference",
    "ConnectionProperty",
    ...
    "GetServiceAccountRequest",
    "GetServiceAccountResponse",
    ...
    "VectorSearchStatistics",
    "ViewDefinition",
)

Our process for making this file is simply;

  • read the lines in their entirety from the GAPIC generated file for the import section into a list
  • read the lines in their entirety from the GAPIC generated file for the all section into a list

Add the two lines we care about (e.g. the NEW lines that reference BigQueryClient) to their respective lists and sort the list alphabetically so the sections will come out alphabetically.

We then use those lists as inputs to the template in each section.

Trying to break the lines into component parts (module, object, alias) just complicates what is basically a read a line and then write a line operation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tswast Following up. How do you feel about this PR. Approve? Needs more work?

Base automatically changed from chore-add-microgen-noxfile to autogen September 15, 2025 16:56
* feat: adds _helpers.py.js  template

* Updates with two usage examples

* updates the license header
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Sep 15, 2025
@chalmerlowe chalmerlowe merged commit a0b16ff into autogen Sep 18, 2025
14 of 25 checks passed
@chalmerlowe chalmerlowe deleted the chore-adds-init-files branch September 18, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/python-bigquery API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants