diff --git a/features/src/python/README.md b/features/src/python/README.md index 3a92b67..4e8b0c3 100755 --- a/features/src/python/README.md +++ b/features/src/python/README.md @@ -6,7 +6,7 @@ Installs Python. ```json "features": { - "ghcr.io/postfinance/devcontainer-features/python:1.1.0": { + "ghcr.io/postfinance/devcontainer-features/python:1.2.0": { "version": "latest", "downloadUrl": "", "pipIndex": "", @@ -20,7 +20,7 @@ Installs Python. | Option | Description | Type | Default Value | Proposals | |-----|-----|-----|-----|-----| -| version | The version of Python to install. | string | latest | latest, 3.12, 3.9.19 | +| version | The version of Python to install. | string | latest | latest, system-default, 3.12, 3.9.19 | | downloadUrl | The download URL to use. | string | <empty> | https://mycompany.com/artifactory/python-generic-ftp-remote, https://mycompany.com/artifactory/python-generic-remote/ftp/python | | pipIndex | The pip index to use (used by search). | string | <empty> | https://mycompany.com/artifactory/api/pypi/python/simple, https://mycompany.com/nexus/repository/pypi-group/pypi | | pipIndexUrl | The pip index URL to use (used by install). | string | <empty> | https://mycompany.com/artifactory/api/pypi/python/simple, https://mycompany.com/nexus/repository/pypi-group/simple | diff --git a/features/src/python/devcontainer-feature.json b/features/src/python/devcontainer-feature.json index 1908836..6c7950c 100644 --- a/features/src/python/devcontainer-feature.json +++ b/features/src/python/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "1.1.0", + "version": "1.2.0", "name": "Python", "description": "Installs Python.", "options": { @@ -8,6 +8,7 @@ "type": "string", "proposals": [ "latest", + "system-default", "3.12", "3.9.19" ], @@ -67,4 +68,4 @@ "PATH": "/usr/local/python/current/bin:${PATH}", "PYTHON_PATH": "/usr/local/python/current" } -} \ No newline at end of file +} diff --git a/features/src/python/installer.go b/features/src/python/installer.go index 0280633..8540944 100644 --- a/features/src/python/installer.go +++ b/features/src/python/installer.go @@ -83,7 +83,18 @@ func (c *pythonComponent) GetAllVersions() ([]*gover.Version, error) { } func (c *pythonComponent) InstallVersion(version *gover.Version) error { - // Download the file + if version == gover.EmptyVersion { + return installer.Tools.System.InstallPackagesByOs(func(osInfo *installer.OsInfo) ([]string, error) { + if osInfo.IsDebian() || osInfo.IsUbuntu() { + return []string{"python3", "python3-pip", "python-is-python3"}, nil + } else if osInfo.IsAlpine() { + return []string{"python3", "py3-pip"}, nil + } + return nil, fmt.Errorf("unsupported OS vendor: %s", osInfo.Vendor) + }) + } + + // Download and compile a specific version of Python name := fmt.Sprintf("Python-%s", version.Raw) fileName := fmt.Sprintf("%s.tgz", name) // The folder only contains the major, minor and sometimes the patch version diff --git a/features/test/python/install-system-provided.sh b/features/test/python/install-system-provided.sh new file mode 100755 index 0000000..90aa5cc --- /dev/null +++ b/features/test/python/install-system-provided.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +[[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh" +[[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh" + +check_version "$(python --version)" "Python 3." +check_command_exists python3 +check_command_exists python +check_command_exists pip diff --git a/features/test/python/scenarios.json b/features/test/python/scenarios.json index b958411..aa3add4 100644 --- a/features/test/python/scenarios.json +++ b/features/test/python/scenarios.json @@ -18,5 +18,15 @@ "version": "3.15.0a1" } } + }, + "install-system-provided": { + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "./python": { + "version": "system-default" + } + } } }