fix: prevent stdlib pyc files from invalidating runtime repos#3661
fix: prevent stdlib pyc files from invalidating runtime repos#3661rickeylev wants to merge 7 commits intobazel-contrib:mainfrom
Conversation
Summary of ChangesHello, 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 in Bazel 9 where the implicit watching behavior of Highlights
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a fix to prevent repository invalidation from .pyc file creation under Bazel 9 by symlinking __pycache__ directories to a location outside the repository. The approach is sound and well-implemented. My review includes one critical comment about a hardcoded debugging flag that must be removed, and a few medium-severity suggestions for code cleanup related to unused variables and imports.
python/private/python_repository.bzl
Outdated
| root = rctx.path(".") | ||
| root_str = str(root) |
| os_name = repo_utils.get_platforms_os_name(rctx) | ||
| is_windows = os_name == "windows" | ||
|
|
||
| # 1. RULES_PYTHON_PYCACHE_DIR |
There was a problem hiding this comment.
Please document the env vars that we use here somewhere plus don't forget the changelog notes. Might be great to mention.
The runtime repositories are being constantly invalidated due to pyc creation under Bazel 9
because, starting in Bazel 9,
glob()functions implicitly registerrepository_ctx.watch()calls on the files and directories they match. Thus, the directories where
__pycache__directories are created end up being considered changed (either directly because their
mtimes change, or indirectly, because their directory listing changes), which then invalidates
the repo, causing it to re-run.
This glob-induced-watching seems to occur even if an
excludewould have excluded the file.Note that this only seems to occur if
reproducible=False, which generally wouldn't occur,but could occur if a user is registering their own runtime and doesn't care about the sha.
Regardless, this still seems worthwhile because it allows pyc to be more safely be
generated without causing repo invalidations, while allowing them to be persisted between
repo-phase invocations.
To fix, create
__pycache__directories ahead of time and symlink them to a location that Bazelisn't watching, i.e. outside the repository's directory. I tried creating a separate top-level
folder that wasn't matched by any globs and symlinking to it, but Bazel would read through
the symlinks and watch the underlying locations.
This also has a side-bonus that allows pyc files to be re-used in between
repository-phase invocations.
Fixes #3643