Skip to content

Commit

Permalink
feat: Add creation scripts in bin folder and adding it to setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlove-aws committed Aug 25, 2020
1 parent b1547a2 commit c49762b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/@jsii/spec/lib/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface Assembly extends AssemblyConfiguration, Documentable {
*
* @default none
*/
bin?: { [script: string]: string };
bin?: { readonly [script: string]: string };
}

/**
Expand Down
38 changes: 31 additions & 7 deletions packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ class PythonModule implements PythonType {
public constructor(
public readonly pythonName: string,
public readonly fqn: string | null,

opts: ModuleOpts,
) {
this.assembly = opts.assembly;
Expand Down Expand Up @@ -1429,13 +1430,6 @@ class PythonModule implements PythonType {
code.line(`from ${'.'.repeat(distanceFromRoot + 1)}_jsii import *`);

this.emitRequiredImports(code, context);
if (this.assembly.bin) {
code.line(`print('BIN-scripts were found.');`);
const scripts = Object.keys(this.assembly.bin);
for (const script of scripts) {
code.line(`print('${script}: ${this.assembly.bin[script]}');`);
}
}
}

// Emit all of our members.
Expand Down Expand Up @@ -1469,6 +1463,27 @@ class PythonModule implements PythonType {
code.line('publication.publish()');
}

public emitBinScripts(code: CodeMaker): string[] {
const scripts: string[] = [];
if (this.loadAssembly) {
if (this.assembly.bin != null) {
for (const [name, script_path] of Object.entries(this.assembly.bin)) {
const script_file = path.join(
'src',
pythonModuleNameToFilename(this.pythonName),
'bin',
name,
);
code.openFile(script_file);
code.line(`print('${name}: ${script_path}');`);
code.closeFile(script_file);
scripts.push(script_file);
}
}
}
return scripts;
}

/**
* Emit the README as module docstring if this is the entry point module (it loads the assembly)
*/
Expand Down Expand Up @@ -1618,6 +1633,8 @@ class Package {
a.pythonName.localeCompare(b.pythonName),
);

const scripts: string[] = [];

// Iterate over all of our modules, and write them out to disk.
for (const mod of modules) {
const filename = path.join(
Expand All @@ -1629,6 +1646,12 @@ class Package {
code.openFile(filename);
mod.emit(code, context);
code.closeFile(filename);

for (const script of mod.emitBinScripts(code)) {
if (scripts.indexOf(script) < 0) {
scripts.push(script);
}
}
}

// Handle our package data.
Expand Down Expand Up @@ -1707,6 +1730,7 @@ class Package {
'Programming Language :: Python :: 3.8',
'Typing :: Typed',
],
scripts,
};

switch (this.metadata.docs?.stability) {
Expand Down

0 comments on commit c49762b

Please sign in to comment.