From f2b1fa1399a16caeb27ebc4cf4d5e15b51da8de0 Mon Sep 17 00:00:00 2001 From: ilia-shipitsin <125650415+ilia-shipitsin@users.noreply.github.com> Date: Thu, 18 May 2023 09:21:55 +0200 Subject: [PATCH] [macos] enable python3 (and pipx) on macOS13 (#7599) --- images/macos/provision/core/python.sh | 16 ++++---- .../SoftwareReport.Generator.ps1 | 8 ++++ images/macos/templates/macOS-13.anka.pkr.hcl | 1 + images/macos/tests/Python.Tests.ps1 | 37 ++++++++++--------- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/images/macos/provision/core/python.sh b/images/macos/provision/core/python.sh index 390a6ee7b..38250d758 100755 --- a/images/macos/provision/core/python.sh +++ b/images/macos/provision/core/python.sh @@ -3,14 +3,16 @@ source ~/utils/utils.sh echo "Installing Python Tooling" -echo "Install latest Python 2" -Python2Url="https://www.python.org/ftp/python/2.7.18/python-2.7.18-macosx10.9.pkg" -download_with_retries $Python2Url "/tmp" "python2.pkg" -sudo installer -pkg /tmp/python2.pkg -target / -pip install --upgrade pip +if ! is_Veertu; then + echo "Install latest Python 2" + Python2Url="https://www.python.org/ftp/python/2.7.18/python-2.7.18-macosx10.9.pkg" + download_with_retries $Python2Url "/tmp" "python2.pkg" + sudo installer -pkg /tmp/python2.pkg -target / + pip install --upgrade pip -echo "Install Python2 certificates" -bash -c "/Applications/Python\ 2.7/Install\ Certificates.command" + echo "Install Python2 certificates" + bash -c "/Applications/Python\ 2.7/Install\ Certificates.command" +fi # Close Finder window if is_Veertu; then diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index 5aed6ee70..08249e864 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -52,8 +52,12 @@ $languageAndRuntime.AddToolVersion("Perl", $(Get-PerlVersion)) if (-not $os.IsVenturaArm64) { $languageAndRuntime.AddToolVersion("PHP", $(Get-PHPVersion)) } + if ((-not $os.IsVentura) -and (-not $os.IsVenturaArm64)) { $languageAndRuntime.AddToolVersion("Python", $(Get-PythonVersion)) +} + +if (-not $os.IsVenturaArm64) { $languageAndRuntime.AddToolVersion("Python3", $(Get-Python3Version)) } $languageAndRuntime.AddToolVersion("R", $(Get-RVersion)) @@ -73,9 +77,13 @@ $packageManagement.AddToolVersion("NPM", $(Get-NPMVersion)) if ((-not $os.IsVentura) -and (-not $os.IsVenturaArm64)) { $packageManagement.AddToolVersion("NuGet", $(Get-NuGetVersion)) $packageManagement.AddToolVersion("Pip", $(Get-PipVersion -Version 2)) +} + +if (-not $os.IsVenturaArm64) { $packageManagement.AddToolVersion("Pip3", $(Get-PipVersion -Version 3)) $packageManagement.AddToolVersion("Pipx", $(Get-PipxVersion)) } + $packageManagement.AddToolVersion("RubyGems", $(Get-RubyGemsVersion)) if (-not $os.IsVenturaArm64) { $packageManagement.AddToolVersion("Vcpkg", $(Get-VcpkgVersion)) diff --git a/images/macos/templates/macOS-13.anka.pkr.hcl b/images/macos/templates/macOS-13.anka.pkr.hcl index 28bd20a89..3e11d06c8 100644 --- a/images/macos/templates/macOS-13.anka.pkr.hcl +++ b/images/macos/templates/macOS-13.anka.pkr.hcl @@ -163,6 +163,7 @@ build { "./provision/core/open_windows_check.sh", "./provision/core/powershell.sh", "./provision/core/dotnet.sh", + "./provision/core/python.sh", "./provision/core/azcopy.sh", "./provision/core/ruby.sh", "./provision/core/rubygem.sh", diff --git a/images/macos/tests/Python.Tests.ps1 b/images/macos/tests/Python.Tests.ps1 index 15f4e1605..6433dc7db 100644 --- a/images/macos/tests/Python.Tests.ps1 +++ b/images/macos/tests/Python.Tests.ps1 @@ -3,19 +3,7 @@ Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" -DisableNameChecking $os = Get-OSVersion -Describe "Python" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { - It "Python 2 is available" { - "python --version" | Should -ReturnZeroExitCode - } - - It "Python 2 is real 2.x" { - (Get-CommandResult "python --version").Output | Should -BeLike "Python 2.*" - } - - It "Python 2 is installed under /usr/local/bin" { - Get-WhichTool "python" | Should -BeLike "/usr/local/bin*" - } - +Describe "Python3" -Skip:($os.IsVenturaArm64) { It "Python 3 is available" { "python3 --version" | Should -ReturnZeroExitCode } @@ -24,10 +12,6 @@ Describe "Python" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { Get-WhichTool "python3" | Should -BeLike "/usr/local/bin*" } - It "Pip 2 is available" { - "pip --version" | Should -ReturnZeroExitCode - } - It "Pip 3 is available" { "pip3 --version" | Should -ReturnZeroExitCode } @@ -42,6 +26,25 @@ Describe "Python" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { $pip3Path | Should -BeExactly $python3Path } +} + +Describe "Python2" -Skip:($os.IsVenturaArm64 -or $os.IsVentura) { + It "Python 2 is available" { + "python --version" | Should -ReturnZeroExitCode + } + + It "Python 2 is real 2.x" { + (Get-CommandResult "python --version").Output | Should -BeLike "Python 2.*" + } + + It "Python 2 is installed under /usr/local/bin" { + Get-WhichTool "python" | Should -BeLike "/usr/local/bin*" + } + + It "Pip 2 is available" { + "pip --version" | Should -ReturnZeroExitCode + } + It "2to3 symlink does not point to Python 2" { $2to3path = (Get-ChildItem (Get-Command 2to3).Path).Target $2to3path | Should -Not -BeLike '/Frameworks/Python.framework/Versions/2.*'