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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,20 @@ class PythonModule implements PythonType {

// Before we write anything else, we need to write out our module headers, this
// is where we handle stuff like imports, any required initialization, etc.

// If multiple packages use the same namespace (in Python, a directory) it
// depends on how they are laid out on disk if deep imports of multiple packages
// will succeed. `pip` merges all packages into the same directory, and deep
// imports work automatically. `bazel` puts packages into different directories,
// and `import aws_cdk.subpackage` will fail if `aws_cdk/__init__.py` and
// `aws_cdk/subpackage/__init__.py` are not in the same directory.
//
// We can get around this by using `pkgutil` to extend the search path for the
// current module (`__path__`) with all packages found on `sys.path`.
code.line('from pkgutil import extend_path');
code.line('__path__ = extend_path(__path__, __name__)');
code.line();

code.line('import abc');
code.line('import builtins');
code.line('import datetime');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading