From aea7fcdd74532e80334f5644394401ade9c73c0b Mon Sep 17 00:00:00 2001 From: Michael Cooper Date: Tue, 10 Sep 2024 12:37:40 -0700 Subject: [PATCH] Create and activate a Python virtualenv (#7) --- Dockerfile | 8 +++++--- tests/dataloader-languages.test.ts | 8 +++++++- tests/index.ts | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 326ed80..9c2be74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 diff --git a/tests/dataloader-languages.test.ts b/tests/dataloader-languages.test.ts index 1bb7409..d12d0b5 100644 --- a/tests/dataloader-languages.test.ts +++ b/tests/dataloader-languages.test.ts @@ -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" }, @@ -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"]); +}); diff --git a/tests/index.ts b/tests/index.ts index ee32099..9173f79 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -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 }; }