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

feat(python): add license & classifiers to generated packages #712

Merged
merged 6 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 31 additions & 3 deletions packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { propertySpec } from '../reflect-hacks';
import { Target, TargetOptions } from '../target';
import { shell } from '../util';

// tslint:disable-next-line:no-var-requires
const spdxLicenseList = require('spdx-license-list');

export default class Python extends Target {
protected readonly generator = new PythonGenerator();

Expand Down Expand Up @@ -1135,6 +1138,25 @@ class Package {
// Strip " (build abcdef)" from the jsii version
const jsiiVersionSimple = this.metadata.jsiiVersion.replace(/ .*$/, '');

const classifiers = [
`License :: ${getLicense(this.metadata.license)}`,
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
];
switch (this.metadata.docs && this.metadata.docs.stability) {
case spec.Stability.Experimental:
classifiers.push('Development Status :: 4 - Beta');
break;
case spec.Stability.Stable:
classifiers.push('Development Status :: 5 - Production/Stable');
break;
case spec.Stability.Deprecated:
classifiers.push('Development Status :: 7 - Inactive');
break;
default:
// No 'Development Status' classifier in those cases
}

const setupKwargs = {
name: this.name,
version: this.version,
Expand All @@ -1152,12 +1174,10 @@ class Package {
package_data: packageData,
python_requires: ">=3.6",
install_requires: [`jsii~=${jsiiVersionSimple}`, "publication>=0.0.3"].concat(dependencies),
classifiers,
};

// We Need a setup.py to make this Package, actually a Package.
// TODO:
// - License
// - Classifiers
code.openFile("setup.py");
code.line("import json");
code.line("import setuptools");
Expand Down Expand Up @@ -1187,6 +1207,14 @@ class Package {
code.openFile("MANIFEST.in");
code.line("include pyproject.toml");
code.closeFile("MANIFEST.in");

function getLicense(licenseName: string): string {
const spdx = spdxLicenseList[licenseName];
if (spdx.osiApproved) {
return `OSI Approved :: ${spdx.name}`;
}
return spdx.name;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"jsii~=0.15.0",
"publication>=0.0.3",
"scope.jsii-calc-base-of-base~=0.15.0"
],
"classifiers": [
"License :: OSI Approved :: Apache License 2.0",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3"
]
}
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
"jsii~=0.15.0",
"publication>=0.0.3",
"scope.jsii-calc-base~=0.15.0"
],
"classifiers": [
"License :: OSI Approved :: Apache License 2.0",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Development Status :: 7 - Inactive"
]
}
""")
Expand Down
6 changes: 6 additions & 0 deletions packages/jsii-pacmak/test/expected.jsii-calc/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"scope.jsii-calc-base~=0.15.0",
"scope.jsii-calc-base-of-base~=0.15.0",
"scope.jsii-calc-lib~=0.15.0"
],
"classifiers": [
"License :: OSI Approved :: Apache License 2.0",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Development Status :: 4 - Beta"
]
}
""")
Expand Down