Skip to content

Commit b3b303d

Browse files
[macos] Remove python2 UnixTools and adjust brew symlinks (#8452)
1 parent 060ad13 commit b3b303d

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

images/macos/provision/core/python.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ if is_Monterey || is_BigSur; then
77
echo "Install latest Python 2"
88
Python2Url="https://www.python.org/ftp/python/2.7.18/python-2.7.18-macosx10.9.pkg"
99
download_with_retries $Python2Url "/tmp" "python2.pkg"
10-
sudo installer -pkg /tmp/python2.pkg -target /
10+
11+
sudo installer -showChoiceChangesXML -pkg /tmp/python2.pkg -target / > /tmp/python2_choices.xml
12+
13+
# To avoid symlink conflicts, remove tools installation in /usr/local/bin using installer choices
14+
xmllint --shell /tmp/python2_choices.xml <<EOF
15+
cd //array/dict[string[text()='org.python.Python.PythonUnixTools-2.7']]/integer
16+
set 0
17+
save
18+
EOF
19+
20+
sudo installer -applyChoiceChangesXML /tmp/python2_choices.xml -pkg /tmp/python2.pkg -target /
21+
1122
pip install --upgrade pip
1223

1324
echo "Install Python2 certificates"
@@ -19,10 +30,8 @@ if is_Veertu; then
1930
close_finder_window
2031
fi
2132

22-
# Explicitly overwrite symlinks created by Python2 such as /usr/local/bin/2to3 since they conflict with symlinks from Python3
23-
# https://github.com/actions/runner-images/issues/2322
2433
echo "Brew Installing Python 3"
25-
brew_smart_install "python@3.11" || brew link --overwrite python@3.11
34+
brew_smart_install "python@3.11"
2635

2736
echo "Installing pipx"
2837
export PIPX_BIN_DIR=/usr/local/opt/pipx_bin

images/macos/software-report/SoftwareReport.Common.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function Get-PipVersion {
129129
[int] $Version
130130
)
131131

132-
$command = If ($Version -eq 2) { "pip --version" } Else { "pip3 --version" }
132+
$command = If ($Version -eq 2) { "/Library/Frameworks/Python.framework/Versions/2.7/bin/pip --version" } Else { "pip3 --version" }
133133
$commandOutput = Run-Command $command
134134
$versionPart1 = $commandOutput | Take-Part -Part 1
135135
$versionPart2 = $commandOutput | Take-Part -Part 4
@@ -192,7 +192,7 @@ function Get-PerlVersion {
192192
}
193193

194194
function Get-PythonVersion {
195-
$pythonVersion = Run-Command "python --version"
195+
$pythonVersion = Run-Command "/Library/Frameworks/Python.framework/Versions/2.7/bin/python --version"
196196
return ($pythonVersion -replace "^Python").Trim()
197197
}
198198

images/macos/tests/Python.Tests.ps1

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,11 @@ Describe "Python3" -Skip:($os.IsVenturaArm64) {
3030

3131
Describe "Python2" -Skip:($os.IsVenturaArm64 -or $os.IsVentura) {
3232
It "Python 2 is available" {
33-
"python --version" | Should -ReturnZeroExitCode
34-
}
35-
36-
It "Python 2 is real 2.x" {
37-
(Get-CommandResult "python --version").Output | Should -BeLike "Python 2.*"
38-
}
39-
40-
It "Python 2 is installed under /usr/local/bin" {
41-
Get-WhichTool "python" | Should -BeLike "/usr/local/bin*"
33+
"/Library/Frameworks/Python.framework/Versions/2.7/bin/python --version" | Should -ReturnZeroExitCode
4234
}
4335

4436
It "Pip 2 is available" {
45-
"pip --version" | Should -ReturnZeroExitCode
37+
"/Library/Frameworks/Python.framework/Versions/2.7/bin/pip --version" | Should -ReturnZeroExitCode
4638
}
4739

4840
It "2to3 symlink does not point to Python 2" {

0 commit comments

Comments
 (0)