feat(pypi): Use target_compatible_with in package aliases#3586
feat(pypi): Use target_compatible_with in package aliases#3586nahueespinosa wants to merge 2 commits intobazel-contrib:mainfrom
Conversation
Summary of ChangesHello @nahueespinosa, 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 introduces a significant improvement to how Bazel handles Python package compatibility within multi-Python environments. By leveraging Bazel's 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
Activity
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
|
Signed-off-by: Nahuel Espinosa <nahue.espinosa@gmail.com>
c01ea5f to
e8966fb
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to handle platform-specific package compatibility by using target_compatible_with in package aliases. This allows Bazel to gracefully skip incompatible targets in multi-platform builds. The implementation in pkg_aliases.bzl correctly uses a select statement to set compatibility based on the provided configuration settings. My review includes a suggestion to improve code style for type checking and a recommendation to add tests to verify the new target_compatible_with logic, which is currently missing. Overall, this is a good proof of concept that addresses a valid use case.
| if target_name.startswith("_"): | ||
| kwargs["visibility"] = ["//_groups:__subpackages__"] | ||
|
|
||
| if type(actual) == type({}): |
There was a problem hiding this comment.
| extra_aliases = ["my_special"], | ||
| native = struct( | ||
| alias = lambda *, name, actual, visibility = None, tags = None: got.update({name: actual}), | ||
| alias = lambda *, name, actual, visibility = None, tags = None, target_compatible_with = None: got.update({name: actual}), |
There was a problem hiding this comment.
The tests should be updated to assert that target_compatible_with is being set correctly. Currently, the new target_compatible_with parameter is accepted by the mock alias but its value is not checked.
You could modify the mock to store the target_compatible_with value and then add assertions to verify it. For example, in _test_config_setting_aliases you could do:
# In _test_config_setting_aliases
got_compatible_with = {}
def mock_alias(*, name, actual, visibility = None, tags = None, target_compatible_with = None):
got.update({name: actual})
if target_compatible_with:
got_compatible_with[name] = target_compatible_with
# ... inside pkg_aliases call
native = struct(
alias = mock_alias
)
# ... after pkg_aliases call
# The result of selects.with_or is a dict for the select() statement.
# We can check its contents.
env.expect.that_dict(got_compatible_with["pkg"]).to_be({
"//:my_config_setting": [],
"//conditions:default": ["@platforms//:incompatible"],
})This would ensure the new logic is correctly tested across different scenarios (e.g., with single config settings, multiple, and with whl_config_setting).
The aliases created by pypi use
target_compatible_withwhere applicable. This prevents hard errors when multiple Python toolchains are defined and certain packages are not supported across all of them. Using@platforms//:incompatibleBazel can gracefully skip incompatible targets during a wildcard build (e.g., //...) rather than failing the entire invocation.As a proof of concept I changed the constraint on the
websocketspackage in themulti_python_versionsexample to exclude it from Python 3.10. Runningbazel test //...now correctly skips the incompatible targets:This is currently a proof of concept. I wanted to see if this align with the project's direction and whether you would consider supporting this use case.