feat: support per-wheel enable_implicit_namespace_pkgs in whl_mods (WIP)
Update: I was reading a thread in #python and saw that this set to True when setting --incompatible_default_to_explicit_init_py is actually desirable and forward-looking.
So perhaps this PR is unnecessary for my use case, unless somebody runs into issues and needs to toggle it for some packages/wheels.
Other note: perhaps the enable_implicit_namespace_pkgs documentation can be further clarified.
As part of investigating https://github.com/aspect-build/rules_py/issues/611 which requires enable_implicit_namespace_pkgs = True as a workaround to unblock PEX creation, I looked into how to only toggle on this flag per wheel, as per https://github.com/aspect-build/rules_py/issues/611#issuecomment-3305979729 .
The goal of this is to reduce reliance on this flag where it's not necessary.
This PR is a proof-of-concept to gather if there's any interest in this feature. The commits aren't cleaned up yet.
Not yet done:
- [ ] Update CHANGELOG.md
- [ ] Update documentation for whl_mods
Summary of Changes
Hello @chrisirhc, I'm Gemini Code Assist[^1]! 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 feature to rules_py by enabling the enable_implicit_namespace_pkgs flag to be set individually for each wheel via whl_mods. This change aims to provide more precise control over how namespace packages are handled, specifically addressing issues related to PEX creation by allowing the flag to be enabled only where necessary, thereby reducing its global reliance. This is currently a proof-of-concept to gather feedback on the approach.
Highlights
-
Per-wheel Namespace Package Control: Introduced a new
enable_implicit_namespace_pkgsattribute towhl_modsandpackage_annotation, allowing granular control over__init__.pyfile generation for namespace packages on a per-wheel basis. -
Configuration Propagation: The new
enable_implicit_namespace_pkgssetting is now propagated through thepypiextension and utilized when generatingwhl_librarybuild rules, ensuring the per-wheel configuration is applied. -
Test Coverage: New test cases have been added in
extension_tests.bzlto verify the correct handling and propagation of theenable_implicit_namespace_pkgsattribute withinwhl_mods, and existing tests ingenerate_whl_library_build_bazel_tests.bzlwere updated to include this new parameter.
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 |
|---|
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 :thumbsup: and :thumbsdown: 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.
[^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.