Skip to content

feat: delegate boilerplate helpers to google-api-core#17699

Open
hebaalazzeh wants to merge 15 commits into
feat/gapic-centralization-api-corefrom
feat/gapic-generator-centralization
Open

feat: delegate boilerplate helpers to google-api-core#17699
hebaalazzeh wants to merge 15 commits into
feat/gapic-centralization-api-corefrom
feat/gapic-generator-centralization

Conversation

@hebaalazzeh

Copy link
Copy Markdown
Contributor

Description

This draft PR updates the GAPIC generator templates to delegate common, service-agnostic boilerplate logic to the newly centralized functions in google-api-core.gapic_v1.

Related PR: #17628

Key Changes:

  • Deduplication via Delegation: The generator templates for client.py have been updated so that boilerplate helper methods (such as _use_client_cert_effective, _get_api_endpoint, and _get_default_mtls_endpoint) now delegate their implementations to the centralized api-core functions (e.g., _client_cert.use_client_cert_effective()).
  • Backward Compatibility: Rather than removing the internal _-prefixed methods from the generated clients entirely, we retain their definitions and signatures but delegate their logic. This ensures 100% backward compatibility for any existing code that might be monkey-patching or relying on these internal client methods.
  • Temporary Dependency Override: For testing purposes, the google-api-core dependency in setup.py has been temporarily pinned to the feat/gapic-centralization-api-core branch.

Purpose of this Draft PR:
Running the showcase and unit tests against this draft PR will provide end-to-end integration verification that the google-api-core centralization branch works perfectly with generated code before we officially merge it.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes several GAPIC helper functions (for routing, client certificates, environment configuration, and request ID setup) from the gapic-generator templates into google-api-core under google.api_core.gapic_v1. This refactoring simplifies the generated client code and consolidates the logic. The review feedback highlights two main areas for improvement: removing an unused import uuid statement in the client template, and preventing a potential AttributeError in get_api_endpoint when default_endpoint_template is None.

Comment thread packages/google-api-core/google/api_core/gapic_v1/_routing.py Outdated
@hebaalazzeh hebaalazzeh self-assigned this Jul 13, 2026
@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-generator-centralization branch from 4c7310b to 7c06a55 Compare July 13, 2026 18:28
@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request contains two main sets of changes. First, in bigframes, it refactors iloc indexing on DataFrames and Series to defer ordering checks until necessary (avoiding them for no-op slices) and adds support for positional column indexing and assignment by offsets, which helps handle duplicate or non-string column names. Second, in gapic-generator and google-api-core, it centralizes common client helper functions (such as mTLS endpoint resolution, client certificate handling, universe domain validation, and request ID setup) into shared internal modules in google-api-core, removing duplicate code from the generator templates and generated tests. Regarding the feedback, a performance concern was raised in bigframes where calling key.to_pandas() on a boolean indexer downloads the entire Series or Index to the client, and a server-side implementation was suggested instead.

Comment on lines +662 to +666
key_list = (
list(key)
if not isinstance(key, (bigframes.series.Series, indexes.Index))
else list(key.to_pandas())
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using key.to_pandas() here will download the entire boolean Series or Index to the client. For large datasets, this can lead to significant performance degradation and high memory usage on the client side.

Consider implementing this logic on the server side. For a boolean bigframes.Series, you could use SQL window functions to generate row numbers, filter for True values, and then use the resulting row numbers for positional filtering. This would avoid a potentially large data transfer.

@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-generator-centralization branch from a5ea0fa to 9c48260 Compare July 14, 2026 01:16
@hebaalazzeh hebaalazzeh changed the base branch from main to feat/gapic-centralization-api-core July 14, 2026 03:08
@hebaalazzeh hebaalazzeh marked this pull request as ready for review July 14, 2026 03:35
@hebaalazzeh hebaalazzeh requested a review from a team as a code owner July 14, 2026 03:35
@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes client routing, certificate handling, and environment variable reading in the generated Python clients by delegating to helper modules in google.api_core.gapic_v1, allowing for the removal of redundant boilerplate code and unit tests. The review feedback highlights several key issues: first, avoid including test_utils* as a top-level package in setup.py to prevent namespace conflicts; second, avoid downgrading google-api-core and removing its hashes in requirements.txt; third, remove the hardcoded public PyPI index URL in WORKSPACE to support private mirrors; and finally, guard the local installation of ../google-api-core in noxfile.py with an existence check to ensure standalone testing remains functional.

Comment thread packages/gapic-generator/setup.py Outdated
google-api-core==2.30.3 \
--hash=sha256:a85761ba72c444dad5d611c2220633480b2b6be2521eca69cca2dbb3ffd6bfe8 \
--hash=sha256:e601a37f148585319b26db36e219df68c5d07b6382cff2d580e83404e44d641b
google-api-core==2.25.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Downgrading google-api-core to 2.25.0 and removing its hashes in requirements.txt reduces security (by not verifying package integrity via hashes) and limits testing of the generator against newer versions of google-api-core (such as 2.30.3).

If this was done temporarily for testing the centralization changes, please ensure that requirements.txt is re-compiled using pip-compile to include the latest compatible version and its corresponding hashes before merging.

Comment thread packages/gapic-generator/WORKSPACE Outdated
Comment thread packages/gapic-generator/noxfile.py Outdated
hebaalazzeh and others added 4 commits July 13, 2026 20:39
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Python GAPIC generator to delegate several client-side helper methods (such as mTLS endpoint routing, client certificate sourcing, environment variable configuration, and request ID setup) to the google.api_core.gapic_v1 library. Consequently, local implementations and their corresponding unit tests have been removed from the templates. The PR also updates the generator's dependencies, setup configuration, and test environments to support Python 3.11 and use the local version of google-api-core during monorepo testing. The reviewer noted that the regenerated golden files are out of sync with the updated unit test template (test_%service.py.j2), as they are missing the mock for CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE in the mock_mtls_env fixture. All golden files should be regenerated to ensure consistency.

@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Python GAPIC generator templates to delegate routing, client certificate handling, environment configuration, and request ID setup to helper modules in google-api-core. It also cleans up redundant unit tests in the generated code and updates noxfile.py configurations to support local monorepo development. The review feedback highlights a mismatch between the template changes and the generated golden files regarding mocked environment variables, and recommends guarding several local google-api-core installations in noxfile.py with existence checks to prevent failures in sparse checkout environments.

Comment thread packages/gapic-generator/noxfile.py
Comment thread packages/gapic-generator/noxfile.py Outdated
Comment thread packages/gapic-generator/noxfile.py Outdated
Comment thread packages/gapic-generator/noxfile.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant