Skip to content

Commit

Permalink
fix(pacmak): python pack fails when installing 'black' via pip
Browse files Browse the repository at this point in the history
The failure is because of intermittent unavailability of black or one of
its packages from the PyPI index.

Instead, install back into the environment, i.e., superchain, and use
that.
  • Loading branch information
Niranjan Jayakar committed Jul 9, 2020
1 parent bdb5483 commit 0d75233
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
26 changes: 3 additions & 23 deletions packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,9 @@ export default class Python extends Target {
public async generateCode(outDir: string, tarball: string): Promise<void> {
await super.generateCode(outDir, tarball);

// We'll just run "black" on that now, to make the generated code a little more readable.
const blackRoot = await fs.mkdtemp(
path.join(os.tmpdir(), 'jsii-pacmak-black-'),
);
try {
await shell('python3', ['-m', 'venv', path.join(blackRoot, '.env')], {
cwd: blackRoot,
});
await shell(
path.join(blackRoot, '.env', 'bin', 'pip'),
['install', 'black'],
{ cwd: blackRoot },
);
await shell(
path.join(blackRoot, '.env', 'bin', 'black'),
['--py36', outDir],
{
cwd: outDir,
},
);
} finally {
await fs.remove(blackRoot);
}
await shell('black', ['--py36', outDir], {
cwd: outDir,
});
}

public async build(sourceDir: string, outDir: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion superchain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN rpm --import "https://packages.microsoft.com/keys/microsoft.asc"

# Install Python 3
RUN yum -y install python3 python3-pip \
&& python3 -m pip install --upgrade pip setuptools wheel twine \
&& python3 -m pip install --upgrade pip setuptools wheel twine black \
&& yum clean all && rm -rf /var/cache/yum

# Install Ruby 2.6+
Expand Down

0 comments on commit 0d75233

Please sign in to comment.