Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsii-pacmak): different packages sharing a namespace fail in Bazel #4437

Merged
merged 2 commits into from
Mar 4, 2024

Commits on Mar 1, 2024

  1. fix(jsii-pacmak): different packages sharing a namespace fail in Bazel

    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 root 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__)
    ```
    rix0rrr committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    c944d42 View commit details
    Browse the repository at this point in the history
  2. Snapshots

    rix0rrr committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    c78cfc2 View commit details
    Browse the repository at this point in the history