Skip to content

Commit f3d1da0

Browse files
RomainMullermergify[bot]
authored andcommitted
feat(python): check distribution artifacts with twine (#711)
Adds a `twine check` invocation at the end of building the distribution artifacts for PyPI, in order to ensure the produced bundles will render propertly on PyPI, and be valid artifacts. This particularly guards against "tool old" versions of `setuptools`, but could also catch certain other issues. Fixes #710
1 parent b37790d commit f3d1da0

File tree

4 files changed

+76
-52
lines changed

4 files changed

+76
-52
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,25 @@ Due to the polyglot nature of `jsii`, the toolchain requirements are somewhat
1111
more complicated than for most projects. In order to locally develop `jsii`, you
1212
will need the following tools:
1313

14-
- [Node 8.11.0] or later
15-
- An OpenJDK-8 distribution
16-
+ [Oracle's OpenJDK8]
17-
+ [Amazon Corretto 8]
18-
- [.NET Core 2.0] or later
19-
- [Python 3.6.5] or later
20-
- [Ruby 2.5.1] or later
21-
22-
[Node 8.11.0]: https://nodejs.org/download/release/v8.11.0/
14+
- [Node `8.11.0`] or later
15+
- An OpenJDK-8 distribution (e.g: [Oracle's OpenJDK8], [Amazon Corretto 8])
16+
+ [`maven >= 3.0.5`](https://maven.apache.org)
17+
- [.NET Core `2.0`] or later
18+
+ *Recommended:* [`mono >= 5`](https://www.mono-project.com)
19+
- [Python `3.6.5`] or later
20+
+ [`pip`](https://pip.pypa.io/en/stable/installing/)
21+
+ [`setuptools >= 38.6.0`](https://pypi.org/project/setuptools/)
22+
+ [`wheel`](https://pypi.org/project/wheel/)
23+
+ *Recommended:* [`twine`](https://pypi.org/project/twine/)
24+
- [Ruby `2.4.4p296`] or later
25+
+ [`bundler ~> 1.17.2`](https://bundler.io)
26+
27+
[Node `8.11.0`]: https://nodejs.org/download/release/v8.11.0/
2328
[Oracle's OpenJDK8]: http://openjdk.java.net/install/
2429
[Amazon Corretto 8]: https://aws.amazon.com/corretto/
25-
[.NET Core 2.0]: https://www.microsoft.com/net/download
26-
[Python 3.6.5]: https://www.python.org/downloads/release/python-365/
27-
[Ruby 2.5.1]: https://www.ruby-lang.org/en/news/2018/03/28/ruby-2-5-1-released/
30+
[.NET Core `2.0`]: https://www.microsoft.com/net/download
31+
[Python `3.6.5`]: https://www.python.org/downloads/release/python-365/
32+
[Ruby `2.4.4p296`]: https://www.ruby-lang.org/en/news/2018/03/28/ruby-2-5-1-released/
2833

2934
### Alterative: build in Docker
3035

packages/jsii-pacmak/lib/logging.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
export let level = 0;
2-
3-
export const LEVEL_INFO = 1;
4-
export const LEVEL_VERBOSE = 2;
5-
61
export enum Level {
2+
WARN = -1,
73
QUIET = 0,
84
INFO = 1,
95
VERBOSE = 2,
106
}
117

8+
export const LEVEL_INFO: number = Level.INFO;
9+
export const LEVEL_VERBOSE: number = Level.VERBOSE;
10+
11+
/** The minimal logging level for messages to be emitted. */
12+
export let level = Level.QUIET;
13+
14+
export function warn(fmt: string, ...args: any[]) {
15+
log(Level.WARN, fmt, ...args);
16+
}
17+
1218
export function info(fmt: string, ...args: any[]) {
1319
log(Level.INFO, fmt, ...args);
1420
}
@@ -23,4 +29,4 @@ function log(messageLevel: Level, fmt: string, ...args: any[]) {
2329
// tslint:disable-next-line:no-console
2430
console.error.call(console, ...[ `[jsii-pacmak] [${levelName}]`, fmt, ...args ]);
2531
}
26-
}
32+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as reflect from 'jsii-reflect';
66
import * as spec from 'jsii-spec';
77
import { Stability } from 'jsii-spec';
88
import { Generator, GeneratorOptions } from '../generator';
9+
import { warn } from '../logging';
910
import { md2rst } from '../markdown';
1011
import { propertySpec } from '../reflect-hacks';
1112
import { Target, TargetOptions } from '../target';
@@ -28,6 +29,22 @@ export default class Python extends Target {
2829
// Actually package up our code, both as a sdist and a wheel for publishing.
2930
await shell("python3", ["setup.py", "sdist", "--dist-dir", outDir], { cwd: sourceDir });
3031
await shell("python3", ["setup.py", "bdist_wheel", "--dist-dir", outDir], { cwd: sourceDir });
32+
if (await twineIsPresent()) {
33+
await shell("twine", ["check", path.join(outDir, '*')], { cwd: sourceDir });
34+
} else {
35+
warn('Unable to validate distribution packages because `twine` is not present. '
36+
+ 'Run `pip3 install twine` to enable distribution package validation.');
37+
}
38+
39+
// Approximating existence check using `pip3 show`. If that fails, assume twine is not there.
40+
async function twineIsPresent(): Promise<boolean> {
41+
try {
42+
const output = await shell("pip3", ["show", "twine"], { cwd: sourceDir });
43+
return output.trim() !== '';
44+
} catch {
45+
return false;
46+
}
47+
}
3148
}
3249
}
3350

superchain/Dockerfile

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,19 @@
11
FROM amazonlinux:2
22

3-
# Install shared dependencies
4-
RUN yum -y upgrade \
5-
&& yum -y install awscli git gzip rsync tar unzip zip \
6-
&& yum clean all && rm -rf /var/cache/yum
7-
8-
###
9-
# We'll be trying to install stuff slowest to fastest, as a courtesy to people who'll have to build & re-build this.
10-
###
11-
12-
# Install NVM and Node 8+
13-
ARG NODE_VERSION=8.16.0
14-
ARG NPM_VERSION=6.8.0
15-
ENV NVM_DIR=/usr/local/nvm
16-
RUN curl -sSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh -o /tmp/install-nvm.sh \
17-
&& echo "ef7ad1db40c92f348c0461f24983b71ba0ea7d45d4007a36e484270fa7f81fcf /tmp/install-nvm.sh" | sha256sum -c \
18-
&& mkdir -p ${NVM_DIR} \
19-
&& bash /tmp/install-nvm.sh \
20-
&& rm /tmp/install-nvm.sh \
21-
&& . ${NVM_DIR}/nvm.sh \
22-
&& nvm install ${NODE_VERSION} \
23-
&& nvm alias default ${NODE_VERSION} \
24-
&& nvm use default \
25-
&& npm -g install npm@^${NPM_VERSION} \
26-
&& npm set unsafe-perm true
27-
ENV NODE_PATH=${NVM_DIR}/versions/node/v${NODE_VERSION}/lib/node_modules \
28-
PATH=${PATH}:${NVM_DIR}/versions/node/v${NODE_VERSION}/bin
29-
# Install .NET Core & mono
3+
# Install .NET Core, mono & PowerShell
304
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \
315
DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
326
COPY gpg/mono.asc /tmp/mono.asc
337
RUN rpm --import "https://packages.microsoft.com/keys/microsoft.asc" \
348
&& rpm -Uvh "https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm" \
359
&& rpm --import /tmp/mono.asc && rm -f /tmp/mono.asc \
3610
&& curl "https://download.mono-project.com/repo/centos6-stable.repo" | tee /etc/yum.repos.d/mono-centos6-stable.repo \
37-
&& yum -y install dotnet-sdk-2.2 mono-devel \
38-
&& yum clean all && rm -rf /var/cache/yum
39-
40-
# Install Powershell
41-
RUN yum install -y powershell \
11+
&& yum -y install dotnet-sdk-2.2 mono-devel powershell \
4212
&& yum clean all && rm -rf /var/cache/yum
4313

4414
# Install Python 3
45-
RUN yum -y install python3 python3-pip python3-wheel \
46-
&& python3 -m pip install --upgrade pip wheel setuptools \
15+
RUN yum -y install python3 python3-pip \
16+
&& python3 -m pip install --upgrade pip setuptools wheel twine \
4717
&& yum clean all && rm -rf /var/cache/yum
4818

4919
# Install Ruby 2.4+
@@ -64,6 +34,32 @@ RUN amazon-linux-extras install docker
6434
&& yum clean all && rm -rf /var/cache/yum
6535
VOLUME /var/lib/docker
6636

37+
# Install shared dependencies
38+
RUN yum -y install awscli git gzip rsync tar unzip zip \
39+
&& yum clean all && rm -rf /var/cache/yum
40+
41+
# Install NVM and Node 8+
42+
ARG NODE_VERSION=8.16.0
43+
ARG NPM_VERSION=6.8.0
44+
ENV NVM_DIR=/usr/local/nvm
45+
RUN curl -sSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh -o /tmp/install-nvm.sh \
46+
&& echo "ef7ad1db40c92f348c0461f24983b71ba0ea7d45d4007a36e484270fa7f81fcf /tmp/install-nvm.sh" | sha256sum -c \
47+
&& mkdir -p ${NVM_DIR} \
48+
&& bash /tmp/install-nvm.sh \
49+
&& rm /tmp/install-nvm.sh \
50+
&& . ${NVM_DIR}/nvm.sh \
51+
&& nvm install ${NODE_VERSION} \
52+
&& nvm alias default ${NODE_VERSION} \
53+
&& nvm use default \
54+
&& npm -g install npm@^${NPM_VERSION} \
55+
&& npm set unsafe-perm true
56+
ENV NODE_PATH=${NVM_DIR}/versions/node/v${NODE_VERSION}/lib/node_modules \
57+
PATH=${PATH}:${NVM_DIR}/versions/node/v${NODE_VERSION}/bin
58+
59+
# Upgrade all packages that weren't up-to-date just yet
60+
RUN yum -y upgrade \
61+
&& yum clean all && rm -rf /var/cache/yum
62+
6763
# Install some configuration
6864
COPY ssh_config /root/.ssh/config
6965
COPY dockerd-entrypoint.sh /usr/local/bin/

0 commit comments

Comments
 (0)