Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsii-pacmak): different packages sharing a namespace fail in Bazel (
#4437) In Bazel, every package is extracted into a separate directory that are all put into the `$PYTHONPATH` individually. However when searching, Python will latch onto the directory that has an `__init__.py` in it and only import from that directory. Example: ``` eco_package1/ └── site-packages/ └── eco/ └── package1/ └── __init__.py eco/ └── site-packages/ └── eco/ └── __init__.py ``` In this case, the following command will fail: ```py import eco.package1 ``` Because `eco/package1/__init__.py` is not in the same directory as `eco/__init__.py`. We can fix this by generating a command into every `__init__.py` that uses `pkgutil` to extend the search path for a package; it will put all directories in `$PYTHONPATH` that contain the same package onto the search path for submodules. The command looks like this: ```py from pkgutil import extend_path __path__ = extend_path(__path__, __name__) ``` Resolves #3881, thanks to @psalvaggio-dl for providing a repro and doing the research for a fix. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information