Skip to content

Commit

Permalink
Create and activate a Python virtualenv (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon authored Sep 10, 2024
1 parent fba1a88 commit aea7fcd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ RUN apt update
# Rust envvars
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.81.0
RUST_VERSION=1.81.0 \
VIRTUAL_ENV=/var/local/python-venv
ENV PATH=/usr/local/cargo/bin:$VIRTUAL_ENV/bin:$PATH

# == node ======================
FROM base AS node
Expand All @@ -30,7 +31,8 @@ RUN --mount=type=cache,target=/var/cache/apt,id=framework-runtime-python \
python3-setuptools \
python3-wheel \
python3-dev \
python3-venv
python3-venv \
&& python3 -m venv $VIRTUAL_ENV

# == R ===========================
FROM base AS r
Expand Down
8 changes: 7 additions & 1 deletion tests/dataloader-languages.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { binaryVersionTest } from "./index.ts";
import { test } from "node:test";
import { binaryVersionTest, runCommandInContainer } from "./index.ts";

const dataLoaderLanguages = [
{ binary: "node", semver: "^20.17" },
Expand Down Expand Up @@ -33,3 +34,8 @@ const dataLoaderLanguages = [
];

dataLoaderLanguages.forEach(binaryVersionTest);

await test(`A Python virtual environment is activated`, async () => {
// should not throw
await runCommandInContainer(["pip", "install", "requests"]);
});
7 changes: 5 additions & 2 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ export async function runCommandInContainer(
docker.modem.demuxStream(attach, stdout, stderr);
await container.start();
const wait = (await container.wait()) as { StatusCode: number };
if (wait.StatusCode !== 0)
throw new Error(`Command failed with status code ${wait.StatusCode}`);
if (wait.StatusCode !== 0) {
throw new Error(`Command failed with status code ${wait.StatusCode}\n` +
`stdout:\n${stdout.string}\n\n` +
`stderr:\n${stderr.string}`);
}
return { stdout: stdout.string, stderr: stderr.string };
}

Expand Down

0 comments on commit aea7fcd

Please sign in to comment.