Skip to content

Commit 17dd60f

Browse files
authored
fix(pacmak): put package README into the right Python module (#928)
The (translated) Python README used to be written to the `<module>._jsii` module, as opposed to the main module. Put it in the right module where people will actually look for it.
1 parent 9952f86 commit 17dd60f

5 files changed

Lines changed: 31 additions & 29 deletions

File tree

packages/jsii-pacmak/lib/targets/python.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,11 @@ class Module implements PythonType {
10301030
code.line('publication.publish()');
10311031
}
10321032

1033+
/**
1034+
* Emit the README as module docstring if this is the entry point module (it loads the assembly)
1035+
*/
10331036
private emitModuleDocumentation(code: CodeMaker) {
1034-
if (this.package) {
1037+
if (this.package && this.loadAssembly && this.package.convertedReadme.trim().length > 0) {
10351038
code.line('"""');
10361039
code.line(this.package.convertedReadme);
10371040
code.line('"""');
@@ -1466,6 +1469,7 @@ class PythonGenerator extends Generator {
14661469
assm,
14671470
);
14681471

1472+
// This is the '<package>._jsii' module
14691473
const assemblyModule = new Module(
14701474
this.getAssemblyModuleName(assm),
14711475
null,
@@ -1494,12 +1498,16 @@ class PythonGenerator extends Generator {
14941498
// actually be generating a module, otherwise we'll generate a class within
14951499
// that module.
14961500
if (ns === this.assembly.name) {
1501+
// This is the main Python entry point (facade to the JSII module)
1502+
14971503
const module = new Module(
14981504
this.assembly.targets!.python!.module,
14991505
ns,
15001506
{ assembly: this.assembly,
15011507
assemblyFilename: this.getAssemblyFileName(),
1502-
loadAssembly: ns === this.assembly.name },
1508+
loadAssembly: ns === this.assembly.name,
1509+
package: this.package
1510+
},
15031511
);
15041512

15051513
this.package.addModule(module);

packages/jsii-pacmak/test/expected.jsii-calc-base/python/src/scope/jsii_calc_base/_jsii/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
"""
2-
3-
"""
41
import abc
52
import datetime
63
import enum

packages/jsii-pacmak/test/expected.jsii-calc-lib/python/src/scope/jsii_calc_lib/_jsii/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
"""
2-
3-
"""
41
import abc
52
import datetime
63
import enum

packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
"""
2+
# jsii Calculator
3+
4+
This library is used to demonstrate and test the features of JSII
5+
6+
## Sphinx
7+
8+
This file will be incorporated into the sphinx documentation.
9+
10+
If this file starts with an "H1" line (in our case `# jsii Calculator`), this
11+
heading will be used as the Sphinx topic name. Otherwise, the name of the module
12+
(`jsii-calc`) will be used instead.
13+
14+
## Code Samples
15+
16+
```python
17+
# Example may have issues. See https://github.com/aws/jsii/issues/826
18+
# This is totes a magic comment in here, just you wait!
19+
foo = "bar"
20+
```
21+
"""
122
import abc
223
import datetime
324
import enum

packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/_jsii/__init__.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
"""
2-
# jsii Calculator
3-
4-
This library is used to demonstrate and test the features of JSII
5-
6-
## Sphinx
7-
8-
This file will be incorporated into the sphinx documentation.
9-
10-
If this file starts with an "H1" line (in our case `# jsii Calculator`), this
11-
heading will be used as the Sphinx topic name. Otherwise, the name of the module
12-
(`jsii-calc`) will be used instead.
13-
14-
## Code Samples
15-
16-
```python
17-
# Example may have issues. See https://github.com/aws/jsii/issues/826
18-
# This is totes a magic comment in here, just you wait!
19-
foo = "bar"
20-
```
21-
"""
221
import abc
232
import datetime
243
import enum

0 commit comments

Comments
 (0)