Skip to content

Commit 84fd8bb

Browse files
RomainMullermergify[bot]
authored andcommitted
feat(python): add license & classifiers to generated packages (#712)
* feat(python): add classifiers to generated packages Adds three classifiers to generated packages: - Programming Language (Python 3) - Operating System (Independent) - License (from SPDX name) Fixes #707 * pass licence to setuptools
1 parent 511dfc4 commit 84fd8bb

5 files changed

Lines changed: 58 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { md2rst } from '../markdown';
1212
import { Target } from '../target';
1313
import { shell } from '../util';
1414

15+
/* eslint-disable @typescript-eslint/no-var-requires */
16+
const spdxLicenseList = require('spdx-license-list');
17+
/* eslint-enable @typescript-eslint/no-var-requires */
18+
1519
export default class Python extends Target {
1620
protected readonly generator = new PythonGenerator();
1721

@@ -1162,6 +1166,7 @@ class Package {
11621166
name: this.name,
11631167
version: this.version,
11641168
description: this.metadata.description,
1169+
license: this.metadata.license,
11651170
url: this.metadata.homepage,
11661171
long_description_content_type: 'text/markdown',
11671172
author: this.metadata.author.name + (
@@ -1175,9 +1180,32 @@ class Package {
11751180
package_data: packageData,
11761181
python_requires: '>=3.6',
11771182
install_requires: [`jsii~=${jsiiVersionSimple}`, 'publication>=0.0.3'].concat(dependencies),
1183+
classifiers: [
1184+
'Intended Audience :: Developers',
1185+
'Operating System :: OS Independent',
1186+
'Programming Language :: Python :: 3',
1187+
],
11781188
};
11791189
/* eslint-enable @typescript-eslint/camelcase */
11801190

1191+
switch (this.metadata.docs && this.metadata.docs.stability) {
1192+
case spec.Stability.Experimental:
1193+
setupKwargs.classifiers.push('Development Status :: 4 - Beta');
1194+
break;
1195+
case spec.Stability.Stable:
1196+
setupKwargs.classifiers.push('Development Status :: 5 - Production/Stable');
1197+
break;
1198+
case spec.Stability.Deprecated:
1199+
setupKwargs.classifiers.push('Development Status :: 7 - Inactive');
1200+
break;
1201+
default:
1202+
// No 'Development Status' trove classifier for you!
1203+
}
1204+
1205+
if (spdxLicenseList[this.metadata.license] && spdxLicenseList[this.metadata.license].osiApproved) {
1206+
setupKwargs.classifiers.push('License :: OSI Approved');
1207+
}
1208+
11811209
// We Need a setup.py to make this Package, actually a Package.
11821210
// TODO:
11831211
// - License

packages/jsii-pacmak/test/expected.jsii-calc-base-of-base/python/setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "scope.jsii-calc-base-of-base",
77
"version": "0.20.2",
88
"description": "An example transitive dependency for jsii-calc.",
9+
"license": "Apache-2.0",
910
"url": "https://github.com/aws/jsii",
1011
"long_description_content_type": "text/markdown",
1112
"author": "Amazon Web Services",
@@ -31,6 +32,12 @@
3132
"install_requires": [
3233
"jsii~=0.20.2",
3334
"publication>=0.0.3"
35+
],
36+
"classifiers": [
37+
"Intended Audience :: Developers",
38+
"Operating System :: OS Independent",
39+
"Programming Language :: Python :: 3",
40+
"License :: OSI Approved"
3441
]
3542
}
3643
""")

packages/jsii-pacmak/test/expected.jsii-calc-base/python/setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "scope.jsii-calc-base",
77
"version": "0.20.2",
88
"description": "An example direct dependency for jsii-calc.",
9+
"license": "Apache-2.0",
910
"url": "https://github.com/aws/jsii",
1011
"long_description_content_type": "text/markdown",
1112
"author": "Amazon Web Services",
@@ -32,6 +33,12 @@
3233
"jsii~=0.20.2",
3334
"publication>=0.0.3",
3435
"scope.jsii-calc-base-of-base~=0.20.2"
36+
],
37+
"classifiers": [
38+
"Intended Audience :: Developers",
39+
"Operating System :: OS Independent",
40+
"Programming Language :: Python :: 3",
41+
"License :: OSI Approved"
3542
]
3643
}
3744
""")

packages/jsii-pacmak/test/expected.jsii-calc-lib/python/setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "scope.jsii-calc-lib",
77
"version": "0.20.2",
88
"description": "A simple calcuator library built on JSII.",
9+
"license": "Apache-2.0",
910
"url": "https://github.com/aws/jsii",
1011
"long_description_content_type": "text/markdown",
1112
"author": "Amazon Web Services",
@@ -32,6 +33,13 @@
3233
"jsii~=0.20.2",
3334
"publication>=0.0.3",
3435
"scope.jsii-calc-base~=0.20.2"
36+
],
37+
"classifiers": [
38+
"Intended Audience :: Developers",
39+
"Operating System :: OS Independent",
40+
"Programming Language :: Python :: 3",
41+
"Development Status :: 7 - Inactive",
42+
"License :: OSI Approved"
3543
]
3644
}
3745
""")

packages/jsii-pacmak/test/expected.jsii-calc/python/setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "jsii-calc",
77
"version": "0.20.2",
88
"description": "A simple calcuator built on JSII.",
9+
"license": "Apache-2.0",
910
"url": "https://github.com/aws/jsii",
1011
"long_description_content_type": "text/markdown",
1112
"author": "Amazon Web Services",
@@ -34,6 +35,13 @@
3435
"scope.jsii-calc-base~=0.20.2",
3536
"scope.jsii-calc-base-of-base~=0.20.2",
3637
"scope.jsii-calc-lib~=0.20.2"
38+
],
39+
"classifiers": [
40+
"Intended Audience :: Developers",
41+
"Operating System :: OS Independent",
42+
"Programming Language :: Python :: 3",
43+
"Development Status :: 4 - Beta",
44+
"License :: OSI Approved"
3745
]
3846
}
3947
""")

0 commit comments

Comments
 (0)