Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and activate a Python virtualenv #7

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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