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): some submodules are not exported from aws-cdk-lib #3491

Merged
merged 2 commits into from
Apr 19, 2022
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
37 changes: 36 additions & 1 deletion packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,21 @@ class PythonModule implements PythonType {
}

// Whatever names we've exported, we'll write out our __all__ that lists them.
const exportedMembers = this.members.map((m) => `"${m.pythonName}"`);
//
// __all__ is normally used for when users write `from library import *`, but we also
// use it with the `publication` module to hide everything that's NOT in the list.
//
// Normally adding submodules to `__all__` has the (negative?) side-effect
// that all submodules get loaded when the user does `import *`, but we
// already load submodules anyway so it doesn't make a difference, and in combination
// with the `publication` module NOT having them in this list hides any submodules
// we import as part of typechecking.
const exportedMembers = [
...this.members.map((m) => `"${m.pythonName}"`),
...this.modules
.filter((m) => this.isDirectChild(m))
.map((m) => `"${lastComponent(m.pythonName)}"`),
];
if (this.loadAssembly) {
exportedMembers.push('"__jsii_assembly__"');
}
Expand Down Expand Up @@ -1747,6 +1761,19 @@ class PythonModule implements PythonType {
return scripts;
}

private isDirectChild(pyMod: PythonModule) {
if (
this.pythonName === pyMod.pythonName ||
!pyMod.pythonName.startsWith(`${this.pythonName}.`)
) {
return false;
}
// Must include only one more component
return !pyMod.pythonName
.substring(this.pythonName.length + 1)
.includes('.');
}

/**
* Emit the README as module docstring if this is the entry point module (it loads the assembly)
*/
Expand Down Expand Up @@ -3114,3 +3141,11 @@ function nestedContext(
}

const isDeprecated = (x: PythonBase) => x.docs?.deprecated !== undefined;

/**
* Last component of a .-separated name
*/
function lastComponent(n: string) {
const parts = n.split('.');
return parts[parts.length - 1];
}

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