-
-
Notifications
You must be signed in to change notification settings - Fork 630
feat(runfiles): support for --incompatible_compact_repo_mapping_manifest #3277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(runfiles): support for --incompatible_compact_repo_mapping_manifest #3277
Conversation
Summary of ChangesHello @jklukas, 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 integrates support for Bazel's Highlights
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
|
cc @fmeum for review |
There was a problem hiding this 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 adds support for Bazel's --incompatible_compact_repo_mapping_manifest
flag, which is a great feature for improving performance with bzlmod. The implementation is solid and includes a comprehensive set of tests. My review includes suggestions for a performance optimization in the new mapping logic, a fix for an outdated docstring, and some refactoring opportunities in both the implementation and the tests to improve maintainability and readability.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
||
assert ( | ||
source_repo is not None | ||
), "BUG: if the `source_repo` is None, we should never go past the `if` statement above" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: This assertion may still be important. I need to reassess above whether we need to match the previous conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think an equivalent assertion is needed with the new logic, but I'm open to more thoughts on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the assert. I'm not entirely sure if we have test coverage of all the cases.
Looking at the code, I don't see why the comment wouldn't still apply. source_repo can end up None here if the repo mapping is empty. (which, according to comments, occurs for workspace mode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to push some changes, but noticed that "maintainer can modify" isn't set.
Mostly LGTM, but please remove all the Mapping API compatibility code. As an internal class, there's no need for it to support the wide range of dict operations.
python/runfiles/runfiles.py
Outdated
return _RepositoryMapping(exact_mappings, prefixed_mappings) | ||
|
||
# Mapping protocol implementation | ||
def __getitem__(self, key: Tuple[str, str]) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this to e.g. get_canonical
or similar, just not __getitem__
. This is an internal custom class, so there's not need to add the abstraction or complications of making it look dict-like.
|
||
assert ( | ||
source_repo is not None | ||
), "BUG: if the `source_repo` is None, we should never go past the `if` statement above" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the assert. I'm not entirely sure if we have test coverage of all the cases.
Looking at the code, I don't see why the comment wouldn't still apply. source_repo can end up None here if the repo mapping is empty. (which, according to comments, occurs for workspace mode)
Co-authored-by: Richard Levasseur <[email protected]>
Thank you for the quick review! I believe all comments are now addressed. I removed the |
/gemini review |
There was a problem hiding this 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 adds support for Bazel's --incompatible_compact_repo_mapping_manifest
flag, which uses prefix-based repository mappings. The implementation introduces a _RepositoryMapping
class to handle both exact and new prefix-based mappings, which is a clean way to encapsulate the logic. The accompanying tests are thorough and cover various scenarios including precedence and ordering.
I've found a couple of areas for improvement. First, in Rlocation
, there's an opportunity to refactor the logic to avoid a redundant lookup and remove some unreachable code, making it more efficient and maintainable. Second, in _RepositoryMapping.create_from_file
, adding a check for empty lines in the manifest file would make the parsing more robust.
Overall, this is a great addition that addresses an important performance issue with large dependency graphs in Bazel.
for line in content.splitlines(): | ||
source_canonical, target_apparent, target_canonical = line.split(",") | ||
if source_canonical.endswith("*"): | ||
# This is a prefixed mapping - remove the '*' for prefix matching | ||
prefix = source_canonical[:-1] | ||
prefixed_mappings[(prefix, target_apparent)] = target_canonical | ||
else: | ||
# This is an exact mapping | ||
exact_mappings[(source_canonical, target_apparent)] = target_canonical | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop here doesn't account for empty or whitespace-only lines that content.splitlines()
might produce. This could lead to a ValueError
when trying to unpack the result of line.split(',')
on the next line. It's safer to strip each line and skip it if it's empty.
for line in content.splitlines(): | |
source_canonical, target_apparent, target_canonical = line.split(",") | |
if source_canonical.endswith("*"): | |
# This is a prefixed mapping - remove the '*' for prefix matching | |
prefix = source_canonical[:-1] | |
prefixed_mappings[(prefix, target_apparent)] = target_canonical | |
else: | |
# This is an exact mapping | |
exact_mappings[(source_canonical, target_apparent)] = target_canonical | |
for line in content.splitlines(): | |
line = line.strip() | |
if not line: | |
continue | |
source_canonical, target_apparent, target_canonical = line.split(",") | |
if source_canonical.endswith("*"): | |
# This is a prefixed mapping - remove the '*' for prefix matching | |
prefix = source_canonical[:-1] | |
prefixed_mappings[(prefix, target_apparent)] = target_canonical | |
else: | |
# This is an exact mapping | |
exact_mappings[(source_canonical, target_apparent)] = target_canonical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be best to error out anyway if repo mappings diverged from expected format in the ways described here.
Fixes #3022. To quote @rickeylev: