From 35dfcb413394bc0c21d2993d57968b36d807cd36 Mon Sep 17 00:00:00 2001 From: Markus Zhang Date: Sun, 16 Feb 2025 11:36:42 +0000 Subject: [PATCH] [CHANGE] New feature mise-python --- .github/workflows/test.yaml | 2 + bin/test | 2 +- bin/test_autogenerated | 2 +- src/mise-python/README.md | 25 +++++++++++ src/mise-python/devcontainer-feature.json | 21 +++++++++ src/mise-python/install.sh | 45 +++++++++++++++++++ test/mise-python/python3.12.sh | 8 ++++ .../python3.13_python3.12_python3.11.sh | 10 +++++ test/mise-python/scenarios.json | 19 ++++++++ test/mise-python/test.sh | 14 ++++++ 10 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 src/mise-python/README.md create mode 100644 src/mise-python/devcontainer-feature.json create mode 100755 src/mise-python/install.sh create mode 100644 test/mise-python/python3.12.sh create mode 100644 test/mise-python/python3.13_python3.12_python3.11.sh create mode 100644 test/mise-python/scenarios.json create mode 100644 test/mise-python/test.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dfe9c4a..bc693af 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,6 +17,7 @@ jobs: - bitwarden-cli - bitwarden-secrets-manager - mise + - mise-python - vault baseImage: - debian:latest @@ -62,6 +63,7 @@ jobs: - bitwarden-secrets-manager - kamal - mise + - mise-python - vault steps: - uses: actions/checkout@v4 diff --git a/bin/test b/bin/test index a224345..086245d 100755 --- a/bin/test +++ b/bin/test @@ -27,7 +27,7 @@ elif [[ $1 == +([0-9]) ]]; then fi FEATURE="$1" -BASE_IMAGE="${BASE_IMAGE:-$(echo $BASE_IMAGES | jq --raw-output ".$FEATURE // empty")}" +BASE_IMAGE="${BASE_IMAGE:-$(echo $BASE_IMAGES | jq --raw-output ".\"$FEATURE\" // empty")}" BASE_IMAGE="${BASE_IMAGE:-$BASE_IMAGE_DEFAULT}" cd $BASE_PATH diff --git a/bin/test_autogenerated b/bin/test_autogenerated index c3b7539..1b5c097 100755 --- a/bin/test_autogenerated +++ b/bin/test_autogenerated @@ -27,7 +27,7 @@ elif [[ $1 == +([0-9]) ]]; then fi FEATURE="$1" -BASE_IMAGE="${BASE_IMAGE:-$(echo $BASE_IMAGES | jq --raw-output ".$FEATURE // empty")}" +BASE_IMAGE="${BASE_IMAGE:-$(echo $BASE_IMAGES | jq --raw-output ".\"$FEATURE\" // empty")}" BASE_IMAGE="${BASE_IMAGE:-$BASE_IMAGE_DEFAULT}" cd $BASE_PATH diff --git a/src/mise-python/README.md b/src/mise-python/README.md new file mode 100644 index 0000000..0556adc --- /dev/null +++ b/src/mise-python/README.md @@ -0,0 +1,25 @@ + +# mise-en-place version manager (mise) + +Installs mise-en-place version manager. + +## Example Usage + +```json +"features": { + "ghcr.io/RouL/devcontainer-features/mise:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| no_ruby_dependencies | If set to true, the dependencies for building ruby won't be installed. | boolean | false | +| no_python_dependencies | If set to true, the dependencies for building python won't be installed. | boolean | false | + + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/RouL/devcontainer-features/blob/main/src/mise/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/mise-python/devcontainer-feature.json b/src/mise-python/devcontainer-feature.json new file mode 100644 index 0000000..c0cb2a0 --- /dev/null +++ b/src/mise-python/devcontainer-feature.json @@ -0,0 +1,21 @@ +{ + "id": "mise", + "version": "1.0.0", + "name": "mise-en-place version manager", + "description": "Installs mise-en-place version manager.", + "dependsOn": { + "ghcr.io/RouL/devcontainer-features/mise:latest": {} + }, + "options": { + "version": { + "description": "Version to be installed as default.", + "type": "string", + "default": "latest" + }, + "extra_versions": { + "description": "Additional versions to be installed. (space separated)", + "type": "string", + "default": "" + } + } +} diff --git a/src/mise-python/install.sh b/src/mise-python/install.sh new file mode 100755 index 0000000..f85c699 --- /dev/null +++ b/src/mise-python/install.sh @@ -0,0 +1,45 @@ +#!/usr/bin/bash +set -e + +USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" +VERSION="${VERSION:-latest}" + +REQUIRED_PACKAGES="build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev" + +apt_get_update() +{ + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +export DEBIAN_FRONTEND=noninteractive + +check_packages $REQUIRED_PACKAGES + +install() { + su ${USERNAME} -c "mise use --global python@${VERSION}" +} + +echo "(*) Installing Python (${VERSION}) via mise as default..." + +install + +for extraVersion in $EXTRA_VERSIONS +do + echo "(*) Installung Python (${extraVersion}) via mise" + su ${USERNAME} -c "mise install python@${VERSION}" +done + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" diff --git a/test/mise-python/python3.12.sh b/test/mise-python/python3.12.sh new file mode 100644 index 0000000..bd30dbd --- /dev/null +++ b/test/mise-python/python3.12.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib + +check "check default python == 3.12" bash -c "python --version | grep -E '^Python 3\\.12\\.'" + +reportResults diff --git a/test/mise-python/python3.13_python3.12_python3.11.sh b/test/mise-python/python3.13_python3.12_python3.11.sh new file mode 100644 index 0000000..dbf1c0b --- /dev/null +++ b/test/mise-python/python3.13_python3.12_python3.11.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +source dev-container-features-test-lib + +check "check default python == 3.13" bash -c "python --version | grep -E '^Python 3\\.13\\.'" +check "check python@3.12" bash -c "mise exec python@3.12 -- python --version | grep -E '^Python 3\\.12\\.'" +check "check python@3.11" bash -c "mise exec python@3.11 -- python --version | grep -E '^Python 3\\.11\\.'" + +reportResults diff --git a/test/mise-python/scenarios.json b/test/mise-python/scenarios.json new file mode 100644 index 0000000..2d56be7 --- /dev/null +++ b/test/mise-python/scenarios.json @@ -0,0 +1,19 @@ +{ + "python3.12": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "mise-python": { + "version": "3.12" + } + } + }, + "python3.13_python3.12_python3.11": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "mise-python": { + "version": "3.13", + "extra_versions": "3.12 3.11" + } + } + } +} diff --git a/test/mise-python/test.sh b/test/mise-python/test.sh new file mode 100644 index 0000000..3ddf50c --- /dev/null +++ b/test/mise-python/test.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +sudo apt-get update -y > /dev/null +sudo apt-get install -y curl jq ca-certificates > /dev/null + +CURRENT_VERSION="$(curl -L --no-progress-meter https://api.github.com/repos/jdx/mise/releases/latest | jq --raw-output '.tag_name')" +CURRENT_VERSION="${CURRENT_VERSION#v}" + +source dev-container-features-test-lib + +check "check default python" bash -c "python --version | grep -E '^Python '" + +reportResults