Skip to content

Commit

Permalink
feat(jupyterlab): added support for uv as installer (#406)
Browse files Browse the repository at this point in the history
Co-authored-by: M Atif Ali <[email protected]>
  • Loading branch information
ffais and matifali authored Feb 18, 2025
1 parent 01d2c10 commit 0703b13
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 17 deletions.
2 changes: 1 addition & 1 deletion jupyterlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A module that adds JupyterLab in your Coder template.
module "jupyterlab" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/modules/jupyterlab/coder"
version = "1.0.23"
version = "1.0.30"
agent_id = coder_agent.example.id
}
```
52 changes: 48 additions & 4 deletions jupyterlab/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,70 @@ 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 gcc musl-dev linux-headers && uv venv",
]);
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([
"\u001B[0;1mInstalling jupyterlab!",
"pipx is not installed",
"Please install pipx in your Dockerfile/VM image before running this script",
"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",
]);
});

// TODO: Add faster test to run with uv.
// currently times out.
// it("runs with uv", async () => {
// const state = await runTerraformApply(import.meta.dir, {
// agent_id: "foo",
// });
// const output = await executeScriptInContainerWithUv(state, "python:3-alpine");
// expect(output.exitCode).toBe(0);
// expect(output.stdout).toEqual([
// "Checking for a supported installer",
// "uv is installed",
// "\u001B[0;1mInstalling jupyterlab!",
// "🥳 jupyterlab has been installed",
// "👷 Starting jupyterlab in background...check logs at /tmp/jupyterlab.log",
// ]);
// });

// TODO: Add faster test to run with pipx.
// currently times out.
// it("runs with pipx", async () => {
Expand Down
46 changes: 34 additions & 12 deletions jupyterlab/run.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
#!/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 pip install -q jupyterlab \
&& printf "%s\n" "🥳 jupyterlab has been installed"
JUPYTERPATH="$HOME/.venv/bin/"
;;
pipx)
pipx install jupyterlab \
&& printf "%s\n" "🥳 jupyterlab has been installed"
JUPYTERPATH="$HOME/.local/bin"
;;
esac
else
printf "%s\n\n" "🥳 jupyterlab is already installed"
fi

printf "👷 Starting jupyterlab in background..."
printf "check logs at ${LOG_PATH}"
$HOME/.local/bin/jupyter-lab --no-browser \
$JUPYTERPATH/jupyter-lab --no-browser \
"$BASE_URL_FLAG" \
--ServerApp.ip='*' \
--ServerApp.port="${PORT}" \
Expand Down

0 comments on commit 0703b13

Please sign in to comment.