Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(jupyterlab): added support for uv as installer #406

Merged
merged 8 commits into from
Feb 18, 2025
44 changes: 41 additions & 3 deletions jupyterlab/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,61 @@ const executeScriptInContainerWithPip = async (
};
};

// executes the coder script after installing pip
const executeScriptInContainerWithUv = async (
state: TerraformState,
image: string,
shell = "sh",
): Promise<{
exitCode: number;
stdout: string[];
stderr: string[];
}> => {
const instance = findResourceInstance(state, "coder_script");
const id = await runContainer(image);
const respPipx = await execContainer(id, [shell, "-c", "apk --no-cache add uv"]);
const resp = await execContainer(id, [shell, "-c", instance.script]);
const stdout = resp.stdout.trim().split("\n");
const stderr = resp.stderr.trim().split("\n");
return {
exitCode: resp.exitCode,
stdout,
stderr,
};
};

describe("jupyterlab", async () => {
await runTerraformInit(import.meta.dir);

testRequiredVariables(import.meta.dir, {
agent_id: "foo",
});

it("fails without pipx", async () => {
it("fails without installers", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
});
const output = await executeScriptInContainer(state, "alpine");
expect(output.exitCode).toBe(1);
expect(output.stdout).toEqual([
"Checking for a supported installer",
"No valid installer is not installed",
"Please install pipx or uv in your Dockerfile/VM image before running this script",
]);
});

it("runs with uv", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
});
const output = await executeScriptInContainerWithUv(state, "alpine");
expect(output.exitCode).toBe(0);
expect(output.stdout).toEqual([
"Checking for a supported installer",
"uv is installed",
"\u001B[0;1mInstalling jupyterlab!",
"pipx is not installed",
"Please install pipx in your Dockerfile/VM image before running this script",
"🥳 jupyterlab has been installed",
"👷 Starting jupyterlab in background...check logs at /tmp/jupyterlab.log",
]);
});

Expand Down
42 changes: 31 additions & 11 deletions jupyterlab/run.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
#!/usr/bin/env sh
INSTALLER=""
check_available_installer () {
# check if pipx is installed
echo "Checking for a supported installer"
if command -v pipx > /dev/null 2>&1; then
echo "pipx is installed"
INSTALLER="pipx"
return
fi
# check if uv is installed
if command -v uv > /dev/null 2>&1; then
echo "uv is installed"
INSTALLER="uv"
return
fi
echo "No valid installer is not installed"
echo "Please install pipx or uv in your Dockerfile/VM image before running this script"
exit 1
}

if [ -n "${BASE_URL}" ]; then
BASE_URL_FLAG="--ServerApp.base_url=${BASE_URL}"
fi

BOLD='\033[0;1m'

printf "$${BOLD}Installing jupyterlab!\n"

# check if jupyterlab is installed
if ! command -v jupyter-lab > /dev/null 2>&1; then
# install jupyterlab
# check if pipx is installed
if ! command -v pipx > /dev/null 2>&1; then
echo "pipx is not installed"
echo "Please install pipx in your Dockerfile/VM image before running this script"
exit 1
fi
# install jupyterlab
pipx install -q jupyterlab
printf "%s\n\n" "🥳 jupyterlab has been installed"
check_available_installer
printf "$${BOLD}Installing jupyterlab!\n"
case $INSTALLER in
uv)
uv add jupyter-lab
printf "%s\n" "🥳 jupyterlab has been installed"
;;
pipx)
pipx install -q jupyterlab
printf "%s\n" "🥳 jupyterlab has been installed"
;;
esac
else
printf "%s\n\n" "🥳 jupyterlab is already installed"
fi
Expand Down
Loading