Skip to content

Conversation

rickeylev
Copy link
Collaborator

Currently, the local toolchain code requires using a path (or program name) to find
the Python interpreter. This comes up short when using Bazel to
download an arbitrary runtime (or otherwise manage the creation of it, e.g.
downloading Python and building it from source in a repo rule). In such cases, the
file system location of the interpreter isn't known (it'll be in some Bazel cache
directory).

To fix, add the interpreter_target attribute to local_runtime_repo, which it
looks up the path for, then continues on as normal. As an example, the test uses
a custom repository rule to download a particular version of Python appropriate
to the OS.

By letting a local toolchain point to a label, it allows Bazel
repository rules to manage the download and creation of the Python
runtime itself. This makes it easy to customize where a runtime
is coming from.
@rickeylev rickeylev requested a review from aignas as a code owner September 29, 2025 03:10
Copy link
Contributor

Summary of Changes

Hello @rickeylev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the flexibility of local Python toolchains by introducing the ability to specify the Python interpreter using a Bazel label. Previously, toolchains were limited to resolving interpreters via direct file paths or program names on the system's PATH, which proved insufficient for scenarios where Bazel itself manages the Python runtime (e.g., through repository rules that download or build Python). The new interpreter_target attribute addresses this by allowing a label to point to the interpreter, making it possible to integrate Bazel-managed Python environments seamlessly into the toolchain resolution process.

Highlights

  • New interpreter_target attribute: Introduced interpreter_target to local_runtime_repo, allowing users to specify a Python interpreter via a Bazel label, rather than just a file system path or program name.
  • Enhanced Flexibility for Python Runtimes: This change enables Bazel to manage Python runtimes that are downloaded or built within repository rules, addressing limitations where the interpreter's file system location might not be known upfront.
  • Mutual Exclusivity: The interpreter_target and interpreter_path attributes are now mutually exclusive, ensuring clarity in how the interpreter is resolved.
  • Updated interpreter_path Default: The default value for interpreter_path has been changed from "python3" to an empty string, with "python3" now being the implicit default if neither interpreter_path nor interpreter_target is explicitly set.
  • New Test Infrastructure: Added new test cases and a pbs_archive repository rule to demonstrate and validate the functionality of specifying Python interpreters via labels, including downloading Python from a remote source.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 introduces a valuable feature by allowing local_runtime_repo to reference a Python interpreter via a Bazel label (interpreter_target). This is particularly useful for scenarios where runtimes are managed by Bazel itself. The implementation is solid, with appropriate logic for mutual exclusivity and path resolution. The addition of comprehensive tests and documentation is also commendable. I've identified a critical syntax error in one of the test files that needs to be fixed, and a high-severity issue in a new repository rule that could lead to insecure downloads. Once these are addressed, this PR will be in great shape.

Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

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

Some questions about naming/descriptions, but the impl LGTM.

@rickeylev rickeylev added this pull request to the merge queue Oct 1, 2025
Merged via the queue into bazel-contrib:main with commit fb06c86 Oct 1, 2025
4 checks passed
@rickeylev rickeylev deleted the tests.use.pbs.for.local.toolchain branch October 1, 2025 05:58
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.

2 participants