From 2f702974cc4efe8afc258fb46b55eaac6bd8e7d7 Mon Sep 17 00:00:00 2001 From: Erik Bershel <110455084+erik-bershel@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:34:30 +0200 Subject: [PATCH] [macOS] Update Python script and Python3 symlink behaviour (#13174) --- images/macos/scripts/build/Install-Toolset.ps1 | 9 +++++++++ images/macos/scripts/build/install-python.sh | 10 +--------- images/macos/scripts/tests/Python.Tests.ps1 | 7 ++++++- images/macos/toolsets/toolset-14.json | 3 --- images/macos/toolsets/toolset-15.json | 3 --- images/macos/toolsets/toolset-26.json | 3 --- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/images/macos/scripts/build/Install-Toolset.ps1 b/images/macos/scripts/build/Install-Toolset.ps1 index 1e81cd27b..a9a89665f 100644 --- a/images/macos/scripts/build/Install-Toolset.ps1 +++ b/images/macos/scripts/build/Install-Toolset.ps1 @@ -54,4 +54,13 @@ foreach ($tool in $tools) { } } + +# Ensure python3 and pip3 point to the latest installed Python version +# Fix for ./setup.sh script behavior for python3 and pip3 symlinks +# Only Intel images are affected since /usr/local/bin is used for Intel +# ARM images use /opt/homebrew/bin which is managed by Homebrew +Write-Host "Ensuring python3 and pip3 point to the latest installed Python version from Homebrew" +brew unlink python@3.14 && brew link python@3.14 --force --overwrite +Split-Path (readlink (which python3)) + Invoke-PesterTests "Toolcache" diff --git a/images/macos/scripts/build/install-python.sh b/images/macos/scripts/build/install-python.sh index 0188382f3..5f3668afb 100644 --- a/images/macos/scripts/build/install-python.sh +++ b/images/macos/scripts/build/install-python.sh @@ -12,16 +12,8 @@ echo "Installing Python Tooling" close_finder_window # Installing latest Homebrew Python 3 to handle python3 and pip3 symlinks -# When latest Python3 is installed as a dependency for other packages -# it does not create /usr/local/bin/python3 and /usr/local/bin/pip3 echo "Brew Installing default Python 3" -brew_smart_install "python" - -# Install specific Python version -# Update symlinks for python3 and pip3 to point to the specific version -toolsetVersion=$(get_toolset_value '.python.default') -echo "Installing Python $toolsetVersion" -brew_smart_install "python@$toolsetVersion" +brew_smart_install "python3" # Pipx has its own Python dependency echo "Installing pipx" diff --git a/images/macos/scripts/tests/Python.Tests.ps1 b/images/macos/scripts/tests/Python.Tests.ps1 index 0100e9caa..d5a7d3ad7 100644 --- a/images/macos/scripts/tests/Python.Tests.ps1 +++ b/images/macos/scripts/tests/Python.Tests.ps1 @@ -26,10 +26,15 @@ Describe "Python3" { "pipx --version" | Should -ReturnZeroExitCode } - It "Pip 3 and Python 3 came from the same brew formula" { + It "Pip 3 and Python 3 came from the same path prefix" { $pip3Path = Split-Path (readlink (which pip3)) $python3Path = Split-Path (readlink (which python3)) $pip3Path | Should -BeExactly $python3Path } + It "Pip 3 and Python 3 came from brew formula" { + Split-Path (readlink (which pip3)) | Should -BeLike "*/Cellar/*" + Split-Path (readlink (which python3)) | Should -BeLike "*/Cellar/*" + } + } diff --git a/images/macos/toolsets/toolset-14.json b/images/macos/toolsets/toolset-14.json index bf94c2568..33dfe5be9 100644 --- a/images/macos/toolsets/toolset-14.json +++ b/images/macos/toolsets/toolset-14.json @@ -222,9 +222,6 @@ "fastlane" ] }, - "python": { - "default": "3.13" - }, "toolcache": [ { "name": "Python", diff --git a/images/macos/toolsets/toolset-15.json b/images/macos/toolsets/toolset-15.json index be5c180e3..5d3c259f6 100644 --- a/images/macos/toolsets/toolset-15.json +++ b/images/macos/toolsets/toolset-15.json @@ -226,9 +226,6 @@ "fastlane" ] }, - "python": { - "default": "3.13" - }, "toolcache": [ { "name": "Python", diff --git a/images/macos/toolsets/toolset-26.json b/images/macos/toolsets/toolset-26.json index 34c56fb58..0a346018b 100644 --- a/images/macos/toolsets/toolset-26.json +++ b/images/macos/toolsets/toolset-26.json @@ -130,9 +130,6 @@ "fastlane" ] }, - "python": { - "default": "3.13" - }, "toolcache": [ { "name": "Python",