diff --git a/.github/.devcontainer/devcontainer.json b/.github/.devcontainer/devcontainer.json index 36bc5fa..46f0f2e 100644 --- a/.github/.devcontainer/devcontainer.json +++ b/.github/.devcontainer/devcontainer.json @@ -15,6 +15,9 @@ "pythonDeps": "jupyter,papermill", "juliaDeps": "IJulia" }, + "./uv": { + "version": "latest" + }, "ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": { "version": "prerelease", "installTinyTex": "true", diff --git a/.github/.devcontainer/quarto-computing-dependencies/install.sh b/.github/.devcontainer/quarto-computing-dependencies/install.sh index a53403d..b7f6fad 100755 --- a/.github/.devcontainer/quarto-computing-dependencies/install.sh +++ b/.github/.devcontainer/quarto-computing-dependencies/install.sh @@ -10,8 +10,6 @@ R_DEPS=${RDEPS:-"rmarkdown"} PYTHON_DEPS=${PYTHONDEPS:-"jupyter,papermill"} JULIA_DEPS=${JULIADEPS:-"IJulia"} -set -e - if [ "$(id -u)" -ne 0 ]; then echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' exit 1 diff --git a/.github/.devcontainer/uv/devcontainer-feature.json b/.github/.devcontainer/uv/devcontainer-feature.json new file mode 100644 index 0000000..8e1c05b --- /dev/null +++ b/.github/.devcontainer/uv/devcontainer-feature.json @@ -0,0 +1,17 @@ +{ + "id": "uv", + "version": "1.0.0", + "name": "uv", + "description": "Install uv, an extremely fast Python package and project manager, written in Rust.", + "options": { + "version": { + "default": "latest", + "description": "Select the version to install.", + "proposals": ["latest"], + "type": "string" + } + }, + "installsAfter": [ + "./quarto-computing-dependencies" + ] +} diff --git a/.github/.devcontainer/uv/install.sh b/.github/.devcontainer/uv/install.sh new file mode 100644 index 0000000..027a664 --- /dev/null +++ b/.github/.devcontainer/uv/install.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +set -e + +export DEBIAN_FRONTEND=noninteractive + +USERNAME=${USERNAME:-${_REMOTE_USER:-"automatic"}} + +VERSION=${VERSION:-"latest"} + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Determine the appropriate non-root user +if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then + USERNAME="" + POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") + for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do + if id -u "${CURRENT_USER}" >/dev/null 2>&1; then + USERNAME=${CURRENT_USER} + break + fi + done + if [ "${USERNAME}" = "" ]; then + USERNAME=root + fi +elif [ "${USERNAME}" = "none" ] || ! id -u "${USERNAME}" >/dev/null 2>&1; then + USERNAME=root +fi + +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +install_uv() { + local version=$1 + local url="https://github.com/astral-sh/uv/releases/${version}/download/uv-installer.sh" + check_packages curl ca-certificates + su "${USERNAME}" -c "curl --proto '=https' --tlsv1.2 -LsSf ${url} | sh" +} + +enable_autocompletion() { + su "${USERNAME}" -c "echo 'eval \"\$(uv generate-shell-completion zsh)\"' >> \"\$HOME/.zshrc\"" + su "${USERNAME}" -c "echo 'eval \"\$(uvx --generate-shell-completion zsh)\"' >> \"\$HOME/.zshrc\"" +} + +install_uv ${VERSION} +enable_autocompletion