Skip to content

fix: manual runfiles path construction when using submodules#3636

Open
faximan wants to merge 2 commits intobazel-contrib:mainfrom
faximan:faximan/fix-submodule-path
Open

fix: manual runfiles path construction when using submodules#3636
faximan wants to merge 2 commits intobazel-contrib:mainfrom
faximan:faximan/fix-submodule-path

Conversation

@faximan
Copy link

@faximan faximan commented Feb 24, 2026

This fixes #3563. Verified by running the repro in https://github.com/mering/reproduction_rules_python_1_7.

The identified regression in b8e32c4 is problematic because prepending ctx.workspace_name to short_path results in paths containing .. (e.g., _main/../sub+/path/to/file.py) when building from a root module that includes other modules. This causes the _find_runfiles_root logic, which counts slashes, to incorrectly calculate the runfiles root.

The fix is simply using the available runfiles_root_path function instead. In the example above, this makes the path simply sub+/path/to/file.py.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @faximan, 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 resolves an issue with runfiles path construction in Bazel when dealing with binaries defined in separate modules. It fixes a regression that led to incorrect path calculations, particularly when building from a root module that includes other modules. The solution involves using the runfiles_root_path function to ensure accurate and consistent path resolution.

Highlights

  • Runfiles Path Construction: The PR fixes an issue where incorrect runfiles paths were being constructed in bootstrap scripts when a binary is defined in another Bazel module.
  • Regression Fix: Addresses a regression introduced by commit b8e32c4, which caused paths containing .. due to prepending ctx.workspace_name to short_path.
  • Solution: Replaces manual path construction with the runfiles_root_path function to ensure correct path resolution.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • CHANGELOG.md
    • Added a changelog entry documenting the fix for the incorrect runfiles path construction issue.
Activity
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 effectively addresses the runfiles path construction issue by consistently utilizing the runfiles_root_path helper function across py_executable.bzl. This change correctly handles paths from different Bazel modules, preventing .. segments that previously caused incorrect runfiles root calculations. The update to the CHANGELOG.md accurately reflects this important fix. Overall, these changes significantly improve the correctness and maintainability of the Python bootstrap scripts.

@faximan faximan changed the title fix: manual runfiles path construction fix: manual runfiles path construction when using submodules Feb 24, 2026
substitutions = {
"%python_binary%": python_binary,
"%python_binary_actual%": python_binary_actual,
"%stage2_bootstrap%": "{}/{}".format(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to add a test somewhere? For example examples/bzlmod has submodules in it which could ensure that we can still import things.

@rickeylev Any other ideas how we could do this?

Copy link
Author

Choose a reason for hiding this comment

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

I tried and failed to write a test here tests the specific fix in this PR. As I'm very unfamiliar with this code base in general, I am afraid I'd need support to land that.

@shayanhoshyari
Copy link
Contributor

Related to #3605

@faximan
Copy link
Author

faximan commented Feb 25, 2026

Related to #3605

Indeed! It is not sufficient to fix #3563 though (I just verified), but it is definitely the same idea.

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.

[Regression] Error loading native python modules when binary is defined in another bazel module

3 participants