pycross_wheel_library: enable implicit namespace packages#216
pycross_wheel_library: enable implicit namespace packages#216tobyh-canva wants to merge 1 commit into
pycross_wheel_library: enable implicit namespace packages#216Conversation
## Context Currently, `pycross_wheel_library` installs wheels and unconditionally converts any implicit namespace packages into legacy `pkgutil`-style namespace packages. This `pkgutil`-style conversion can be problematic and unexpected in a lot of cases, and should be unnecessary beyond Python 3.3 when the `--incompatible_default_to_explicit_init_py=true` Bazel flag is set. Looking at the `pycross_wheel_library` rule implementation, and the source code of `wheel_installer.py`, it appears as though there was an intention to allow users to disable this `pkgutil`-style conversion, but the option isn't exposed via the Bazel interfaces, and it's also not used inside the script itself. ## Intent Allow users to disable the automatic conversion of PEP 420 implicit namespace packages to `pkgutil`-style namespace packages, whilst maintaining backwards compatibility. ## Changes - Introduce a boolean bazelrc flag, `--@rules_pycross//config_settings:default_enable_implicit_namespace_pkgs`, to configure the default behaviour of enabling implicit namespace packages in `pycross_wheel_library`. - Update the `pycross_wheel_library` rule and ``wheel_installer.py` script to respect the flag. - Document the flag.
There was a problem hiding this comment.
Just FYI, I wrote this doc by hand, it's not generated 😅 I couldn't figure out a way to use stardoc to generate docs for a Bazel flag. LMK if there's a preferred way to generate this doc.
| "enable_implicit_namespace_pkgs": attr.int( | ||
| default = -1, |
There was a problem hiding this comment.
There are no tests for this option. I'd be happy to add some, but I'm not sure where they should go - in //e2e or //pycross/tests? And if so, should I just check in a dummy wheel file containing a namespace package? Please LMK what you would prefer 🙏
|
Hi @tobyh-canva Sorry for being way late to this. I agree this option just slipped through the cracks at some point. It looks like What do you think about doing the same in rules_pycross? Versus making a global config setting. |
Context
Currently,
pycross_wheel_libraryinstalls wheels and unconditionally converts any implicit namespace packages into legacypkgutil-style namespace packages.This
pkgutil-style conversion can be problematic and unexpected in a lot of cases, and should be unnecessary beyond Python 3.3 when the--incompatible_default_to_explicit_init_py=trueBazel flag is set.Looking at the
pycross_wheel_libraryrule implementation, and the source code ofwheel_installer.py, it appears as though there was an intention to allow users to disable thispkgutil-style conversion, but the option isn't exposed via the Bazel interfaces, and it's also not used inside the script itself.Intent
Allow users to disable the automatic conversion of PEP 420 implicit namespace packages to
pkgutil-style namespace packages, whilst maintaining backwards compatibility.Changes
--@rules_pycross//config_settings:default_enable_implicit_namespace_pkgs, to configure the default behaviour of enabling implicit namespace packages inpycross_wheel_library.pycross_wheel_libraryrule andwheel_installer.pyscript to respect the flag.