Closed caseyduquettesc closed 1 year ago
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"
🚀 feature request
Relevant Rules
Description
When you have two
py_library
targets that are namespaced packages with the same namespace, it's not possible to test the code where one depends on the other without hacks in the library code. Take the following example -Folder structure is
<distribution_name>/<namespace_name>/<package_name>
, following https://packaging.python.org/en/latest/guides/packaging-namespace-packages/pkg_a's BUILD.bazel looks like
pkg_b's BUILD.bazel looks like
When someone installs
my-namespace-pkg-a
andmy-namespace-pkg-b
throughpip
, they can import classes usingHowever, if
pkg_b
tries to importpkg_a
, bazel test and bazel run can't resolve the same imports that an external consumer of the published wheel would use.This fails to resolve during execution in bazel. I can import
my_namespace
, but the only sub-package I can find is the current package,pkg_b
. I describe a workaround below, but it involves import hacking, which wouldn't be obvious to most engineers who run into this problem.Describe the solution you'd like
I'm not sure how you could solve this, but when a namespace target depends on another namespace target, if it could emulate how pip (or python?) works by merging the same packages of a namespace, then it might work.
Relevant docs regarding native namespaces:
Describe alternatives you've considered
The hack to get around this requires adding the parent directory to the import path
And then in the library code, you need to catch the import failure and try to import from the package within the namespace, instead of the namespace, but this is a code smell in published code.