Skip to content

Commit aea7fcd

Browse files
authored
Create and activate a Python virtualenv (#7)
1 parent fba1a88 commit aea7fcd

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ RUN apt update
66
# Rust envvars
77
ENV RUSTUP_HOME=/usr/local/rustup \
88
CARGO_HOME=/usr/local/cargo \
9-
PATH=/usr/local/cargo/bin:$PATH \
10-
RUST_VERSION=1.81.0
9+
RUST_VERSION=1.81.0 \
10+
VIRTUAL_ENV=/var/local/python-venv
11+
ENV PATH=/usr/local/cargo/bin:$VIRTUAL_ENV/bin:$PATH
1112

1213
# == node ======================
1314
FROM base AS node
@@ -30,7 +31,8 @@ RUN --mount=type=cache,target=/var/cache/apt,id=framework-runtime-python \
3031
python3-setuptools \
3132
python3-wheel \
3233
python3-dev \
33-
python3-venv
34+
python3-venv \
35+
&& python3 -m venv $VIRTUAL_ENV
3436

3537
# == R ===========================
3638
FROM base AS r

tests/dataloader-languages.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { binaryVersionTest } from "./index.ts";
1+
import { test } from "node:test";
2+
import { binaryVersionTest, runCommandInContainer } from "./index.ts";
23

34
const dataLoaderLanguages = [
45
{ binary: "node", semver: "^20.17" },
@@ -33,3 +34,8 @@ const dataLoaderLanguages = [
3334
];
3435

3536
dataLoaderLanguages.forEach(binaryVersionTest);
37+
38+
await test(`A Python virtual environment is activated`, async () => {
39+
// should not throw
40+
await runCommandInContainer(["pip", "install", "requests"]);
41+
});

tests/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ export async function runCommandInContainer(
9797
docker.modem.demuxStream(attach, stdout, stderr);
9898
await container.start();
9999
const wait = (await container.wait()) as { StatusCode: number };
100-
if (wait.StatusCode !== 0)
101-
throw new Error(`Command failed with status code ${wait.StatusCode}`);
100+
if (wait.StatusCode !== 0) {
101+
throw new Error(`Command failed with status code ${wait.StatusCode}\n` +
102+
`stdout:\n${stdout.string}\n\n` +
103+
`stderr:\n${stderr.string}`);
104+
}
102105
return { stdout: stdout.string, stderr: stderr.string };
103106
}
104107

0 commit comments

Comments
 (0)